Rename Method refactoring does not rename all implementations of an abstract method

未關閉
#774 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 7 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
python
領域
devtools

研究方向

Start from the reproduction in the issue: a base.py with abstract BaseTokenizer.tokenize, its WordTokenizer override, and the BaseBlob.tokens call site. Apply Rename Method to the abstract method and check which overrides and call sites are missed. Done means the reproduction's expected output is reached, with overrides and calls renamed together and test.py still valid. The payload names no rope source files, so locate the rename logic yourself.

由索引模型根據 Issue 內容生成。

描述

bug rename-refactor

Steps to reproduce the behavior:

  1. Code before refactoring:

structure

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

base.py:

from abc import abstractmethod, ABC


class BaseTokenizer(ABC):
    @abstractmethod
    def tokenize(self, text):
        return

    def itokenize(self, text, *args, **kwargs):
        return (t for t in self.tokenize(text, *args, **kwargs))


class WordTokenizer(BaseTokenizer):
    def tokenize(self, text, include_punc=True):
        return []


class BaseBlob(object):
    tokenizer = WordTokenizer()

    def __init__(self, text):
        self.raw = self.string = text

    def tokens(self):
        return list(self.tokenizer.tokenize(self.raw))


class TextBlob(BaseBlob):
    pass

test.py:

from unittest import TestCase, main
from main import base as tb
from main.base import WordTokenizer

class TextBlobTest(TestCase):

    def setUp(self):
        self.text = 'Explicit is better than implicit.'
        self.blob = tb.TextBlob(self.text)

    def test_tokens_property(self):
        self.assertTrue(self.blob.tokens, list(WordTokenizer().tokenize(self.text)))

  1. Apply the Rename Method refactoring with the new name 'continuous' to the method 'BaseTokenizer.tokenize'

  2. Expected code after refactoring:

structure:

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

base.py:

from abc import abstractmethod, ABC


class BaseTokenizer(ABC):
    @abstractmethod
    def CONTINUOUS(self, text):
        return

    def itokenize(self, text, *args, **kwargs):
        return (t for t in self.CONTINUOUS(text, *args, **kwargs))


class WordTokenizer(BaseTokenizer):
    def CONTINUOUS(self, text, include_punc=True):
        return []


class BaseBlob(object):
    tokenizer = WordTokenizer()

    def __init__(self, text):
        self.raw = self.string = text

    def tokens(self):
        return list(self.tokenizer.CONTINUOUS(self.raw))


class TextBlob(BaseBlob):
    pass

test.py:

from unittest import TestCase, main
from main import base as tb
from main.base import WordTokenizer

class TextBlobTest(TestCase):

    def setUp(self):
        self.text = 'Explicit is better than implicit.'
        self.blob = tb.TextBlob(self.text)

    def test_tokens_property(self):
        self.assertTrue(self.blob.tokens, list(WordTokenizer().CONTINUOUS(self.text)))

主要語言
Python
星號
2.2k
分支
197
平均合併
2 天 13 小時
30 天內合併 PR
5

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

python-rope/rope 的其他 Issue

查看 python-rope/rope 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。