aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Lib/importlib/_bootstrap.py
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-02-10 16:44:39 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:39 +0300
commite9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch)
tree64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/python3/src/Lib/importlib/_bootstrap.py
parent2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff)
downloadydb-e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0.tar.gz
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Lib/importlib/_bootstrap.py')
-rw-r--r--contrib/tools/python3/src/Lib/importlib/_bootstrap.py236
1 files changed, 118 insertions, 118 deletions
diff --git a/contrib/tools/python3/src/Lib/importlib/_bootstrap.py b/contrib/tools/python3/src/Lib/importlib/_bootstrap.py
index 4a2553175c..e00b27ece2 100644
--- a/contrib/tools/python3/src/Lib/importlib/_bootstrap.py
+++ b/contrib/tools/python3/src/Lib/importlib/_bootstrap.py
@@ -7,9 +7,9 @@ work. One should use importlib as the public-facing version of this module.
"""
#
-# IMPORTANT: Whenever making changes to this module, be sure to run a top-level
-# `make regen-importlib` followed by `make` in order to get the frozen version
-# of the module updated. Not doing so will result in the Makefile to fail for
+# IMPORTANT: Whenever making changes to this module, be sure to run a top-level
+# `make regen-importlib` followed by `make` in order to get the frozen version
+# of the module updated. Not doing so will result in the Makefile to fail for
# all others who don't have a ./python around to freeze the module
# in the early stages of compilation.
#
@@ -67,7 +67,7 @@ class _ModuleLock:
# Deadlock avoidance for concurrent circular imports.
me = _thread.get_ident()
tid = self.owner
- seen = set()
+ seen = set()
while True:
lock = _blocking_on.get(tid)
if lock is None:
@@ -75,14 +75,14 @@ class _ModuleLock:
tid = lock.owner
if tid == me:
return True
- if tid in seen:
- # bpo 38091: the chain of tid's we encounter here
- # eventually leads to a fixpoint or a cycle, but
- # does not reach 'me'. This means we would not
- # actually deadlock. This can happen if other
- # threads are at the beginning of acquire() below.
- return False
- seen.add(tid)
+ if tid in seen:
+ # bpo 38091: the chain of tid's we encounter here
+ # eventually leads to a fixpoint or a cycle, but
+ # does not reach 'me'. This means we would not
+ # actually deadlock. This can happen if other
+ # threads are at the beginning of acquire() below.
+ return False
+ seen.add(tid)
def acquire(self):
"""
@@ -380,7 +380,7 @@ class ModuleSpec:
self.cached == other.cached and
self.has_location == other.has_location)
except AttributeError:
- return NotImplemented
+ return NotImplemented
@property
def cached(self):
@@ -596,44 +596,44 @@ def _exec(spec, module):
if sys.modules.get(name) is not module:
msg = 'module {!r} not in sys.modules'.format(name)
raise ImportError(msg, name=name)
- try:
- if spec.loader is None:
- if spec.submodule_search_locations is None:
- raise ImportError('missing loader', name=spec.name)
- # Namespace package.
- _init_module_attrs(spec, module, override=True)
- else:
- _init_module_attrs(spec, module, override=True)
- if not hasattr(spec.loader, 'exec_module'):
- # (issue19713) Once BuiltinImporter and ExtensionFileLoader
- # have exec_module() implemented, we can add a deprecation
- # warning here.
- spec.loader.load_module(name)
- else:
- spec.loader.exec_module(module)
- finally:
- # Update the order of insertion into sys.modules for module
- # clean-up at shutdown.
- module = sys.modules.pop(spec.name)
- sys.modules[spec.name] = module
- return module
+ try:
+ if spec.loader is None:
+ if spec.submodule_search_locations is None:
+ raise ImportError('missing loader', name=spec.name)
+ # Namespace package.
+ _init_module_attrs(spec, module, override=True)
+ else:
+ _init_module_attrs(spec, module, override=True)
+ if not hasattr(spec.loader, 'exec_module'):
+ # (issue19713) Once BuiltinImporter and ExtensionFileLoader
+ # have exec_module() implemented, we can add a deprecation
+ # warning here.
+ spec.loader.load_module(name)
+ else:
+ spec.loader.exec_module(module)
+ finally:
+ # Update the order of insertion into sys.modules for module
+ # clean-up at shutdown.
+ module = sys.modules.pop(spec.name)
+ sys.modules[spec.name] = module
+ return module
def _load_backward_compatible(spec):
# (issue19713) Once BuiltinImporter and ExtensionFileLoader
# have exec_module() implemented, we can add a deprecation
# warning here.
- try:
- spec.loader.load_module(spec.name)
- except:
- if spec.name in sys.modules:
- module = sys.modules.pop(spec.name)
- sys.modules[spec.name] = module
- raise
+ try:
+ spec.loader.load_module(spec.name)
+ except:
+ if spec.name in sys.modules:
+ module = sys.modules.pop(spec.name)
+ sys.modules[spec.name] = module
+ raise
# The module must be in sys.modules at this point!
- # Move it to the end of sys.modules.
- module = sys.modules.pop(spec.name)
- sys.modules[spec.name] = module
+ # Move it to the end of sys.modules.
+ module = sys.modules.pop(spec.name)
+ sys.modules[spec.name] = module
if getattr(module, '__loader__', None) is None:
try:
module.__loader__ = spec.loader
@@ -659,43 +659,43 @@ def _load_backward_compatible(spec):
def _load_unlocked(spec):
# A helper for direct use by the import system.
if spec.loader is not None:
- # Not a namespace package.
+ # Not a namespace package.
if not hasattr(spec.loader, 'exec_module'):
return _load_backward_compatible(spec)
module = module_from_spec(spec)
- # This must be done before putting the module in sys.modules
- # (otherwise an optimization shortcut in import.c becomes
- # wrong).
- spec._initializing = True
- try:
- sys.modules[spec.name] = module
- try:
- if spec.loader is None:
- if spec.submodule_search_locations is None:
- raise ImportError('missing loader', name=spec.name)
- # A namespace package so do nothing.
- else:
- spec.loader.exec_module(module)
- except:
- try:
- del sys.modules[spec.name]
- except KeyError:
- pass
- raise
- # Move the module to the end of sys.modules.
- # We don't ensure that the import-related module attributes get
- # set in the sys.modules replacement case. Such modules are on
- # their own.
- module = sys.modules.pop(spec.name)
- sys.modules[spec.name] = module
- _verbose_message('import {!r} # {!r}', spec.name, spec.loader)
- finally:
- spec._initializing = False
-
- return module
-
+ # This must be done before putting the module in sys.modules
+ # (otherwise an optimization shortcut in import.c becomes
+ # wrong).
+ spec._initializing = True
+ try:
+ sys.modules[spec.name] = module
+ try:
+ if spec.loader is None:
+ if spec.submodule_search_locations is None:
+ raise ImportError('missing loader', name=spec.name)
+ # A namespace package so do nothing.
+ else:
+ spec.loader.exec_module(module)
+ except:
+ try:
+ del sys.modules[spec.name]
+ except KeyError:
+ pass
+ raise
+ # Move the module to the end of sys.modules.
+ # We don't ensure that the import-related module attributes get
+ # set in the sys.modules replacement case. Such modules are on
+ # their own.
+ module = sys.modules.pop(spec.name)
+ sys.modules[spec.name] = module
+ _verbose_message('import {!r} # {!r}', spec.name, spec.loader)
+ finally:
+ spec._initializing = False
+
+ return module
+
# A method used during testing of _load_unlocked() and by
# _load_module_shim().
def _load(spec):
@@ -722,8 +722,8 @@ class BuiltinImporter:
"""
- _ORIGIN = "built-in"
-
+ _ORIGIN = "built-in"
+
@staticmethod
def module_repr(module):
"""Return repr for the module.
@@ -731,14 +731,14 @@ class BuiltinImporter:
The method is deprecated. The import machinery does the job itself.
"""
- return f'<module {module.__name__!r} ({BuiltinImporter._ORIGIN})>'
+ return f'<module {module.__name__!r} ({BuiltinImporter._ORIGIN})>'
@classmethod
def find_spec(cls, fullname, path=None, target=None):
if path is not None:
return None
if _imp.is_builtin(fullname):
- return spec_from_loader(fullname, cls, origin=cls._ORIGIN)
+ return spec_from_loader(fullname, cls, origin=cls._ORIGIN)
else:
return None
@@ -797,8 +797,8 @@ class FrozenImporter:
"""
- _ORIGIN = "frozen"
-
+ _ORIGIN = "frozen"
+
@staticmethod
def module_repr(m):
"""Return repr for the module.
@@ -806,12 +806,12 @@ class FrozenImporter:
The method is deprecated. The import machinery does the job itself.
"""
- return '<module {!r} ({})>'.format(m.__name__, FrozenImporter._ORIGIN)
+ return '<module {!r} ({})>'.format(m.__name__, FrozenImporter._ORIGIN)
@classmethod
def find_spec(cls, fullname, path=None, target=None):
if _imp.is_frozen(fullname):
- return spec_from_loader(fullname, cls, origin=cls._ORIGIN)
+ return spec_from_loader(fullname, cls, origin=cls._ORIGIN)
else:
return None
@@ -884,7 +884,7 @@ def _resolve_name(name, package, level):
"""Resolve a relative module name to an absolute one."""
bits = package.rsplit('.', level - 1)
if len(bits) < level:
- raise ImportError('attempted relative import beyond top-level package')
+ raise ImportError('attempted relative import beyond top-level package')
base = bits[0]
return '{}.{}'.format(base, name) if name else base
@@ -987,12 +987,12 @@ def _find_and_load_unlocked(name, import_):
if parent:
# Set the module as an attribute on its parent.
parent_module = sys.modules[parent]
- child = name.rpartition('.')[2]
- try:
- setattr(parent_module, child, module)
- except AttributeError:
- msg = f"Cannot set an attribute on {parent!r} for child module {child!r}"
- _warnings.warn(msg, ImportWarning)
+ child = name.rpartition('.')[2]
+ try:
+ setattr(parent_module, child, module)
+ except AttributeError:
+ msg = f"Cannot set an attribute on {parent!r} for child module {child!r}"
+ _warnings.warn(msg, ImportWarning)
return module
@@ -1040,30 +1040,30 @@ def _handle_fromlist(module, fromlist, import_, *, recursive=False):
"""
# The hell that is fromlist ...
# If a package was imported, try to import stuff from fromlist.
- for x in fromlist:
- if not isinstance(x, str):
- if recursive:
- where = module.__name__ + '.__all__'
- else:
- where = "``from list''"
- raise TypeError(f"Item in {where} must be str, "
- f"not {type(x).__name__}")
- elif x == '*':
- if not recursive and hasattr(module, '__all__'):
- _handle_fromlist(module, module.__all__, import_,
- recursive=True)
- elif not hasattr(module, x):
- from_name = '{}.{}'.format(module.__name__, x)
- try:
- _call_with_frames_removed(import_, from_name)
- except ModuleNotFoundError as exc:
- # Backwards-compatibility dictates we ignore failed
- # imports triggered by fromlist for modules that don't
- # exist.
- if (exc.name == from_name and
- sys.modules.get(from_name, _NEEDS_LOADING) is not None):
- continue
- raise
+ for x in fromlist:
+ if not isinstance(x, str):
+ if recursive:
+ where = module.__name__ + '.__all__'
+ else:
+ where = "``from list''"
+ raise TypeError(f"Item in {where} must be str, "
+ f"not {type(x).__name__}")
+ elif x == '*':
+ if not recursive and hasattr(module, '__all__'):
+ _handle_fromlist(module, module.__all__, import_,
+ recursive=True)
+ elif not hasattr(module, x):
+ from_name = '{}.{}'.format(module.__name__, x)
+ try:
+ _call_with_frames_removed(import_, from_name)
+ except ModuleNotFoundError as exc:
+ # Backwards-compatibility dictates we ignore failed
+ # imports triggered by fromlist for modules that don't
+ # exist.
+ if (exc.name == from_name and
+ sys.modules.get(from_name, _NEEDS_LOADING) is not None):
+ continue
+ raise
return module
@@ -1125,10 +1125,10 @@ def __import__(name, globals=None, locals=None, fromlist=(), level=0):
# Slice end needs to be positive to alleviate need to special-case
# when ``'.' not in name``.
return sys.modules[module.__name__[:len(module.__name__)-cut_off]]
- elif hasattr(module, '__path__'):
- return _handle_fromlist(module, fromlist, _gcd_import)
+ elif hasattr(module, '__path__'):
+ return _handle_fromlist(module, fromlist, _gcd_import)
else:
- return module
+ return module
def _builtin_from_name(name):