You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The @handle decorator is registering the function as a callback somewhere. The name is irrelevant, because it's never referred to in the scope where it's defined, hence the name _.
Mypy however, doesn't like it:
prompt_toolkit/key_binding/bindings/basic.py:179: error: Name '_' already defined on line 160
prompt_toolkit/key_binding/bindings/basic.py:183: error: Name '_' already defined on line 160
prompt_toolkit/key_binding/bindings/basic.py:187: error: Name '_' already defined on line 160
prompt_toolkit/key_binding/bindings/basic.py:194: error: Name '_' already defined on line 160
prompt_toolkit/key_binding/bindings/basic.py:207: error: Name '_' already defined on line 160
I would hate to give all 214 occurrences of key bindings a name, if it doesn't matter.
$ grep 'def _(' -R prompt_toolkit/ | wc -l
214
Would it be possible to add an exception to mypy, which allows function names to be rebound in the same scope, if they are never called by their name binding?
If so, that would be great, and I think not just for prompt_toolkit and its users.
(Btw, I'm at PyCon right now.)
Thanks a lot!
The text was updated successfully, but these errors were encountered:
@jonathanslenders You may be interested in the discussion in #2904. Unfortunately, there isn't a good method of making an exception to this pattern that I am aware of, so a plugin seems the optimal solution.
I'm adding type annotations to the prompt_toolkit library.
The code for handling the key bindings looks something like this:
The
@handle
decorator is registering the function as a callback somewhere. The name is irrelevant, because it's never referred to in the scope where it's defined, hence the name_
.Mypy however, doesn't like it:
I would hate to give all 214 occurrences of key bindings a name, if it doesn't matter.
Would it be possible to add an exception to mypy, which allows function names to be rebound in the same scope, if they are never called by their name binding?
If so, that would be great, and I think not just for prompt_toolkit and its users.
(Btw, I'm at PyCon right now.)
Thanks a lot!
The text was updated successfully, but these errors were encountered: