prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.11k stars 717 forks source link

local variable 'mouse_modifiers' referenced before assignment #1572

Open ale-dd opened 2 years ago

ale-dd commented 2 years ago

Since upgrading from prompt-toolkit==3.0.19 to prompt-toolkit==3.0.28, I started seeing this issue pretty frequently.


  File "/usr/lib/python3.9/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/root/.local/lib/python3.9/site-packages/prompt_toolkit/application/application.py", line 711, in read_from_input
    self.key_processor.process_keys()
  File "/root/.local/lib/python3.9/site-packages/prompt_toolkit/key_binding/key_processor.py", line 270, in process_keys
    self._process_coroutine.send(key_press)
  File "/root/.local/lib/python3.9/site-packages/prompt_toolkit/key_binding/key_processor.py", line 185, in _process
    self._call_handler(matches[-1], key_sequence=buffer[:])
  File "/root/.local/lib/python3.9/site-packages/prompt_toolkit/key_binding/key_processor.py", line 320, in _call_handler
    handler.call(event)
  File "/root/.local/lib/python3.9/site-packages/prompt_toolkit/key_binding/key_bindings.py", line 124, in call
    result = self.handler(event)
  File "/root/.local/lib/python3.9/site-packages/prompt_toolkit/key_binding/bindings/mouse.py", line 279, in _
    modifiers=mouse_modifiers,

Exception local variable 'mouse_modifiers' referenced before assignment
Press ENTER to continue...```
jonathanslenders commented 2 years ago

Thanks for reporting!

I think there's a typo on this line: https://github.com/prompt-toolkit/python-prompt-toolkit/blob/f3088dc4b19148f378e458249a50b020d4fe7a04/prompt_toolkit/key_binding/bindings/mouse.py#L205 That should be mouse_modifiers instead of mouse_modifier there.

jonathanslenders commented 2 years ago

Fix: https://github.com/prompt-toolkit/python-prompt-toolkit/pull/1574