The Inline Method removes an overridden method

Aperta
#828 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 7 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
devtools

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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])
Lingua principale
Python
Stelle
2.2k
Fork
197
Merge medio
2g 13h
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python-rope/rope

Tutte le issue di python-rope/rope

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.