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