27
27
import time
28
28
import re
29
29
import types
30
- from typing import Callable , Dict , Iterable , List , Protocol , Optional , TypeVar
30
+ from typing import (
31
+ TYPE_CHECKING ,
32
+ List ,
33
+ Protocol ,
34
+ Callable ,
35
+ Dict ,
36
+ Iterable ,
37
+ Optional ,
38
+ TypeVar ,
39
+ )
31
40
import zipfile
32
41
import zipimport
33
42
import warnings
76
85
from pkg_resources .extern .packaging import version as _packaging_version
77
86
from pkg_resources .extern .platformdirs import user_cache_dir as _user_cache_dir
78
87
79
- # declare some globals that will be defined later to
80
- # satisfy the linters.
81
- require = None
82
- working_set = None
83
- add_activation_listener = None
84
- cleanup_resources = None
85
- resource_stream = None
86
- set_extraction_path = None
87
- resource_isdir = None
88
- resource_string = None
89
- iter_entry_points = None
90
- resource_listdir = None
91
- resource_filename = None
92
- resource_exists = None
93
-
94
88
95
89
warnings .warn (
96
90
"pkg_resources is deprecated as an API. "
@@ -3257,6 +3251,15 @@ def _mkstemp(*args, **kw):
3257
3251
warnings .filterwarnings ("ignore" , category = PEP440Warning , append = True )
3258
3252
3259
3253
3254
+ class PkgResourcesDeprecationWarning (Warning ):
3255
+ """
3256
+ Base class for warning about deprecations in ``pkg_resources``
3257
+
3258
+ This class is not derived from ``DeprecationWarning``, and as such is
3259
+ visible by default.
3260
+ """
3261
+
3262
+
3260
3263
# from jaraco.functools 1.3
3261
3264
def _call_aside (f , * args , ** kwargs ):
3262
3265
f (* args , ** kwargs )
@@ -3275,15 +3278,6 @@ def _initialize(g=globals()):
3275
3278
)
3276
3279
3277
3280
3278
- class PkgResourcesDeprecationWarning (Warning ):
3279
- """
3280
- Base class for warning about deprecations in ``pkg_resources``
3281
-
3282
- This class is not derived from ``DeprecationWarning``, and as such is
3283
- visible by default.
3284
- """
3285
-
3286
-
3287
3281
@_call_aside
3288
3282
def _initialize_master_working_set ():
3289
3283
"""
@@ -3320,6 +3314,26 @@ def _initialize_master_working_set():
3320
3314
globals ().update (locals ())
3321
3315
3322
3316
3317
+ if TYPE_CHECKING :
3318
+ # All of these are set by the @_call_aside methods above
3319
+ __resource_manager = ResourceManager () # Won't exist at runtime
3320
+ resource_exists = __resource_manager .resource_exists
3321
+ resource_isdir = __resource_manager .resource_isdir
3322
+ resource_filename = __resource_manager .resource_filename
3323
+ resource_stream = __resource_manager .resource_stream
3324
+ resource_string = __resource_manager .resource_string
3325
+ resource_listdir = __resource_manager .resource_listdir
3326
+ set_extraction_path = __resource_manager .set_extraction_path
3327
+ cleanup_resources = __resource_manager .cleanup_resources
3328
+
3329
+ working_set = WorkingSet ()
3330
+ require = working_set .require
3331
+ iter_entry_points = working_set .iter_entry_points
3332
+ add_activation_listener = working_set .subscribe
3333
+ run_script = working_set .run_script
3334
+ run_main = run_script
3335
+
3336
+
3323
3337
# ---- Ported from ``setuptools`` to avoid introducing an import inter-dependency ----
3324
3338
LOCALE_ENCODING = "locale" if sys .version_info >= (3 , 10 ) else None
3325
3339
0 commit comments