The Inline Method removes an overridden method

Đang mở
#828 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ó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
devtools

Hướng nghiên cứu

Start by running the two-class snippet in the issue (WordList overriding append and extend) and confirm the before-and-after output differs. Then apply Inline Method to WordList.extend in rope and find where the inlining step decides which calls to keep. The issue does not name rope's internal files, so locate them from that entry point. Done means the inlined code still routes each element through the overridden append, so Word objects are still created.

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

Mô tả

bug

The Inline Method removes an overridden method that changes the type of the stored objects.

Steps to reproduce the behavior:

  1. Code before refactoring:
class Word(str):
    def __new__(cls, value):
        print(f"criando Word({value!r})")
        return super().__new__(cls, value)


class WordList(list):
    def append(self, obj):
        print(f"append: recebi {obj!r} (type={type(obj).__name__})")
        if isinstance(obj, str) and not isinstance(obj, Word):
            obj = Word(obj)
        super().append(obj)

    def extend(self, iterable):
        print("extend (custom): chamando append para cada elemento")
        for e in iterable:
            self.append(e)


wl = WordList()
wl.extend(["ola", "mundo"])
print("conteúdo wl:", wl)
print("types wl:", [type(x).__name__ for x in wl])
  1. Apply the inline method to WordList.extend

  2. Code after refactoring:

class Word(str):
    def __new__(cls, value):
        print(f"criando Word({value!r})")
        return super().__new__(cls, value)


class WordList(list):
    def append(self, obj):
        print(f"append: recebi {obj!r} (type={type(obj).__name__})")
        if isinstance(obj, str) and not isinstance(obj, Word):
            obj = Word(obj)
        super().append(obj)


wl = WordList()
wl.extend(["ola", "mundo"])
print("conteúdo wl:", wl)
print("types wl:", [type(x).__name__ for x in wl])
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.