rope icon indicating copy to clipboard operation
rope copied to clipboard

The Inline Method refactoring removed an import

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

The Inline Method refactoring removed an import from the test file, causing an error when the test file is run.

Steps to reproduce the behavior:

  1. Code before refactoring:
-- mixins.py
from __future__ import unicode_literals

class StringlikeMixin(object):
    def __init__(self, text):
        self._text = text

    def _strkey(self):
        return self._text

    def find(self, sub, start=0, end=None):
        if end is None:
            end = len(self._strkey())
        return self._strkey().find(sub, start, end)

-- test_mixins.py
from __future__ import unicode_literals, absolute_import
from nose.tools import *
from mixins import StringlikeMixin


def test_find():
    text = 'Beautiful is better than ugly.'
    blob = StringlikeMixin(text)

    assert_equal(
        blob.find('better', 5, len(blob._strkey())),
        text.find('better', 5, len(text))
    )
  1. Apply the inline method to StringlikeMixin.find

  2. Code after refactoring:

-- mixins.py
from __future__ import unicode_literals

class StringlikeMixin(object):
    def __init__(self, text):
        self._text = text

    def _strkey(self):
        return self._text


-- test_mixins.py
from __future__ import unicode_literals, absolute_import

from mixins import StringlikeMixin

def test_find():
    text = 'Beautiful is better than ugly.'
    blob = StringlikeMixin(text)

    assert_equal(
        blob._strkey().find('better', 5, len(blob._strkey())),
        text.find('better', 5, len(text))
    )

jonh-copin avatar Nov 24 '25 19:11 jonh-copin