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

Aberta
#812 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 7 dias

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
30/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Estagnada
Stack de tecnologia
python

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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:

Linguagem predominante
Python
Estrelas
2.2k
Forks
197
Merge médio
2d 13h
PRs com merge (30d)
5

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de python-rope/rope

Todas as issues de python-rope/rope

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.