rope
rope copied to clipboard
Applying the Inline Method refactoring does not add the required import.
Steps to reproduce the behavior:
- Code before refactoring:
structure: project | - src | -- __init__.py | -- main.py | -- test.py
main.py
import sys
class Base:
def __init__(self, text):
self.raw = text
def split(self, sep=None, maxsplit=sys.maxsize):
return self.raw.split(sep, maxsplit)[0]
test.py
from unittest import TestCase
from src.split_main import Base
class Test(TestCase):
def test_split(self):
blob = Base('Beautiful is better')
self.assertEqual(blob.split(), ['Beautiful'])
-
Apply the Inline Method to Base.split().
-
Expected code after refactoring:
structure: project | - src | -- __init__.py | -- main.py | -- test.py
main.py
class Base:
def __init__(self, text):
self.raw = text
test.py
import sys
from unittest import TestCase
from src.split_main import Base
class Test(TestCase):
def test_split(self):
blob = Base('Beautiful is better')
self.assertEqual(blob.raw.split(None, sys.maxsize)[0], ['Beautiful'])
- The "import sys" is not automatically added.