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
However, if I set default argument for t, mypy fails:
fromtypingimportType, TypeVarMyType=TypeVar('MyType', str, int)
# error: Incompatible default for argument "t" (default has type "Type[str]", argument has type "Type[int]")deffunc(t: Type[MyType] =str) ->MyType:
returnt()
fromtypingimportType, TypeVarMyType=TypeVar('MyType', str, int)
# error: Incompatible default for argument "t" (default has type "Type[int]", argument has type "Type[str]")deffunc(t: Type[MyType] =int) ->MyType:
returnt()
fromtypingimportType, TypeVarMyType=TypeVar('MyType')
# error: Incompatible default for argument "t" (default has type "Type[int]", argument has type "Type[MyType]")deffunc(t: Type[MyType] =int) ->MyType:
returnt()
IMO that's a bug. Without TypeVar it works correctly though:
This is a duplicate of #4236. Please make sure to search the issue tracker when reporting bugs (using a couple of words such as "default" and "generic"/"typevar" then scanning through the listed issues works well).
Consider a function which takes type and returns instance of that type. This is handled correctly by mypy:
However, if I set default argument for t, mypy fails:
IMO that's a bug. Without TypeVar it works correctly though:
The text was updated successfully, but these errors were encountered: