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

Abierto
#812 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 7 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
30/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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:

Lenguaje dominante
Python
Estrellas
2.2k
Forks
197
Merge medio
2 d 13 h
PR fusionados (30 d)
5

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de python-rope/rope

Todos los issues de python-rope/rope

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.