@@ -256,15 +256,15 @@ def _type_repr(obj):
256
256
return repr (obj )
257
257
258
258
259
- def _collect_parameters (args , * , enforce_default_ordering : bool = True ):
260
- """Collect all type variables and parameter specifications in args
259
+ def _collect_type_parameters (args , * , enforce_default_ordering : bool = True ):
260
+ """Collect all type parameters in args
261
261
in order of first appearance (lexicographic order).
262
262
263
263
For example::
264
264
265
265
>>> P = ParamSpec('P')
266
266
>>> T = TypeVar('T')
267
- >>> _collect_parameters ((T, Callable[P, T]))
267
+ >>> _collect_type_parameters ((T, Callable[P, T]))
268
268
(~T, ~P)
269
269
"""
270
270
# required type parameter cannot appear after parameter with default
@@ -280,7 +280,7 @@ def _collect_parameters(args, *, enforce_default_ordering: bool = True):
280
280
# `t` might be a tuple, when `ParamSpec` is substituted with
281
281
# `[T, int]`, or `[int, *Ts]`, etc.
282
282
for x in t :
283
- for collected in _collect_parameters ([x ]):
283
+ for collected in _collect_type_parameters ([x ]):
284
284
if collected not in parameters :
285
285
parameters .append (collected )
286
286
elif hasattr (t , '__typing_subst__' ):
@@ -320,7 +320,7 @@ def _check_generic_specialization(cls, arguments):
320
320
if actual_len < expected_len :
321
321
# If the parameter at index `actual_len` in the parameters list
322
322
# has a default, then all parameters after it must also have
323
- # one, because we validated as much in _collect_parameters ().
323
+ # one, because we validated as much in _collect_type_parameters ().
324
324
# That means that no error needs to be raised here, despite
325
325
# the number of arguments being passed not matching the number
326
326
# of parameters: all parameters that aren't explicitly
@@ -1255,7 +1255,7 @@ def _generic_init_subclass(cls, *args, **kwargs):
1255
1255
if error :
1256
1256
raise TypeError ("Cannot inherit from plain Generic" )
1257
1257
if '__orig_bases__' in cls .__dict__ :
1258
- tvars = _collect_parameters (cls .__orig_bases__ )
1258
+ tvars = _collect_type_parameters (cls .__orig_bases__ )
1259
1259
# Look for Generic[T1, ..., Tn].
1260
1260
# If found, tvars must be a subset of it.
1261
1261
# If not found, tvars is it.
@@ -1417,7 +1417,7 @@ def __init__(self, origin, args, *, inst=True, name=None):
1417
1417
self .__args__ = tuple (... if a is _TypingEllipsis else
1418
1418
a for a in args )
1419
1419
enforce_default_ordering = origin in (Generic , Protocol )
1420
- self .__parameters__ = _collect_parameters (
1420
+ self .__parameters__ = _collect_type_parameters (
1421
1421
args ,
1422
1422
enforce_default_ordering = enforce_default_ordering ,
1423
1423
)
@@ -3770,6 +3770,16 @@ def __getattr__(attr):
3770
3770
elif attr in {"ContextManager" , "AsyncContextManager" }:
3771
3771
import contextlib
3772
3772
obj = _alias (getattr (contextlib , f"Abstract{ attr } " ), 2 , name = attr , defaults = (bool | None ,))
3773
+ elif attr == "_collect_parameters" :
3774
+ import warnings
3775
+
3776
+ depr_message = (
3777
+ "The private _collect_parameters function is deprecated and will be"
3778
+ " removed in a future version of Python. Any use of private functions"
3779
+ " is discouraged and may break in the future."
3780
+ )
3781
+ warnings .warn (depr_message , category = DeprecationWarning , stacklevel = 2 )
3782
+ obj = _collect_type_parameters
3773
3783
else :
3774
3784
raise AttributeError (f"module { __name__ !r} has no attribute { attr !r} " )
3775
3785
globals ()[attr ] = obj
0 commit comments