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
{{ message }}
Repository navigation
Arguments annotated with typevars cannot have defaults #19092
Adding a default value for a function argument that uses a TypeVar in its type results in an error. This can be worked-around using overloads, but it would be better if it just worked out of the box.
fromtypingimportTypeVarclassBase:
passT=TypeVar('T')
# Also fails: T = TypeVar('T', bound=Base)deffoo1(obj: T=Base()) ->list[T]:
return [obj]
deffoo2(ty: type[T] =Base) ->list[T]:
return [ty()]
Expected Behavior
This should type-check with no errors.
Actual Behavior
main.py:9: error: Incompatible default for argument "obj" (default has type "Base", argument has type "T") [assignment]
main.py:12: error: Incompatible default for argument "ty" (default has type "type[Base]", argument has type "type[T]") [assignment]
Activity