rope
rope copied to clipboard
Rename Method refactoring does not rename all implementations of an abstract method
Steps to reproduce the behavior:
- 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)))
-
Apply the Rename Method refactoring with the new name 'continuous' to the method 'BaseTokenizer.tokenize'
-
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)))