27
27
import time
28
28
import re
29
29
import types
30
- from typing import List , Protocol
30
+ from typing import Any , Callable , Dict , Iterable , List , Protocol , Optional
31
31
import zipfile
32
32
import zipimport
33
33
import warnings
94
94
resource_listdir = None
95
95
resource_filename = None
96
96
resource_exists = None
97
- _distribution_finders = None
98
- _namespace_handlers = None
99
- _namespace_packages = None
100
97
101
98
102
99
warnings .warn (
@@ -120,11 +117,10 @@ class PEP440Warning(RuntimeWarning):
120
117
parse_version = packaging .version .Version
121
118
122
119
123
- _state_vars = {}
120
+ _state_vars : Dict [ str , Any ] = {}
124
121
125
122
126
- def _declare_state (vartype , ** kw ):
127
- globals ().update (kw )
123
+ def _declare_state (vartype : str , ** kw : object ) -> None :
128
124
_state_vars .update (dict .fromkeys (kw , vartype ))
129
125
130
126
@@ -2025,7 +2021,10 @@ def __init__(self, importer):
2025
2021
self ._setup_prefix ()
2026
2022
2027
2023
2028
- _declare_state ('dict' , _distribution_finders = {})
2024
+ _distribution_finders : Dict [
2025
+ type , Callable [[object , str , bool ], Iterable ["Distribution" ]]
2026
+ ] = {}
2027
+ _declare_state ('dict' , _distribution_finders = _distribution_finders )
2029
2028
2030
2029
2031
2030
def register_finder (importer_type , distribution_finder ):
@@ -2198,8 +2197,12 @@ def resolve_egg_link(path):
2198
2197
2199
2198
register_finder (importlib .machinery .FileFinder , find_on_path )
2200
2199
2201
- _declare_state ('dict' , _namespace_handlers = {})
2202
- _declare_state ('dict' , _namespace_packages = {})
2200
+ _namespace_handlers : Dict [
2201
+ type , Callable [[object , str , str , types .ModuleType ], Optional [str ]]
2202
+ ] = {}
2203
+ _declare_state ('dict' , _namespace_handlers = _namespace_handlers )
2204
+ _namespace_packages : Dict [Optional [str ], List [str ]] = {}
2205
+ _declare_state ('dict' , _namespace_packages = _namespace_packages )
2203
2206
2204
2207
2205
2208
def register_namespace_handler (importer_type , namespace_handler ):
0 commit comments