Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jedi doesn't show available methods for instances #558

Closed
tarjeiba opened this issue Mar 23, 2015 · 8 comments
Closed

Jedi doesn't show available methods for instances #558

tarjeiba opened this issue Mar 23, 2015 · 8 comments

Comments

@tarjeiba
Copy link

(This is a repost from the emacs-jedi issues, Issue #212.)

My configuration of jedi won't show available methods for an instance of a class, only for the class itself. The following will give no completion at the point

import matplotlib.pyplot as plt

fig = plt.figure()
fig.

while a corresponding plt.Figure instead of fig. will show all available methods. Does anyone have an idea of what may be wrong?

@davidhalter
Copy link
Owner

Hmm, what's your Jedi version? Have you tried the latest master branch?

@tarjeiba
Copy link
Author

Yes, I have tried using the latest master branch in a fresh python virtual environment with only matplotlib installed.

@tarjeiba
Copy link
Author

Could this be related to Issue 372? I get autocomplete for a. in the snippet below, but not for b.

import numpy as np
a = [1,2]
a.
b = np.array([1,2])
b.

@davidhalter
Copy link
Owner

Can you give me the completion output of just plt.figure?

@tarjeiba
Copy link
Author

>>> import jedi
>>> source1 = '''
... import matplotlib.pyplot as plt
... fig = plt.figure()
... fig.'''
>>> source2 = '''
... import matplotlib.pyplot as plt
... plt.figure.'''
>>> script1 = jedi.Script(source1, 3, len('fig.'), 'example1.py')
>>> script2 = jedi.Script(source2, 3, len('plt.figure.'), 'example2.py')
>>> completions1 = script1.completions()
>>> print completions1[0].complete
abs
>>> completions2 = script2.completions()
>>> print completions2[0].complete
func_closure

...so everything seems to be in order. Still, no completion shows when used in Emacs. I find it strange that it finds completions for other, "simpler", types, though. As the list example above. I'm not sure whether this is an emacs or emacs-jedi issue.

@davidhalter
Copy link
Owner

What you missed is that func_closure is the completion of a function object, not an actual class. People tend to think that numpy/matplotlib uses classes, that you instantiate. This is not true. Most of the time you call a function that returns you an object of something, but you don't call the object itself (because they need to handle the content of the object first).

So what's happening here is simple, plt.figure is a function and therefore gets executed. The execution is too complicated for Jedi (i.e. matplotlib uses a weird caching mechanism that Jedi doesn't understand and therefore cannot evaluate the return value).

This is not a bug - it's simply one of the things Jedi - at the moment - cannot understand, so I'm closing it.

@tarjeiba
Copy link
Author

That explains it. Thanks for the thorough follow-up.

And this is the same for numpy arrays?

@davidhalter
Copy link
Owner

If they are not working - yes! (I know that it's a function, so...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants