diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-06-08 19:00:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-08 19:00:04 (GMT) |
commit | 8698fa83f6c226d35af0367e40dd4387fcccbe40 (patch) | |
tree | f132abf43e01fde9ca91ad87a3c42dda860d109f /Lib/importlib/util.py | |
parent | 1f90b2f57a21b48858a2c60c2c1e59b8ff9f63b7 (diff) | |
download | cpython-8698fa83f6c226d35af0367e40dd4387fcccbe40.zip cpython-8698fa83f6c226d35af0367e40dd4387fcccbe40.tar.gz cpython-8698fa83f6c226d35af0367e40dd4387fcccbe40.tar.bz2 |
[3.12] gh-104310: Rename the New Function in importlib.util (gh-105255) (gh-105518)
The original name wasn't as clear as it could have been. This change includes the following:
* rename the function
* change the default value for "disable_check" to False
* add clues to the docstring that folks should probably not use the function
---------
(cherry picked from commit 34c63b86d3c33a85acf55a0c5c118304754e145d)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Diffstat (limited to 'Lib/importlib/util.py')
-rw-r--r-- | Lib/importlib/util.py | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/Lib/importlib/util.py b/Lib/importlib/util.py index b1d9271..f4d6e82 100644 --- a/Lib/importlib/util.py +++ b/Lib/importlib/util.py @@ -116,12 +116,24 @@ def find_spec(name, package=None): # is imported by runpy, which means we want to avoid any unnecessary # dependencies. Thus we use a class. -class allowing_all_extensions: - """A context manager that lets users skip the compatibility check. +class _incompatible_extension_module_restrictions: + """A context manager that can temporarily skip the compatibility check. + + NOTE: This function is meant to accommodate an unusual case; one + which is likely to eventually go away. There's is a pretty good + chance this is not what you were looking for. + + WARNING: Using this function to disable the check can lead to + unexpected behavior and even crashes. It should only be used during + extension module development. + + If "disable_check" is True then the compatibility check will not + happen while the context manager is active. Otherwise the check + *will* happen. Normally, extensions that do not support multiple interpreters may not be imported in a subinterpreter. That implies modules - that do not implement multi-phase init. + that do not implement multi-phase init or that explicitly of out. Likewise for modules import in a subinterpeter with its own GIL when the extension does not support a per-interpreter GIL. This @@ -130,10 +142,14 @@ class allowing_all_extensions: In both cases, this context manager may be used to temporarily disable the check for compatible extension modules. + + You can get the same effect as this function by implementing the + basic interface of multi-phase init (PEP 489) and lying about + support for mulitple interpreters (or per-interpreter GIL). """ - def __init__(self, disable_check=True): - self.disable_check = disable_check + def __init__(self, *, disable_check): + self.disable_check = bool(disable_check) def __enter__(self): self.old = _imp._override_multi_interp_extensions_check(self.override) |