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

Fixes bug whereby read_only bool is called as a function #1944

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

technige
Copy link

@technige technige commented Dec 13, 2024

This is a simple bug fix to remedy the following issue:

  File ".../site-packages/prompt_toolkit/filters/app.py", line 374, in emacs_insert_mode
    or app.current_buffer.read_only()
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Exception 'bool' object is not callable

It would appear to be a simple typo, calling the boolean read_only property as if it were a function.

@jonathanslenders
Copy link
Member

Hi @technige, how do you reproduce this? Buffer.read_only is supposed to be of type Filter which is a callable.

@technige
Copy link
Author

technige commented Jan 2, 2025

@jonathanslenders I had code which, while within a keypress handler, attempted to disable and then re-enable a Buffer by using buffer.read_only = False followed later by buffer.read_only = True. The full stack trace was as follows:

Unhandled exception in event loop:
  File "/usr/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File ".../site-packages/prompt_toolkit/input/vt100.py", line 162, in callback_wrapper
    callback()
  File ".../site-packages/prompt_toolkit/application/application.py", line 714, in read_from_input_in_context
    context.copy().run(read_from_input)
  File ".../site-packages/prompt_toolkit/application/application.py", line 694, in read_from_input
    self.key_processor.process_keys()
  File ".../site-packages/prompt_toolkit/key_binding/key_processor.py", line 273, in process_keys
    self._process_coroutine.send(key_press)
  File ".../site-packages/prompt_toolkit/key_binding/key_processor.py", line 171, in _process
    matches = self._get_matches(buffer)
              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/prompt_toolkit/key_binding/key_processor.py", line 129, in _get_matches
    return [b for b in self._bindings.get_bindings_for_keys(keys) if b.filter()]
                                                                     ^^^^^^^^^^
  File ".../site-packages/prompt_toolkit/filters/base.py", line 134, in __call__
    return all(f() for f in self.filters)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/prompt_toolkit/filters/base.py", line 134, in <genexpr>
    return all(f() for f in self.filters)
               ^^^
  File ".../site-packages/prompt_toolkit/filters/base.py", line 177, in __call__
    return any(f() for f in self.filters)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/prompt_toolkit/filters/base.py", line 177, in <genexpr>
    return any(f() for f in self.filters)
               ^^^
  File ".../site-packages/prompt_toolkit/filters/base.py", line 254, in __call__
    return self.func()
           ^^^^^^^^^^^
  File ".../site-packages/prompt_toolkit/filters/app.py", line 374, in emacs_insert_mode
    or app.current_buffer.read_only()
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Exception 'bool' object is not callable

But based on your explanation, I see that this is actually user error, with me incorrectly assuming that I could use this property in this way. Apologies for the noise, please feel free to close the PR.

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

Successfully merging this pull request may close these issues.

2 participants