8000 `findit.find_implementations` on method call finds implementation for different subclass · Issue #812 · python-rope/rope · GitHub
[go: up one dir, main page]

Skip to content
findit.find_implementations on method call finds implementation for different subclass #812
@smheidrich

Description

@smheidrich

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUnexpected or incorrect user-visible behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0