-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Replace Union annotations with TypeVar #26453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@WillAyd we are almost done with removing all ignored modules from mypy.ini Once that's done I will take a look where we have used Union and see if we can use TypeVar instead. |
@WillAyd I will look for Union in |
TypeVar is going to be more suitable for parametrization and generic functions. In the case of containers I think the difference between: T = TypeVar('T', str, float)
List[T] and List[Union[str, float]] Would be that the former could only accept Looking at functions: def foo(something: T) -> T:
... Would basically mean that if def foo(Union[str, float]) -> Union[str, float]:
... Would allow all of those combinations, so it could accept 'a' and return 1. We've used Union throughout so far but more often than not I think parametrization of the Type is actually what we want. |
Nice, thanks for explaining, I will replace all unions in |
does #26588 fully close this? |
Yep |
Had a revelation after python/mypy#6847 (comment) and I think we've been using Union too liberally in places where a TypeVar may make more sense (especially in pandas._typing) so would be good to go back and swap those out.
@gwrome @vaibhavhrt
The text was updated successfully, but these errors were encountered: