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
I understand callable is not subscriptable, and I would file a bug in BPO if you agree this issue is worth fixing.
Nevertheless, I can't use callable even to typecheck very basic code like this the example below.
To Reproduce
Create a module with this:
def f(g: callable) -> None:
g()
f(f)
f('a')
Type check it:
$ mypy callable_type.py
callable_type.py:3: error: Function "builtins.callable" is not valid as a type
callable_type.py:3: note: Perhaps you need "Callable[...]" or a callback protocol?
callable_type.py:4: error: callable? not callable
Found 2 errors in 1 file (checked 1 source file)
Expected Behavior
From a user perspective, the distinction between callable and abc.Callable (or typing.Callable) is as arbitrary as the distinction between list and typing.List, which PEP 585 finally fixed.
I believe Mypy should accept callable in type hints, and that Python should make callable implement __class_getitem__. If it's not a class, it should become one (this has happened before in the history of Python; it's a non-breaking change if done correctly).
Actual Behavior
Mypy refuses to accept builtins.callable in a type hint.
Your Environment
Mypy version used: 0.818
Mypy command-line flags: none
Mypy configuration options from mypy.ini (and other config files): none
Python version used: 3.9.4
Operating system and version: MacOS 10.14.6.
The text was updated successfully, but these errors were encountered:
If we implemented your proposal, we'd also have to teach --disallow-any-generics to tell people to give type parameters to callable, and then they'd be back to using Callable. So we'd be introducing a new feature and simultaneously tell people to not use it. As such, I don't think it makes sense for mypy to accept callable as a type until callable[...] is accepted at runtime.
Bug Report
Mypy does not recognize the built-in function
callable
as a valid type for type hinting.In the spirit of PEP 585 -- Type Hinting Generics In Standard Collections, it should.
I understand
callable
is not subscriptable, and I would file a bug in BPO if you agree this issue is worth fixing.Nevertheless, I can't use
callable
even to typecheck very basic code like this the example below.To Reproduce
Expected Behavior
From a user perspective, the distinction between
callable
andabc.Callable
(ortyping.Callable
) is as arbitrary as the distinction betweenlist
andtyping.List
, which PEP 585 finally fixed.I believe Mypy should accept
callable
in type hints, and that Python should makecallable
implement__class_getitem__
. If it's not a class, it should become one (this has happened before in the history of Python; it's a non-breaking change if done correctly).Actual Behavior
Mypy refuses to accept
builtins.callable
in a type hint.Your Environment
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: