rope icon indicating copy to clipboard operation
rope copied to clipboard

Inline method refactoring inserts an unexpected argument

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

Inline method refactoring inserts an unexpected argument in the method call.

Steps to reproduce the behavior:

  1. Code before refactoring:

structure:

-- main ---- __init__.py ---- blob.py -- test ---- __init__.py ---- test.py

blob.py:

class Word(str):

    def translate_to(self, source, from_lang='auto', to_lang='en', host=None):
        pass

    def translate(self, from_lang='auto', to="en"):
        return self.translate_to('string', from_lang=from_lang, to_lang=to)

test.py:

import main as tb
from unittest import TestCase


class WordTest(TestCase):

    def test_translate(self, mock_translate):
        mock_translate.return_value = 'gato'
        assert_equal(tb.Word("cat").translate(to="es"), "gato")

  1. Apply the Inline Method refactoring to the 'Word.translate' in 'blob.py'

  2. Expected code after refactoring:

blob.py:

class Word(str):

    def translate_to(self, source, from_lang='auto', to_lang='en', host=None):
        pass

test.py:

import main as tb
from unittest import TestCase


class WordTest(TestCase):

    def test_translate(self, mock_translate):
        mock_translate.return_value = 'gato'
        assert_equal(tb.Word("cat").translate_to('string', __0__from_lang='auto', to_lang="es"), "gato")

jonh-copin avatar Feb 26 '24 21:02 jonh-copin