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
typing._type_check no longer recognizes several kinds of non-types #92601
Comments
|
I think commit 870b22b changed this behavior. It's intentional. Please see the explanation at #31151 (review). |
Understood. I'm currently using It looks like typing._type_check() was intentionally loosened to not require the maybe-typeform it was checking to be callable so that:
It was understood that loosening this check would cause _type_check() to potentially deviate from how static type checkers recognize a "type", but that giving additional flexibility to the runtime typing implementation was considered to be a good tradeoff. My particular usage of typing._type_check() in trycast desires to only allow garden-variety/universal typeforms (that are generally useable anywhere) but not "only-allowed-in-special-places" typeforms like ParamSpecArgs or InitVar. And it also doesn't want to allow "definitely-not-typeforms" like values of {int, float, bool} (ex: I would argue that questionable constructions like Suggested remediations at the
Suggested remediations at the trycast layer (for @davidfstr to consider if no remediations at the
|
|
CC @GBeauregard as the originator of bpo-46644 |
|
This was an intentional change to reduce the number of bugs where typing.py would reject current or future exotic but valid type annotations. Also, |
Will do. Thanks for taking a look! |
Bug report
The internal function
typing._type_check()is used extensively to check whether a particular value represents a type. Its docstring begins with:In Python 3.11b1 this function no longer errors on various kinds of non-types:
By contrast on Python 3.10:
Your environment
Regression introduced somewhere between Python 3.10 and Python 3.11b1.
The text was updated successfully, but these errors were encountered: