File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change 7
7
import importlib .machinery
8
8
import os
9
9
import os .path
10
- import re
11
10
import sys
12
11
from types import ModuleType
13
12
import warnings
@@ -638,9 +637,7 @@ def get_data(package, resource):
638
637
return loader .get_data (resource_name )
639
638
640
639
641
- _DOTTED_WORDS = r'(?!\d)(\w+)(\.(?!\d)(\w+))*'
642
- _NAME_PATTERN = re .compile (f'^(?P<pkg>{ _DOTTED_WORDS } )(?P<cln>:(?P<obj>{ _DOTTED_WORDS } )?)?$' , re .U )
643
- del _DOTTED_WORDS
640
+ _NAME_PATTERN = None
644
641
645
642
def resolve_name (name ):
646
643
"""
@@ -674,6 +671,15 @@ def resolve_name(name):
674
671
AttributeError - if a failure occurred when traversing the object hierarchy
675
672
within the imported package to get to the desired object)
676
673
"""
674
+ global _NAME_PATTERN
675
+ if _NAME_PATTERN is None :
676
+ # Lazy import to speedup Python startup time
677
+ import re
678
+ dotted_words = r'(?!\d)(\w+)(\.(?!\d)(\w+))*'
679
+ _NAME_PATTERN = re .compile (f'^(?P<pkg>{ dotted_words } )'
680
+ f'(?P<cln>:(?P<obj>{ dotted_words } )?)?$' ,
681
+ re .UNICODE )
682
+
677
683
m = _NAME_PATTERN .match (name )
678
684
if not m :
679
685
raise ValueError (f'invalid format: { name !r} ' )
You can’t perform that action at this time.
0 commit comments