`findit.find_implementations` on method call finds implementation for different subclass

Đang mở
#812 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
30/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
developer-experience

Hướng nghiên cứu

The reproduction is in example.py and bug.py using rope.contrib.findit.find_implementations on the a.f() call at line 10. Start by reading find_implementations in rope/contrib/findit.py and how it resolves the type of a to its defining class. Done means the call resolves to A.f and not B.f, with the reproduction printing line 2.

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

Mô tả

bug

Describe the bug
Running Rope's rope.contrib.findit.find_implementations on the a.f() call in a file like

class A:
  def f(self):
    return 1

class B(A):
  def f(self):
    return 2

a: A = A()
a.f()

makes it return the position of B.f, which has nothing to do with that call as it's only related to A.

To Reproduce

Save the snippet above as example.py and run this script (let's call it bug.py) in the same folder:

from rope.base.project import Project
from rope.contrib.findit import find_implementations

project = Project(".")
resource = project.get_file("example.py")
pymodule = project.get_pymodule(resource)

call_offset = pymodule.lines.get_line_start(10) + 2  # l. 10: a.f()
for loc in find_implementations(project, resource, call_offset):
  print(loc.lineno)

Expected behavior:

It should output 2, as line 2 is where A.f which is being called here is defined.

Actual behavior:

It outputs (line) 6, which is where B.f is defined. B.f has nothing to do with the call a.f, except that it happens to be an implementation of A.f as well (but that is not the implementation we're calling!).

Screenshots
None required.

Editor information (please complete the following information):
No editor needed to reproduce.

Additional context
This was found while trying to use findit.find_implementations to add support for the LSP textDocument/implementation capability to python-lsp-server:

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.