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
In the second call to decorator_factory() with no arguments, _T should be bound to int. I understand that inferring _T=int is maybe too much for mypy, but I believe _T should then be bound to Any, or maybe object to be extra strict, but definitely not Never, which is what currently happens.
Using default=Any or default=object would also work, depending on what makes the most sense in your application.
For the record, while pyright doesn't complain, it's just as confused as mypy about how to bind _T, just silently so 😉:
# pyright 1.1.389reveal_type(decorator_factory()) # Type of "decorator_factory()" is "((**_P@decorator_factory) -> Unknown) -> ((**_P@decorator_factory) -> Unknown)"reveal_type(Class.method_two) # Type of "Class.method_two" is "(self: Class) -> Unknown"reveal_type(Class().method_two()) # Type of "Class().method_two()" is "Unknown"
while pyright doesn't complain, it's just as confused as mypy
Pyright is not confused here; it's working correctly. It binds the TypeVar based on the default value Box which is equivalent to Box[Unknown]. (Pyright uses Unknown to refer to an implied Any.)
In the second call to
decorator_factory()
with no arguments,_T
should be bound toint
. I understand that inferring _T=int is maybe too much for mypy, but I believe_T
should then be bound toAny
, or maybeobject
to be extra strict, but definitely notNever
, which is what currently happens.https://mypy-play.net/?mypy=master&python=3.13&gist=4a1aeecb04582945c4fa78f196bace5f
For the record, pyright has no complaints about this code.
The text was updated successfully, but these errors were encountered: