-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-45283: Run _type_check
on get_type_hints()
#28563
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
Conversation
CC @ambv, because you was the reviewer together with @Fidget-Spinner the last time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of making get_type_hints()
stricter for runtime objects, which is already the case for forward references (e.g. either string annotations or from __future__ import annotations
). It's a breaking change though so it can only go in for Python 3.11.
Measuring performance impact here would be important as well.
Misc/NEWS.d/next/Library/2021-09-25-13-28-44.bpo-45283.ooE1jy.rst
Outdated
Show resolved
Hide resolved
_type_check
on get_type_hints()
_type_check
on get_type_hints()
Thanks a lot, @ambv! I've implemented requested changes. Sorry for the long wait, I am changing cities, so I cannot work full time on Python right now 🙂 |
How can I do that? 🤔 |
You probably have to write a small throwaway microbenchmark. Something that declares a whole bunch of annotations that happen to call I'm more concerned about annotations than about get_type_hints() here. |
Marking as "do not merge" given the concerns from @Fidget-Spinner on the bug (which I agree with). We should do less runtime type checking in typing.py, not more. |
Yes, I now understand that the long-time goal is to make less runtime checks, not more 🙂 |
This PR contains quite a lot of changes, but they are all related.
ClassVar
is now forbidden on module level duringget_type_hints()
_type_check()
for that__annotations__['123'] = 1
, so I changed them ->__annotations__['123'] = int
Final
andClassVar
are not tested together withget_type_hints()
and functionsget_type_hints
failure onFinal
#28279, because I accidentally created them in the wrong classI am pretty sure that this change can cause multiple problems for people with wrong annotations, because
get_type_hints()
was much more forgiving before this change. But, as a heavy typing user, I believe that this is a good thing, because correctness is very important in this area.https://bugs.python.org/issue45283