Inline method refactoring passes the wrong parameter to the inlined function body

オープン
#760 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 7 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
tooling

調査の方向性

Start from the reproduction in the issue: apply Inline Method to PatternParser.parse in en/parsers.py and check the call in test.py's test_parse. The bad output is self.assertEqual(pattern_parse(__0__self.parser.text), ...), where the argument should stay self.text. Done when the inlined call passes the original argument and the test passes. The payload names no rope source files, so locate the inline refactoring code yourself.

索引モデルが issue の本文から書いたものです。

説明

bug inline-refactor

Inline method refactoring passes the wrong parameter to the inlined function body

Steps to reproduce the behavior:

  1. Code before refactoring:

structure

-- en
---- __init.py__
---- parsers.py
-- test
---- __init.py__
---- test.py

en.__init.py__:

class Parser(object):
    def __init__(self, lexicon={}, default=("NN", "NNP", "CD"), language=None):
        self.lexicon = lexicon
        self.default = default
        self.language = language

    def parse(self, s, tokenize=True, tags=True, chunks=True, relations=False, lemmata=False, encoding="utf-8", **kwargs):
        pass


parser = Parser(
    default=("NN", "NNP", "CD"),
    language="en"
)


def parse(s, *args, **kwargs):
    return parser.parse(s, *args, **kwargs)

en.parsers.py:

from abc import abstractmethod
from en import parse as pattern_parse


class BaseParser(object):
    @abstractmethod
    def parse(self, text):
        return


class PatternParser(BaseParser):

    def parse(self, text):
        return pattern_parse(text)

test.test.py:

import unittest

from en import parse as pattern_parse
import en.parsers as parsers


class TestPatternParser(unittest.TestCase):

    def setUp(self):
        self.parser = PatternParser()
        self.text = "And now for something completely different."

    def test_parse(self):
        self.assertEqual(self.parser.parse(self.text), pattern_parse(self.text))

  1. Apply the Inline Method refactoring to 'PatternParser.parse'

  2. Expected code after refactoring:

en.__init.py__:

class Parser(object):
    def __init__(self, lexicon={}, default=("NN", "NNP", "CD"), language=None):
        self.lexicon = lexicon
        self.default = default
        self.language = language

    def parse(self, s, tokenize=True, tags=True, chunks=True, relations=False, lemmata=False, encoding="utf-8", **kwargs):
        pass


parser = Parser(
    default=("NN", "NNP", "CD"),
    language="en"
)


def parse(s, *args, **kwargs):
    return parser.parse(s, *args, **kwargs)

en.parsers.py:

from abc import abstractmethod
from en import parse as pattern_parse


class BaseParser(object):
    @abstractmethod
    def parse(self, text):
        return


class PatternParser(BaseParser):

    pass

test.test.py:

import unittest

from en import parse as pattern_parse
import en.parsers as parsers


class TestPatternParser(unittest.TestCase):

    def setUp(self):
        self.parser = PatternParser()
        self.text = "And now for something completely different."

    def test_parse(self):
        self.assertEqual(pattern_parse(self.text), pattern_parse(self.text))

The transformation changes the attribute that is passed to the original function.
The result is: self.assertEqual(pattern_parse(__0__self.parser.text), pattern_parse(self.text))
Causing test fail

主要言語
Python
スター
2.2k
フォーク
197
平均マージ
2日 13時間
マージ済み PR(30日)
5

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python-rope/rope のほかの issue

python-rope/rope の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。