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

Exception in jedi crashes ptpython #47

Open
pgy opened this issue Jun 9, 2015 · 4 comments
Open

Exception in jedi crashes ptpython #47

pgy opened this issue Jun 9, 2015 · 4 comments
Labels

Comments

@pgy
Copy link

pgy commented Jun 9, 2015

The following crashes ptpython, it exists (with status 1) immediately after entering the '=' sign.

In [1]: import aiohttp
In [2]: aiohttp.ProxyConnector(proxy=Traceback (most recent call last):
  File "/home/pgy/.pyenv/versions/3.4.3/bin/ptpython", line 11, in <module>
    sys.exit(run())                            
  File "/home/pgy/.pyenv/versions/3.4.3/lib/python3.4/site-packages/ptpython/entry_pointn
    startup_paths=startup_paths)               
  File "/home/pgy/.pyenv/versions/3.4.3/lib/python3.4/site-packages/ptpython/repl.py", ld
    cli.run()                                  
  File "/home/pgy/.pyenv/versions/3.4.3/lib/python3.4/site-packages/prompt_toolkit/intern
    self.eventloop.run(self.input, self.create_eventloop_callbacks())
  File "/home/pgy/.pyenv/versions/3.4.3/lib/python3.4/site-packages/prompt_toolkit/eventn
    c()                                        
  File "/home/pgy/.pyenv/versions/3.4.3/lib/python3.4/site-packages/prompt_toolkit/interw
    is_done=self.is_done)                      
  File "/home/pgy/.pyenv/versions/3.4.3/lib/python3.4/site-packages/prompt_toolkit/render
    extended_height=size.rows,
  File "/home/pgy/.pyenv/versions/3.4.3/lib/python3.4/site-packages/prompt_toolkit/layoun
    c.write_to_screen(cli, screen, WritePosition(xpos, ypos, width, s))r - CPython 3.4.3 
  File "/home/pgy/.pyenv/versions/3.4.3/lib/python3.4/site-packages/prompt_toolkit/layoun
    c.write_to_screen(cli, screen, WritePosition(xpos, ypos, s, height))
  File "/home/pgy/.pyenv/versions/3.4.3/lib/python3.4/site-packages/prompt_toolkit/layoun
    c.write_to_screen(cli, screen, WritePosition(xpos, ypos, width, s))
  File "/home/pgy/.pyenv/versions/3.4.3/lib/python3.4/site-packages/prompt_toolkit/layoun
    width = fl.content.width(cli).preferred
  File "/home/pgy/.pyenv/versions/3.4.3/lib/python3.4/site-packages/prompt_toolkit/layouh
    preferred_width = self.content.preferred_width(cli)
  File "/home/pgy/.pyenv/versions/3.4.3/lib/python3.4/site-packages/prompt_toolkit/layouh
    text = ''.join(t[1] for t in self.get_tokens(cli))
  File "/home/pgy/.pyenv/versions/3.4.3/lib/python3.4/site-packages/ptpython/layout.py",s
    for i, p in enumerate(sig.params):
  File "/home/pgy/.pyenv/versions/3.4.3/lib/python3.4/site-packages/jedi/evaluate/cache.r
    rv = function(obj, *args, **kwargs)
  File "/home/pgy/.pyenv/versions/3.4.3/lib/python3.4/site-packages/jedi/api/classes.py"s
    return [_Param(self._evaluator, p.name) for p in params]
  File "/home/pgy/.pyenv/versions/3.4.3/lib/python3.4/site-packages/jedi/api/classes.py">
    return [_Param(self._evaluator, p.name) for p in params]
  File "/home/pgy/.pyenv/versions/3.4.3/lib/python3.4/site-packages/jedi/evaluate/cache.r
    rv = function(obj, *args, **kwargs)
  File "/home/pgy/.pyenv/versions/3.4.3/lib/python3.4/site-packages/jedi/evaluate/cache._
    return super(CachedMetaClass, self).__call__(*args, **kwargs)
  File "/home/pgy/.pyenv/versions/3.4.3/lib/python3.4/site-packages/jedi/api/classes.py"_
    super(Definition, self).__init__(evaluator, definition)
  File "/home/pgy/.pyenv/versions/3.4.3/lib/python3.4/site-packages/jedi/api/classes.py"_
    self._definition = evaluator.wrap(self._name.get_definition())
AttributeError: 'Operator' object has no attribute 'get_definition'
@jonathanslenders
Copy link
Member

Hi @pgy , Thanks for reporting.
This is a bug in Jedi: davidhalter/jedi#598 and I'll write a workaround.

@jonathanslenders
Copy link
Member

So, the following patch prevents ptpython from crashing. There is still a bug in Jedi that prevents us from getting the right index when passing after the *. I'm not going to commit this yet, I'm not in favour of adding again two try/catch statements. Lets wait for a reply from @davidhalter.

diff --git a/ptpython/layout.py b/ptpython/layout.py
index 5e13060..86037ed 100644
--- a/ptpython/layout.py
+++ b/ptpython/layout.py
@@ -113,12 +113,14 @@ class SignatureToolbar(Window):
                 append((Signature.Operator, '('))

                 for i, p in enumerate(sig.params):
+                    # p is None when we hit the '*' in the signature.
+                    description = p.description if p else '*'
+
+                    try:
+                        sig_index = sig.index
+                    except AttributeError:
+                        sig_index = 0 
+                     if i == sig_index:
-                     if i == sig.index:
                         # Note: we use `_Param.description` instead of
                         #       `_Param.name`, that way we also get the '*' before args.
-                        append((Signature.CurrentName, str(p.description)))
+                        append((Signature.CurrentName, str(description)))
                     else:
-                        append((Signature, str(p.description)))
+                        append((Signature, str(description or '--')))
                     append((Signature.Operator, ', '))

                 if sig.params:
diff --git a/ptpython/python_input.py b/ptpython/python_input.py
index f2167be..62939db 100644
--- a/ptpython/python_input.py
+++ b/ptpython/python_input.py
@@ -406,6 +406,13 @@ class PythonInput(object):
             else:
                 signatures = []

+            if signatures:
+                try:
+                    # Access the params attribute just once. Next time it doesn't give AttributeError.
+                    signatures[0].params
+                except AttributeError:
+                    pass
+                signatures[0].params
+
             self._get_signatures_thread_running = False

             # Set signatures and redraw if the text didn't change in the

@jonathanslenders
Copy link
Member

Workaround implemented: 3397e9a

Probably I'll do a new release very soon.
Thanks @pgy!

@davidhalter
Copy link

@jonathanslenders The * is something that is not properly implemented in Jedi. You can add an issue (if there's not already one). However note that I'm currently not working full time on it.

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

No branches or pull requests

3 participants