Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jonhnanthan opened this issue Feb 27, 2024 · 0 comments
Labels
bug Unexpected or incorrect user-visible behavior rename-refactor

Comments

@jonhnanthan
Copy link

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)))
@jonhnanthan jonhnanthan added the bug Unexpected or incorrect user-visible behavior label Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected or incorrect user-visible behavior rename-refactor
Projects
None yet
Development

No branches or pull requests

2 participants