rope icon indicating copy to clipboard operation
rope copied to clipboard

Rename Method refactoring allowed for methods defined to implement container objects

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

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__'

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