Rename Method refactoring allowed for methods defined to implement container objects

Ouverte
#775 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 7 jours

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
Une demi-journée
Accessibilité débutants
35/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
python
Domaine
devtools

Piste de recherche

Start by reproducing the report with the main.py and test.py from the issue, using Rename Method on StringlikeMixin.len with the new name 'text'. The open question is whether Rope should warn or refuse when a method implements a container protocol like len, and the issue does not settle that. Done means agreeing that behaviour with maintainers and then covering it with a test.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

bug rename-refactor

Rename Method refactoring allowed for methods defined to implement container objects
It would be nice if Rope sent an alert to the user to avoid incompatible parameter type errors when using the "len()" function.

Steps to reproduce the behavior:

  1. Code before refactoring:

structure

-- main
---- main.py
-- test
---- test.py

main.py:

implements_to_string = lambda x: x

@implements_to_string
class StringlikeMixin(object):

    def __len__(self):
        return len(self._strkey())


class BaseBlob(StringlikeMixin):
    def __init__(self, text):
        self.raw = text

    def _strkey(self):
        return self.raw


class Sentence(BaseBlob):
    def __init__(self, sentence, start_index=0, end_index=None, *args, **kwargs):
        super(Sentence, self).__init__(sentence, *args, **kwargs)

test.py:

from unittest import TestCase
from main import main as tb

class SentenceTest(TestCase):

    def setUp(self):
        self.raw_sentence = 'Any place with frites and Belgian beer has my vote.'
        self.sentence = tb.Sentence(self.raw_sentence)

    def test_len(self):
        self.assertEqual(len(self.sentence), len(self.raw_sentence))

  1. Apply the Rename Method refactoring with the new name 'text' to the method 'StringlikeMixin.__len__'
Langage dominant
Python
Étoiles
2.2k
Forks
197
Merge moyen
2 j 13 h
PR mergées (30 j)
5

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de python-rope/rope

Toutes les issues de python-rope/rope

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.