Skip to content

Commit fc72ab6

Browse files
authored
bpo-38691: importlib ignores PYTHONCASEOK if -E is used (GH-18627)
The importlib module now ignores the PYTHONCASEOK environment variable when the -E or -I command line options are being used.
1 parent e53a393 commit fc72ab6

File tree

7 files changed

+2652
-2629
lines changed

7 files changed

+2652
-2629
lines changed

Doc/library/functions.rst

+3
Original file line numberDiff line numberDiff line change
@@ -1835,6 +1835,9 @@ are always available. They are listed here in alphabetical order.
18351835
Negative values for *level* are no longer supported (which also changes
18361836
the default value to 0).
18371837

1838+
.. versionchanged:: 3.9
1839+
When the command line options :option:`-E` or :option:`-I` are being used,
1840+
the environment variable :envvar:`PYTHONCASEOK` is now ignored.
18381841

18391842
.. rubric:: Footnotes
18401843

Doc/whatsnew/3.9.rst

+3
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,9 @@ Changes in the Python API
645645
since the *buffering* parameter has been removed.
646646
(Contributed by Victor Stinner in :issue:`39357`.)
647647

648+
* The :mod:`importlib` module now ignores the :envvar:`PYTHONCASEOK`
649+
environment variable when the :option:`-E` or :option:`-I` command line
650+
options are being used.
648651

649652
CPython bytecode changes
650653
------------------------

Lib/importlib/_bootstrap_external.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def _make_relax_case():
3434
key = b'PYTHONCASEOK'
3535

3636
def _relax_case():
37-
"""True if filenames must be checked case-insensitively."""
38-
return key in _os.environ
37+
"""True if filenames must be checked case-insensitively and ignore environment flags are not set."""
38+
return not sys.flags.ignore_environment and key in _os.environ
3939
else:
4040
def _relax_case():
4141
"""True if filenames must be checked case-insensitively."""

Lib/test/test_importlib/extension/test_case_sensitivity.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from importlib import _bootstrap_external
22
from test import support
33
import unittest
4-
4+
import sys
55
from .. import util
66

77
importlib = util.import_importlib('importlib')
@@ -21,13 +21,15 @@ def find_module(self):
2121
self.machinery.EXTENSION_SUFFIXES))
2222
return finder.find_module(bad_name)
2323

24+
@unittest.skipIf(sys.flags.ignore_environment, 'ignore_environment flag was set')
2425
def test_case_sensitive(self):
2526
with support.EnvironmentVarGuard() as env:
2627
env.unset('PYTHONCASEOK')
2728
self.caseok_env_changed(should_exist=False)
2829
loader = self.find_module()
2930
self.assertIsNone(loader)
3031

32+
@unittest.skipIf(sys.flags.ignore_environment, 'ignore_environment flag was set')
3133
def test_case_insensitivity(self):
3234
with support.EnvironmentVarGuard() as env:
3335
env.set('PYTHONCASEOK', '1')

Lib/test/test_importlib/source/test_case_sensitivity.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Test case-sensitivity (PEP 235)."""
2+
import sys
3+
24
from .. import util
35

46
importlib = util.import_importlib('importlib')
@@ -38,6 +40,7 @@ def sensitivity_test(self):
3840
insensitive_finder = self.finder(insensitive_path)
3941
return self.find(sensitive_finder), self.find(insensitive_finder)
4042

43+
@unittest.skipIf(sys.flags.ignore_environment, 'ignore_environment flag was set')
4144
def test_sensitive(self):
4245
with test_support.EnvironmentVarGuard() as env:
4346
env.unset('PYTHONCASEOK')
@@ -47,6 +50,7 @@ def test_sensitive(self):
4750
self.assertIn(self.name, sensitive.get_filename(self.name))
4851
self.assertIsNone(insensitive)
4952

53+
@unittest.skipIf(sys.flags.ignore_environment, 'ignore_environment flag was set')
5054
def test_insensitive(self):
5155
with test_support.EnvironmentVarGuard() as env:
5256
env.set('PYTHONCASEOK', '1')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The :mod:`importlib` module now ignores the :envvar:`PYTHONCASEOK`
2+
environment variable when the :option:`-E` or :option:`-I` command line
3+
options are being used.

Python/importlib_external.h

+2,634-2,626
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)