-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Warn about unconstrained typevars #3254
Comments
The example is actually okay -- the type of an argument at a call site will be used to infer a value for the type variable. It's not recommended since |
I guess that depends on what you consider OK; the example doesn't compromise type safety or create false positive errors, but it's using a harder-to-understand part of the type system (type variables) when a simpler solution (unions) is available and should have the same results. That line of argument applies even more strongly if you use a typevar without bounds, like this: T = TypeVar('T')
def f(x: T) -> None: ... |
This is essentially the same as #2885 except that it talks about argument rather than return types, so closing. |
I think code like this should produce an error:
because there's nothing to constrain the type variable. There is a good amount of code like this in typeshed.
I'm not sure how easy this would be to implement. Maybe it should be behind a flag at first; I imagine this proposed change may lead to a lot of new errors, but it's a good way to educate people about what typevars are for.
The text was updated successfully, but these errors were encountered: