mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Issue #14581: Windows users are allowed to import modules w/o taking
the file suffix's case into account, even when doing a case-sensitive import.
This commit is contained in:
parent
91900eaf96
commit
8ff6baf25b
2 changed files with 935 additions and 901 deletions
|
@ -841,7 +841,23 @@ class _FileFinder:
|
||||||
contents = _os.listdir(path)
|
contents = _os.listdir(path)
|
||||||
# We store two cached versions, to handle runtime changes of the
|
# We store two cached versions, to handle runtime changes of the
|
||||||
# PYTHONCASEOK environment variable.
|
# PYTHONCASEOK environment variable.
|
||||||
|
if not sys.platform.startswith('win'):
|
||||||
self._path_cache = set(contents)
|
self._path_cache = set(contents)
|
||||||
|
else:
|
||||||
|
# Windows users can import modules with case-insensitive file
|
||||||
|
# suffixes (for legacy reasons). Make the suffix lowercase here
|
||||||
|
# so it's done once instead of for every import. This is safe as
|
||||||
|
# the specified suffixes to check against are always specified in a
|
||||||
|
# case-sensitive manner.
|
||||||
|
lower_suffix_contents = set()
|
||||||
|
for item in contents:
|
||||||
|
name, dot, suffix = item.partition('.')
|
||||||
|
if dot:
|
||||||
|
new_name = '{}.{}'.format(name, suffix.lower())
|
||||||
|
else:
|
||||||
|
new_name = name
|
||||||
|
lower_suffix_contents.add(new_name)
|
||||||
|
self._path_cache = lower_suffix_contents
|
||||||
if sys.platform.startswith(CASE_INSENSITIVE_PLATFORMS):
|
if sys.platform.startswith(CASE_INSENSITIVE_PLATFORMS):
|
||||||
self._relaxed_path_cache = set(fn.lower() for fn in contents)
|
self._relaxed_path_cache = set(fn.lower() for fn in contents)
|
||||||
|
|
||||||
|
|
1818
Python/importlib.h
1818
Python/importlib.h
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue