prompt-toolkit / ptpython

A better Python REPL
BSD 3-Clause "New" or "Revised" License
5.23k stars 280 forks source link

Unhandled exception in event loop #353

Open hoangtranwork opened 4 years ago

hoangtranwork commented 4 years ago

Trying to edit the lambda call: (lambda x, y: (x + y) % 2)(1, 5)

And get this

Unhandled exception in event loop:
  File "/Users/hoang/.asdf/installs/python/3.8-dev/lib/python3.8/asyncio/events.py", line 81, in _run
    self._context.run(self._callback, *self._args)
  File "/Users/hoang/.asdf/installs/python/3.8-dev/lib/python3.8/site-packages/prompt_toolkit/eventloop/utils.py", line 72, in schedule
    func()
  File "/Users/hoang/.asdf/installs/python/3.8-dev/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 456, in redraw
    self._redraw()
  File "/Users/hoang/.asdf/installs/python/3.8-dev/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 523, in _redraw
    self.context.run(run_in_context)
  File "/Users/hoang/.asdf/installs/python/3.8-dev/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 509, in run_in_context
    self.renderer.render(self, self.layout)
  File "/Users/hoang/.asdf/installs/python/3.8-dev/lib/python3.8/site-packages/prompt_toolkit/renderer.py", line 606, in render
    screen.draw_all_floats()
  File "/Users/hoang/.asdf/installs/python/3.8-dev/lib/python3.8/site-packages/prompt_toolkit/layout/screen.py", line 249, in draw_all_floats
    functions[0][1]()
  File "/Users/hoang/.asdf/installs/python/3.8-dev/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 896, in _draw_float
    width = fl.content.preferred_width(write_position.width).preferred
  File "/Users/hoang/.asdf/installs/python/3.8-dev/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 2589, in preferred_width
    return self.content.preferred_width(max_available_width)
  File "/Users/hoang/.asdf/installs/python/3.8-dev/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 1593, in preferred_width
    return self._merge_dimensions(
  File "/Users/hoang/.asdf/installs/python/3.8-dev/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 1648, in _merge_dimensions
    preferred = get_preferred()
  File "/Users/hoang/.asdf/installs/python/3.8-dev/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 1583, in preferred_content_width
    preferred_width = self.content.preferred_width(
  File "/Users/hoang/.asdf/installs/python/3.8-dev/lib/python3.8/site-packages/prompt_toolkit/layout/controls.py", line 367, in preferred_width
    text = fragment_list_to_text(self._get_formatted_text_cached())
  File "/Users/hoang/.asdf/installs/python/3.8-dev/lib/python3.8/site-packages/prompt_toolkit/formatted_text/utils.py", line 57, in fragment_list_to_text
    return "".join(item[1] for item in fragments if ZeroWidthEscape not in item[0])

Exception sequence item 1: expected str instance, NoneType found
Press ENTER to continue...

Pressing ENTER doesnot help. The only way to escape is to restart the shell.

liavkoren commented 4 years ago

I got an extremely similar exception, doing from unittest.mock import call. The command wasn't actually executed, just typing the string into ptipython hard crashes with

Unhandled exception in event loop:
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/Users/liavkoren/Envs/suicidegirls/lib/python3.7/site-packages/prompt_toolkit/eventloop/utils.py", line 72, in schedule
    func()
  File "/Users/liavkoren/Envs/suicidegirls/lib/python3.7/site-packages/prompt_toolkit/application/application.py", line 456, in redraw
    self._redraw()
  File "/Users/liavkoren/Envs/suicidegirls/lib/python3.7/site-packages/prompt_toolkit/application/application.py", line 523, in _redraw
    self.context.run(run_in_context)
  File "/Users/liavkoren/Envs/suicidegirls/lib/python3.7/site-packages/prompt_toolkit/application/application.py", line 509, in run_in_context
    self.renderer.render(self, self.layout)
  File "/Users/liavkoren/Envs/suicidegirls/lib/python3.7/site-packages/prompt_toolkit/renderer.py", line 606, in render
    screen.draw_all_floats()
  File "/Users/liavkoren/Envs/suicidegirls/lib/python3.7/site-packages/prompt_toolkit/layout/screen.py", line 249, in draw_all_floats
    functions[0][1]()
  File "/Users/liavkoren/Envs/suicidegirls/lib/python3.7/site-packages/prompt_toolkit/layout/containers.py", line 896, in _draw_float
    width = fl.content.preferred_width(write_position.width).preferred
  File "/Users/liavkoren/Envs/suicidegirls/lib/python3.7/site-packages/prompt_toolkit/layout/containers.py", line 2589, in preferred_width
    return self.content.preferred_width(max_available_width)
  File "/Users/liavkoren/Envs/suicidegirls/lib/python3.7/site-packages/prompt_toolkit/layout/containers.py", line 1596, in preferred_width
    dont_extend=self.dont_extend_width(),
  File "/Users/liavkoren/Envs/suicidegirls/lib/python3.7/site-packages/prompt_toolkit/layout/containers.py", line 1648, in _merge_dimensions
    preferred = get_preferred()
  File "/Users/liavkoren/Envs/suicidegirls/lib/python3.7/site-packages/prompt_toolkit/layout/containers.py", line 1584, in preferred_content_width
    max_available_width - total_margin_width
  File "/Users/liavkoren/Envs/suicidegirls/lib/python3.7/site-packages/prompt_toolkit/layout/controls.py", line 367, in preferred_width
    text = fragment_list_to_text(self._get_formatted_text_cached())
  File "/Users/liavkoren/Envs/suicidegirls/lib/python3.7/site-packages/prompt_toolkit/layout/controls.py", line 359, in _get_formatted_text_cached
    get_app().render_counter, lambda: to_formatted_text(self.text, self.style)
  File "/Users/liavkoren/Envs/suicidegirls/lib/python3.7/site-packages/prompt_toolkit/cache.py", line 41, in get
    value = getter_func()
  File "/Users/liavkoren/Envs/suicidegirls/lib/python3.7/site-packages/prompt_toolkit/layout/controls.py", line 359, in <lambda>
    get_app().render_counter, lambda: to_formatted_text(self.text, self.style)
  File "/Users/liavkoren/Envs/suicidegirls/lib/python3.7/site-packages/prompt_toolkit/formatted_text/base.py", line 77, in to_formatted_text
    return to_formatted_text(value(), style=style)
  File "/Users/liavkoren/Envs/suicidegirls/lib/python3.7/site-packages/ptpython/layout.py", line 239, in get_text_fragments
    append((Signature, sig.full_name))
  File "/Users/liavkoren/Envs/suicidegirls/lib/python3.7/site-packages/jedi/api/classes.py", line 352, in full_name
    return '.'.join(names)

Exception sequence item 3: expected str instance, tuple found
Press ENTER to continue...

Ptpython v 3.0.1, python v 3.7.6.

derangedhk417 commented 3 years ago

I am having a similar issue whenever I start to type .to_numpy() on a pandas DataFrame. I get about part way through and end up with an exception being thrown.

Unhandled exception in event loop:
  File "/usr/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/arobinson/.local/lib/python3.7/site-packages/prompt_toolkit/eventloop/async_generator.py", line 43, in runner
    for item in get_iterable():
  File "/home/arobinson/.local/lib/python3.7/site-packages/prompt_toolkit/completion/base.py", line 226, in <lambda>
    lambda: self.completer.get_completions(document, complete_event)
  File "/home/arobinson/.local/lib/python3.7/site-packages/ptpython/completer.py", line 544, in get_completions
    completions = list(self.completer.get_completions(document, complete_event))
  File "/home/arobinson/.local/lib/python3.7/site-packages/ptpython/completer.py", line 230, in get_completions
    if jc.type == "function":
  File "/home/arobinson/.local/lib/python3.7/site-packages/jedi/api/classes.py", line 719, in type
    return super().type
  File "/home/arobinson/.local/lib/python3.7/site-packages/jedi/api/classes.py", line 189, in type
    return self._name.api_type
  File "/home/arobinson/.local/lib/python3.7/site-packages/jedi/inference/names.py", line 620, in __getattr__
    return getattr(self._wrapped_name, name)
  File "/home/arobinson/.local/lib/python3.7/site-packages/jedi/inference/value/klass.py", line 80, in api_type
    if definition.type == 'funcdef':

Exception 'NoneType' object has no attribute 'type'
Press ENTER to continue...