Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Set the default for disable_check to False.
  • Loading branch information
ericsnowcurrently committed Jun 2, 2023
commit 04b36cf0f3f5a0149d4e8aa0ec79685400147701
6 changes: 5 additions & 1 deletion Lib/importlib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ class allowing_all_extensions:
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 (and by
default) 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 or that explicitly of out.
Expand All @@ -144,7 +148,7 @@ class allowing_all_extensions:
support for mulitple interpreters (or per-interpreter GIL).
"""

def __init__(self, disable_check=True):
def __init__(self, disable_check=False):
self.disable_check = disable_check

def __enter__(self):
Expand Down
15 changes: 12 additions & 3 deletions Lib/test/test_importlib/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ def run_with_shared_gil(self, script):
def test_single_phase_init_module(self):
script = textwrap.dedent('''
import importlib.util
with importlib.util.allowing_all_extensions():
with importlib.util.allowing_all_extensions(True):
import _testsinglephase
''')
with self.subTest('check disabled, shared GIL'):
Expand All @@ -699,6 +699,15 @@ def test_single_phase_init_module(self):
with self.assertRaises(ImportError):
self.run_with_own_gil(script)

script = textwrap.dedent(f'''
import importlib.util
with importlib.util.allowing_all_extensions():
import _testsinglephase
''')
with self.subTest('check enabled (default)'):
with self.assertRaises(ImportError):
self.run_with_shared_gil(script)

@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase module")
def test_incomplete_multi_phase_init_module(self):
prescript = textwrap.dedent(f'''
Expand All @@ -714,7 +723,7 @@ def test_incomplete_multi_phase_init_module(self):

script = prescript + textwrap.dedent('''
import importlib.util
with importlib.util.allowing_all_extensions():
with importlib.util.allowing_all_extensions(True):
module = module_from_spec(spec)
loader.exec_module(module)
''')
Expand All @@ -739,7 +748,7 @@ def test_incomplete_multi_phase_init_module(self):
def test_complete_multi_phase_init_module(self):
script = textwrap.dedent('''
import importlib.util
with importlib.util.allowing_all_extensions():
with importlib.util.allowing_all_extensions(True):
import _testmultiphase
''')
with self.subTest('check disabled, shared GIL'):
Expand Down