-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
gh-136047: Allow typing._allow_reckless_class_checks to check _py_abc
#136115
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
…py_abc` When `abc.py` fails to import `_abc` and instead imports `_py_abc.ABCMeta`, `_py_abc.ABCMeta.__module__` is set to `abc` to allow `typing._allow_reckless_class_checks` to work with it. Unfortunately, when `typing._caller` falls back to using `sys._getframe`, its `globals()` contains the real module name instead of the module name of the frame's function. This patch allows checking for `_py_abc` in that scenario.
Lib/typing.py
Outdated
@@ -1843,11 +1843,15 @@ def _no_init_or_replace_init(self, *args, **kwargs): | |||
cls.__init__(self, *args, **kwargs) | |||
|
|||
|
|||
_RECKLESS_CLASS_CHECK_ALLOWED = {'abc', 'functools', None} | |||
_SYS_HAS_GETFRAMEMODULENAME = hasattr(sys, '_getframemodulename') | |||
if not _SYS_HAS_GETFRAMEMODULENAME: |
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 wonder if we should just unconditionally allow _py_abc
for simplicity.
We should also add a comment explaining when _py_abc
is relevant.
Last, I think it might be possible to write a unit test for this; the test suite has a way to "block" import of a module that could be used to force the Python implementation of abc
.
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 wonder if we should just unconditionally allow
_py_abc
for simplicity.We should also add a comment explaining when
_py_abc
is relevant.
That sounds better.
Last, I think it might be possible to write a unit test for this; the test suite has a way to "block" import of a module that could be used to force the Python implementation of
abc
.
I have no idea how to write a test about this. Because abc
is being used from deep inside of python bootstrapping, I wasn't able to do it on runtime. To test, I removed Modules/_abc.*
files from the source.
…check `_py_abc`" This reverts commit 4735de5.
When
abc.py
fails to import_abc
and instead imports_py_abc.ABCMeta
,_py_abc.ABCMeta.__module__
is set toabc
to allowtyping._allow_reckless_class_checks
to work with it.Unfortunately, when
typing._caller
falls back to usingsys._getframe
, itsglobals()
contains the real module name instead of the module name of the frame's function.This patch allows checking for
_py_abc
in that scenario.