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

Aperta
#812 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 7 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
30/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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:

Lingua principale
Python
Stelle
2.2k
Fork
197
Merge medio
2g 13h
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python-rope/rope

Tutte le issue di python-rope/rope

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.