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

Đang mở
#760 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 7 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
tooling

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Python
Star
2.2k
Fork
197
Merge trung bình
2 ngày 13 giờ
Pull request đã merge (30 ngày)
5

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của python-rope/rope

Tất cả issue của python-rope/rope

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.