27
27
import time
28
28
import re
29
29
import types
30
- from typing import List , Protocol
30
+ from typing import TYPE_CHECKING , List , Protocol
31
31
import zipfile
32
32
import zipimport
33
33
import warnings
82
82
83
83
# declare some globals that will be defined later to
84
84
# satisfy the linters.
85
- require = None
86
- working_set = None
87
- add_activation_listener = None
88
- cleanup_resources = None
89
- resource_stream = None
90
- set_extraction_path = None
91
- resource_isdir = None
92
- resource_string = None
93
- iter_entry_points = None
94
- resource_listdir = None
95
- resource_filename = None
96
- resource_exists = None
97
85
_distribution_finders = None
98
86
_namespace_handlers = None
99
87
_namespace_packages = None
@@ -3261,6 +3249,15 @@ def _mkstemp(*args, **kw):
3261
3249
warnings .filterwarnings ("ignore" , category = PEP440Warning , append = True )
3262
3250
3263
3251
3252
+ class PkgResourcesDeprecationWarning (Warning ):
3253
+ """
3254
+ Base class for warning about deprecations in ``pkg_resources``
3255
+
3256
+ This class is not derived from ``DeprecationWarning``, and as such is
3257
+ visible by default.
3258
+ """
3259
+
3260
+
3264
3261
# from jaraco.functools 1.3
3265
3262
def _call_aside (f , * args , ** kwargs ):
3266
3263
f (* args , ** kwargs )
@@ -3279,15 +3276,6 @@ def _initialize(g=globals()):
3279
3276
)
3280
3277
3281
3278
3282
- class PkgResourcesDeprecationWarning (Warning ):
3283
- """
3284
- Base class for warning about deprecations in ``pkg_resources``
3285
-
3286
- This class is not derived from ``DeprecationWarning``, and as such is
3287
- visible by default.
3288
- """
3289
-
3290
-
3291
3279
@_call_aside
3292
3280
def _initialize_master_working_set ():
3293
3281
"""
@@ -3323,3 +3311,23 @@ def _initialize_master_working_set():
3323
3311
# match order
3324
3312
list (map (working_set .add_entry , sys .path ))
3325
3313
globals ().update (locals ())
3314
+
3315
+
3316
+ if TYPE_CHECKING :
3317
+ # All of these are set by the @_call_aside methods above
3318
+ __resource_manager = ResourceManager () # Won't exist at runtime
3319
+ resource_exists = __resource_manager .resource_exists
3320
+ resource_isdir = __resource_manager .resource_isdir
3321
+ resource_filename = __resource_manager .resource_filename
3322
+ resource_stream = __resource_manager .resource_stream
3323
+ resource_string = __resource_manager .resource_string
3324
+ resource_listdir = __resource_manager .resource_listdir
3325
+ set_extraction_path = __resource_manager .set_extraction_path
3326
+ cleanup_resources = __resource_manager .cleanup_resources
3327
+
3328
+ working_set = WorkingSet ()
3329
+ require = working_set .require
3330
+ iter_entry_points = working_set .iter_entry_points
3331
+ add_activation_listener = working_set .subscribe
3332
+ run_script = working_set .run_script
3333
+ run_main = run_script
0 commit comments