rope icon indicating copy to clipboard operation
rope copied to clipboard

Applying the Inline Method refactoring does not add the required import.

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

Steps to reproduce the behavior:

  1. 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'])
  1. Apply the Inline Method to Base.split().

  2. 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'])
  1. The "import sys" is not automatically added.

jonh-copin avatar Jan 15 '24 16:01 jonh-copin