0

Consider the following very simple Python project tree:

.
├── main.py
└── second.py

main.py:

import second as s

def foo(arg):
    arg.helloWorld()

foo(s)

second.py:

def helloWorld():
    print("Hello World!")

My Jedi setup in ~/.emacs.d/init.el is the same as this file, but you can also see my exact setup here.

This project runs fine (python main.py outputs Hello World!) but running jedi:goto-definition on the helloWorld in arg.helloWorld() gives Definition not found.. However, if I were to change main.py directly to:

import second as s

s.helloWorld()

Now jedi:goto-definition works and jumps to the def helloWorld() in second.py! So it looks to be a problem with Jedi not recognizing arg as coming from s? I am new to Python and maybe there is an intricacy that I am missing... but the bottom line is that I want Jedi to jump to the definition of helloWorld. How do I achieve this? Thanks for helping!

1

Works as expected for me:

$ pip show jedi
---
Name: jedi
Version: 0.10.0
Location: /usr/local/lib/python2.7/dist-packages
Requires:

Ensure the latest version of Jedi:

pip install --upgrade jedi
|improve this answer|||||
  • Can you please provide your jedi config? – space_voyager Feb 27 '17 at 14:47
  • Ok, now my example is working for some reason... but doing jedi:goto-definition does not work for addDesignVariables on line 49 of this code. Why is that? – space_voyager Feb 27 '17 at 17:11
0

foo can be called with any arg, (arg should have a helloWorld method if you don't want to raise an exception, but it doesn't have to...), so it is impossible to know what arg could be in the function.

If you have for example:

import second as s

class Hello:
    def helloWorld(self):
        print('I can say hello too!')

def foo(arg):
    arg.helloWorld() # Where could helloWorld come from?

foo(s)         # from s?
foo(Hello())   # from Hello?
foo(2)         # doesn't even exist

So, jedi can't know...

|improve this answer|||||
  • Could you expand on your answer, please? – Dan Feb 27 '17 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.