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.
This commit is contained in:
idomic 2020-03-09 07:57:53 -04:00 committed by GitHub
parent e53a3932cb
commit fc72ab6913
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 2656 additions and 2633 deletions

View File

@ -1835,6 +1835,9 @@ are always available. They are listed here in alphabetical order.
Negative values for *level* are no longer supported (which also changes
the default value to 0).
.. versionchanged:: 3.9
When the command line options :option:`-E` or :option:`-I` are being used,
the environment variable :envvar:`PYTHONCASEOK` is now ignored.
.. rubric:: Footnotes

View File

@ -645,6 +645,9 @@ Changes in the Python API
since the *buffering* parameter has been removed.
(Contributed by Victor Stinner in :issue:`39357`.)
* The :mod:`importlib` module now ignores the :envvar:`PYTHONCASEOK`
environment variable when the :option:`-E` or :option:`-I` command line
options are being used.
CPython bytecode changes
------------------------

View File

@ -34,8 +34,8 @@ def _make_relax_case():
key = b'PYTHONCASEOK'
def _relax_case():
"""True if filenames must be checked case-insensitively."""
return key in _os.environ
"""True if filenames must be checked case-insensitively and ignore environment flags are not set."""
return not sys.flags.ignore_environment and key in _os.environ
else:
def _relax_case():
"""True if filenames must be checked case-insensitively."""

View File

@ -1,7 +1,7 @@
from importlib import _bootstrap_external
from test import support
import unittest
import sys
from .. import util
importlib = util.import_importlib('importlib')
@ -21,6 +21,7 @@ class ExtensionModuleCaseSensitivityTest(util.CASEOKTestBase):
self.machinery.EXTENSION_SUFFIXES))
return finder.find_module(bad_name)
@unittest.skipIf(sys.flags.ignore_environment, 'ignore_environment flag was set')
def test_case_sensitive(self):
with support.EnvironmentVarGuard() as env:
env.unset('PYTHONCASEOK')
@ -28,6 +29,7 @@ class ExtensionModuleCaseSensitivityTest(util.CASEOKTestBase):
loader = self.find_module()
self.assertIsNone(loader)
@unittest.skipIf(sys.flags.ignore_environment, 'ignore_environment flag was set')
def test_case_insensitivity(self):
with support.EnvironmentVarGuard() as env:
env.set('PYTHONCASEOK', '1')

View File

@ -1,4 +1,6 @@
"""Test case-sensitivity (PEP 235)."""
import sys
from .. import util
importlib = util.import_importlib('importlib')
@ -38,6 +40,7 @@ class CaseSensitivityTest(util.CASEOKTestBase):
insensitive_finder = self.finder(insensitive_path)
return self.find(sensitive_finder), self.find(insensitive_finder)
@unittest.skipIf(sys.flags.ignore_environment, 'ignore_environment flag was set')
def test_sensitive(self):
with test_support.EnvironmentVarGuard() as env:
env.unset('PYTHONCASEOK')
@ -47,6 +50,7 @@ class CaseSensitivityTest(util.CASEOKTestBase):
self.assertIn(self.name, sensitive.get_filename(self.name))
self.assertIsNone(insensitive)
@unittest.skipIf(sys.flags.ignore_environment, 'ignore_environment flag was set')
def test_insensitive(self):
with test_support.EnvironmentVarGuard() as env:
env.set('PYTHONCASEOK', '1')

View File

@ -0,0 +1,3 @@
The :mod:`importlib` module now ignores the :envvar:`PYTHONCASEOK`
environment variable when the :option:`-E` or :option:`-I` command line
options are being used.

File diff suppressed because it is too large Load Diff