Skip to content

Commit 985e50a

Browse files
Apply suggestions from code review
Co-authored-by: Brett Cannon <[email protected]>
1 parent 18d99ae commit 985e50a

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

Lib/importlib/_bootstrap.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ def _object_name(obj):
2727
return type(obj).__qualname__
2828

2929
def _normalize(name):
30-
""" Normalize 'name' in NKFC form """
30+
"""Normalize 'name' to NKFC form."""
3131
global _unicodedata_normalize
3232
if _unicodedata_normalize is None:
33-
from unicodedata import _normalize
33+
from unicodedata import normalize as _unicodedata_normalize
3434
return _unicodedata_normalize('NFKC', name)
3535

3636
# Bootstrap-related code ######################################################
@@ -43,7 +43,7 @@ def _normalize(name):
4343
# Import done by _install_external_importers()
4444
_bootstrap_external = None
4545

46-
# Import done as needed by _normalize
46+
# Import done lazily as needed by _normalize as unicodedata is not built-in.
4747
_unicodedata_normalize = None
4848

4949
def _wrap(new, old):

Lib/importlib/_bootstrap_external.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,8 +1591,8 @@ def __init__(self, path, *loader_details):
15911591
else:
15921592
self.path = _path_abspath(path)
15931593
self._path_mtime = -1
1594-
self._path_cache = dict()
1595-
self._relaxed_path_cache = dict()
1594+
self._path_cache = {}
1595+
self._relaxed_path_cache = {}
15961596
self._cache_is_normalized = False
15971597

15981598
def invalidate_caches(self):
@@ -1686,7 +1686,7 @@ def _fill_cache(self):
16861686
# so it's done once instead of for every import. This is safe as
16871687
# the specified suffixes to check against are always specified in a
16881688
# case-sensitive manner.
1689-
lower_suffix_contents = dict()
1689+
lower_suffix_contents = {}
16901690
for item in contents:
16911691
name, dot, suffix = item.partition('.')
16921692
if dot:
@@ -1701,9 +1701,7 @@ def _fill_cache(self):
17011701
self._cache_is_normalized = False
17021702

17031703
def _normalize_cache(self):
1704-
"""
1705-
Normalize all entries in the caches to NFKC.
1706-
"""
1704+
"""Normalize all entries in the caches to NFKC."""
17071705
from unicodedata import normalize
17081706

17091707
self._path_cache = { normalize('NFKC', p): p for p in self._path_cache }

0 commit comments

Comments
 (0)