Skip to content

Commit 94f0089

Browse files
Avasamabravalheri
authored andcommitted
Type _declare_state and make it work statically
1 parent 6dc694e commit 94f0089

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

pkg_resources/__init__.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import time
2828
import re
2929
import types
30-
from typing import List, Protocol
30+
from typing import Any, Dict, List, Protocol
3131
import zipfile
3232
import zipimport
3333
import warnings
@@ -94,9 +94,6 @@
9494
resource_listdir = None
9595
resource_filename = None
9696
resource_exists = None
97-
_distribution_finders = None
98-
_namespace_handlers = None
99-
_namespace_packages = None
10097

10198

10299
warnings.warn(
@@ -120,11 +117,10 @@ class PEP440Warning(RuntimeWarning):
120117
parse_version = packaging.version.Version
121118

122119

123-
_state_vars = {}
120+
_state_vars: Dict[str, Any] = {}
124121

125122

126-
def _declare_state(vartype, **kw):
127-
globals().update(kw)
123+
def _declare_state(vartype: str, **kw: object) -> None:
128124
_state_vars.update(dict.fromkeys(kw, vartype))
129125

130126

@@ -2025,7 +2021,8 @@ def __init__(self, importer):
20252021
self._setup_prefix()
20262022

20272023

2028-
_declare_state('dict', _distribution_finders={})
2024+
_distribution_finders = {}
2025+
_declare_state('dict', _distribution_finders=_distribution_finders)
20292026

20302027

20312028
def register_finder(importer_type, distribution_finder):
@@ -2198,8 +2195,10 @@ def resolve_egg_link(path):
21982195

21992196
register_finder(importlib.machinery.FileFinder, find_on_path)
22002197

2201-
_declare_state('dict', _namespace_handlers={})
2202-
_declare_state('dict', _namespace_packages={})
2198+
_namespace_handlers = {}
2199+
_declare_state('dict', _namespace_handlers=_namespace_handlers)
2200+
_namespace_packages = {}
2201+
_declare_state('dict', _namespace_packages=_namespace_packages)
22032202

22042203

22052204
def register_namespace_handler(importer_type, namespace_handler):

0 commit comments

Comments
 (0)