jorgenschaefer / elpy

Emacs Python Development Environment
GNU General Public License v3.0
1.9k stars 260 forks source link

elpy-goto-definition strange behavior with variables holding class reference #1145

Open piojanu opened 7 years ago

piojanu commented 7 years ago

Hi!

I made fresh elpy installation with python plugins: jedi flake8 importmagic autopep8 (after ubuntu format). I use jedi as a backend.

Now, let's consider this example:

1  class SomeClass:
2    def say(self):
3      return "Say what?!"
4  
5  
6  res = "Hello World!"
7  print res
8  
9  cls = SomeClass()
10 res2 = cls.say()
11 print res2

If you want to find definition of res in line 7 and use elpy-goto-definition, it properly finds line 6. But, if you want to find definition of cls in line 10, it jumps to the class name in line 1. Is it expected? For me it seems like a bug and I think, it worked differently in the past. jedi:goto-deinition seems to do it more reasonable and jumps to line 9, which is proper definition. If i'd want to find a class, I'd go to line 9 and use goto-definition over class name. This case works good for both elpy and jedi functions.

Thanks, Piotr

jorgenschaefer commented 7 years ago

Hello, and thanks for the report! Jedi provides two types of "find definition" functions, and both can return multiple responses … the logic Elpy currently uses was defined a whole long time ago (at least two almost full rewrites of Jedi ago), and might not be quite sensible now anymore.

I'll keep this issue open to keep in mind that the logic might reworking.

CakeBrewery commented 7 years ago

I am having a similar issue.

Will calling elpy-goto-definition with variable elpy-rpc-backend set to "jedi" make it call jedi:goto-definition instead? That's what I thought, but I am having different results.

jedi:goto-definition correctly takes me to the function argument definition when the pointer is on a or b within the following function, even if I delete test(1, 2).

def test(a, b):
    print(a + b)

test(1, 2)  # If I delete this line, elpy-goto-definition does not work for variables a and b. 

elpy-goto-definition does not do find the definition for both a and b variables, unless I call the function (with test(1, 2) for example). If that line is deleted elpy-goto-definition does not work.

I was under the impression that using jedi as an RPC backend for elpy would result in it calling jedi:goto-definition.

I am using Ubuntu 17.10.