aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Lib/pkgutil.py
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-04-18 12:39:32 +0300
committershadchin <shadchin@yandex-team.ru>2022-04-18 12:39:32 +0300
commitd4be68e361f4258cf0848fc70018dfe37a2acc24 (patch)
tree153e294cd97ac8b5d7a989612704a0c1f58e8ad4 /contrib/tools/python3/src/Lib/pkgutil.py
parent260c02f5ccf242d9d9b8a873afaf6588c00237d6 (diff)
downloadydb-d4be68e361f4258cf0848fc70018dfe37a2acc24.tar.gz
IGNIETFERRO-1816 Update Python 3 from 3.9.12 to 3.10.4
ref:9f96be6d02ee8044fdd6f124b799b270c20ce641
Diffstat (limited to 'contrib/tools/python3/src/Lib/pkgutil.py')
-rw-r--r--contrib/tools/python3/src/Lib/pkgutil.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/contrib/tools/python3/src/Lib/pkgutil.py b/contrib/tools/python3/src/Lib/pkgutil.py
index 9608d0e0ed..8e010c79c1 100644
--- a/contrib/tools/python3/src/Lib/pkgutil.py
+++ b/contrib/tools/python3/src/Lib/pkgutil.py
@@ -7,7 +7,6 @@ import importlib.util
import importlib.machinery
import os
import os.path
-import re
import sys
from types import ModuleType
import warnings
@@ -205,7 +204,8 @@ class ImpImporter:
def __init__(self, path=None):
global imp
- warnings.warn("This emulation is deprecated, use 'importlib' instead",
+ warnings.warn("This emulation is deprecated and slated for removal "
+ "in Python 3.12; use 'importlib' instead",
DeprecationWarning)
_import_imp()
self.path = path
@@ -272,7 +272,8 @@ class ImpLoader:
code = source = None
def __init__(self, fullname, file, filename, etc):
- warnings.warn("This emulation is deprecated, use 'importlib' instead",
+ warnings.warn("This emulation is deprecated and slated for removal in "
+ "Python 3.12; use 'importlib' instead",
DeprecationWarning)
_import_imp()
self.file = file
@@ -412,7 +413,6 @@ def get_importer(path_item):
The cache (or part of it) can be cleared manually if a
rescan of sys.path_hooks is necessary.
"""
- path_item = os.fsdecode(path_item)
try:
importer = sys.path_importer_cache[path_item]
except KeyError:
@@ -639,9 +639,7 @@ def get_data(package, resource):
return loader.get_data(resource_name)
-_DOTTED_WORDS = r'(?!\d)(\w+)(\.(?!\d)(\w+))*'
-_NAME_PATTERN = re.compile(f'^(?P<pkg>{_DOTTED_WORDS})(?P<cln>:(?P<obj>{_DOTTED_WORDS})?)?$', re.U)
-del _DOTTED_WORDS
+_NAME_PATTERN = None
def resolve_name(name):
"""
@@ -675,6 +673,15 @@ def resolve_name(name):
AttributeError - if a failure occurred when traversing the object hierarchy
within the imported package to get to the desired object.
"""
+ global _NAME_PATTERN
+ if _NAME_PATTERN is None:
+ # Lazy import to speedup Python startup time
+ import re
+ dotted_words = r'(?!\d)(\w+)(\.(?!\d)(\w+))*'
+ _NAME_PATTERN = re.compile(f'^(?P<pkg>{dotted_words})'
+ f'(?P<cln>:(?P<obj>{dotted_words})?)?$',
+ re.UNICODE)
+
m = _NAME_PATTERN.match(name)
if not m:
raise ValueError(f'invalid format: {name!r}')