davidhalter / jedi

Awesome autocompletion, static analysis and refactoring library for python
http://jedi.readthedocs.io
Other
5.8k stars 508 forks source link

'CompiledObject' object has no attribute 'params' #373

Closed ColinDuquesnoy closed 10 years ago

ColinDuquesnoy commented 10 years ago

Hi,

I have an issue when I try to print the parameters of a call def.

This used to work with Jedi 0.7.0. The error happens with both python 2.7 and python 3.3.

For example, running this script :

import jedi
print(jedi.__version__)
code = "open("
s = jedi.Script(code)
defs = s.call_signatures()
for call_def in defs:
    for p in call_def.params:
        print(p)

leads to the following traceback:

0.8.0-alpha1
Traceback (most recent call last):
  File "D:/test.py", line 7, in <module>
    for p in call_def.params:
  File "C:\Python27\lib\site-packages\jedi-0.8.0_alpha1-py2.7.egg\jedi\api\classes.py", line 599, in params
    return sub.params[1:]  # ignore self
AttributeError: 'CompiledObject' object has no attribute 'params'
davidhalter commented 10 years ago

Thank you for the report. I've seen this before, but I might have forgotten about it...

ColinDuquesnoy commented 10 years ago

Hi, this seems to be fixed by your last commits, for builtins only:

colin@mint16 ~ $ python3
Python 3.3.2+ (default, Oct  9 2013, 14:56:03) 
[GCC 4.8.1] on linux
Type "help", "copyright", "credits" or "license" for more information
>>> import jedi
>>> print(jedi.__version__)
0.8.0-alpha1
>>> code = "open("
>>> s = jedi.Script(code)
>>> defs = s.call_signatures()
>>> for call_def in defs:
...     for p in call_def.params:
...         print(p)
... 
<Param: file @48,9>
<Param: mode = 'r' @48,15>
<Param: buffering = -1 @48,25>
<Param: encoding = None @48,39>
<Param: errors = None @48,54>
<Param: newline = None @48,67>
<Param: closefd = True @48,81>
>>> 

But that does not work on real compiled module (PyQt4):

colin@mint16 ~ $ python3
Python 3.3.2+ (default, Oct  9 2013, 14:56:03) 
[GCC 4.8.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import jedi
>>> print(jedi.__version__)
0.8.0-alpha1
>>> code = "from PyQt4.QtGui import QApplication; QApplication.instance("
>>> s = jedi.Script(code)
>>> defs = s.call_signatures()
>>> for call_def in defs:
...     for p in call_def.params:
...         print(p)
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/home/colin/Dev/jedi/jedi/api/classes.py", line 560, in params
    return sub.params[1:]  # ignore self
AttributeError: 'CompiledObject' object has no attribute 'params'
>>> 
davidhalter commented 10 years ago

open is a "faked" builtin, which means there's a python implementation in evaluate/fake/fake/builtins.pym. This hasn't been fixed, yet.

ColinDuquesnoy commented 10 years ago

Ok I see. If I can find some time this evening, I will try to look into this issue.

davidhalter commented 10 years ago

Look at evalutate.compiled.CompiledObject._parse_function_doc. That function returns the parsed params. You probably just have to create a params property..