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 allowed for methods defined to implement container objects #775

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

Comments

@researcher175
Copy link

Rename Method refactoring allowed for methods defined to implement container objects
It would be nice if Rope sent an alert to the user to avoid incompatible parameter type errors when using the "len()" function.

Steps to reproduce the behavior:

  1. Code before refactoring:

structure

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

main.py:

implements_to_string = lambda x: x

@implements_to_string
class StringlikeMixin(object):

    def __len__(self):
        return len(self._strkey())


class BaseBlob(StringlikeMixin):
    def __init__(self, text):
        self.raw = text

    def _strkey(self):
        return self.raw


class Sentence(BaseBlob):
    def __init__(self, sentence, start_index=0, end_index=None, *args, **kwargs):
        super(Sentence, self).__init__(sentence, *args, **kwargs)

test.py:

from unittest import TestCase
from main import main as tb

class SentenceTest(TestCase):

    def setUp(self):
        self.raw_sentence = 'Any place with frites and Belgian beer has my vote.'
        self.sentence = tb.Sentence(self.raw_sentence)

    def test_len(self):
        self.assertEqual(len(self.sentence), len(self.raw_sentence))
  1. Apply the Rename Method refactoring with the new name 'text' to the method 'StringlikeMixin.__len__'
@researcher175 researcher175 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