The Inline Method removes an overridden method

オープン
#828 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 7 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python
領域
devtools

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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])
主要言語
Python
スター
2.2k
フォーク
197
平均マージ
2日 13時間
マージ済み PR(30日)
5

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python-rope/rope のほかの issue

python-rope/rope の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。