rope icon indicating copy to clipboard operation
rope copied to clipboard

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

Open jonh-copin opened this issue 1 year ago • 0 comments

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)))

jonh-copin avatar Feb 27 '24 13:02 jonh-copin