-
Notifications
You must be signed in to change notification settings - Fork 237
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
How to test type compatibility in Python 3.7? #570
Comments
One possible solution is to use But I think maybe it is time consider adding some basic introspection to
@gvanrossum Does it make sense to add such two helper functions that would be essentially public wrappers around internal APIs like |
Yes. I like that we make these things functions in |
Besides the two features you suggest, I guess testing type (either actual type or typing's type variable, like _GenericAlias) compatibility would also be useful. If this would be automatically supported by those two features, it would still be worth mentioning in that particular release's notes. Thanks! |
Canonical check, compatible with 3.6 (__origin__ is Dict) and 3.7 (__origin__ is dict). See python/typing#570.
|
With the new fixes done in Python 3.7. We cannot test type compatibility like:
This is expected as mentioned in PEP560. So I'm not saying I should continue to write code like that.
But since it's still useful to inspect whether type is a list or not (e.g. when you inspect the object's type hints and generate a default value for it), I wonder whether these is already a known way to test such compatibility.
Thanks!
The text was updated successfully, but these errors were encountered: