Skip to content

Commit a47a7a5

Browse files
committed
Issue #27083: Respect the PYTHONCASEOK environment variable under
Windows. Originally only b'PYTHONCASEOK' was being checked for in os.environ, but that won't work under Windows where all environment variables are strings (on OS X they are bytes). Thanks to Eryk Sun for the bug report.
1 parent f76457e commit a47a7a5

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

Lib/importlib/_bootstrap_external.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def _make_relax_case():
2929
if sys.platform.startswith(_CASE_INSENSITIVE_PLATFORMS):
3030
def _relax_case():
3131
"""True if filenames must be checked case-insensitively."""
32-
return b'PYTHONCASEOK' in _os.environ
32+
return (b'PYTHONCASEOK' in _os.environ
33+
or 'PYTHONCASEOK' in _os.environ)
3334
else:
3435
def _relax_case():
3536
"""True if filenames must be checked case-insensitively."""

Lib/test/test_importlib/source/test_case_sensitivity.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,17 @@ def sensitivity_test(self):
3939
insensitive_finder = self.finder(insensitive_path)
4040
return self.find(sensitive_finder), self.find(insensitive_finder)
4141

42+
def env_changed(self, *, should_exist):
43+
possibilities = b'PYTHONCASEOK', 'PYTHONCASEOK'
44+
if any(x in self.importlib._bootstrap_external._os.environ
45+
for x in possibilities) == should_exist:
46+
self.skipTest('os.environ changes not reflected in '
47+
'_os.environ')
48+
4249
def test_sensitive(self):
4350
with test_support.EnvironmentVarGuard() as env:
4451
env.unset('PYTHONCASEOK')
45-
if b'PYTHONCASEOK' in self.importlib._bootstrap_external._os.environ:
46-
self.skipTest('os.environ changes not reflected in '
47-
'_os.environ')
52+
self.env_changed(should_exist=False)
4853
sensitive, insensitive = self.sensitivity_test()
4954
self.assertIsNotNone(sensitive)
5055
self.assertIn(self.name, sensitive.get_filename(self.name))
@@ -53,9 +58,7 @@ def test_sensitive(self):
5358
def test_insensitive(self):
5459
with test_support.EnvironmentVarGuard() as env:
5560
env.set('PYTHONCASEOK', '1')
56-
if b'PYTHONCASEOK' not in self.importlib._bootstrap_external._os.environ:
57-
self.skipTest('os.environ changes not reflected in '
58-
'_os.environ')
61+
self.env_changed(should_exist=True)
5962
sensitive, insensitive = self.sensitivity_test()
6063
self.assertIsNotNone(sensitive)
6164
self.assertIn(self.name, sensitive.get_filename(self.name))

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Release date: TBA
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #27083: Respect the PYTHONCASEOK environment variable under Windows.
14+
1315
- Issue #27514: Make having too many statically nested blocks a SyntaxError
1416
instead of SystemError.
1517

0 commit comments

Comments
 (0)