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
Notice that the default parameter for value is an identity callable that casts x to Tv. This produces an error:
error: Invalid type "Tv"
If I remove the call to cast, I get a different error which makes sense to me and was the original reason I added cast in the first place:
error: Incompatible default for argument "value" (default has type "Callable[[T], T]", argument has type "Callable[[T], Tv]")
error: Incompatible return value type (got "T", expected "Tv")
Given that this method is mostly TypeVar based, what do you think would be the right behavior? I find the second error acceptable (because T != Tv) but I find Tv not being a type very confusing and therefor a bug.
The text was updated successfully, but these errors were encountered:
Troubles with specifying defaults for generic arguments is a known issue #3737. And the fact that the cast doesn't work there is unfortunate. A typical workaround is to use an overload. In your case it will actually make the signature more correct:
This is a bug report however it could be that I'm doing it wrong™. This is for mypy version 0.670
Consider this method:
Notice that the default parameter for
value
is an identity callable that castsx
toTv
. This produces an error:If I remove the call to
cast
, I get a different error which makes sense to me and was the original reason I addedcast
in the first place:Given that this method is mostly
TypeVar
based, what do you think would be the right behavior? I find the second error acceptable (becauseT
!=Tv
) but I findTv
not being a type very confusing and therefor a bug.The text was updated successfully, but these errors were encountered: