The Inline Method removes an overridden method

Offen
#828 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 7 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Veraltet
Tech-Stack
python
Bereich
devtools

Rechercherichtung

Start by running the two-class snippet in the issue (WordList overriding append and extend) and confirm the before-and-after output differs. Then apply Inline Method to WordList.extend in rope and find where the inlining step decides which calls to keep. The issue does not name rope's internal files, so locate them from that entry point. Done means the inlined code still routes each element through the overridden append, so Word objects are still created.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

bug

The Inline Method removes an overridden method that changes the type of the stored objects.

Steps to reproduce the behavior:

  1. Code before refactoring:
class Word(str):
    def __new__(cls, value):
        print(f"criando Word({value!r})")
        return super().__new__(cls, value)


class WordList(list):
    def append(self, obj):
        print(f"append: recebi {obj!r} (type={type(obj).__name__})")
        if isinstance(obj, str) and not isinstance(obj, Word):
            obj = Word(obj)
        super().append(obj)

    def extend(self, iterable):
        print("extend (custom): chamando append para cada elemento")
        for e in iterable:
            self.append(e)


wl = WordList()
wl.extend(["ola", "mundo"])
print("conteúdo wl:", wl)
print("types wl:", [type(x).__name__ for x in wl])
  1. Apply the inline method to WordList.extend

  2. Code after refactoring:

class Word(str):
    def __new__(cls, value):
        print(f"criando Word({value!r})")
        return super().__new__(cls, value)


class WordList(list):
    def append(self, obj):
        print(f"append: recebi {obj!r} (type={type(obj).__name__})")
        if isinstance(obj, str) and not isinstance(obj, Word):
            obj = Word(obj)
        super().append(obj)


wl = WordList()
wl.extend(["ola", "mundo"])
print("conteúdo wl:", wl)
print("types wl:", [type(x).__name__ for x in wl])
Vorherrschende Sprache
Python
Sterne
2.2k
Forks
197
Ø Merge
2 T. 13 Std.
Gemergte PRs (30 T.)
5

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus python-rope/rope

Alle Issues in python-rope/rope

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.