@@ -256,15 +256,15 @@ def _type_repr(obj):
256256 return repr (obj )
257257
258258
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
261261 in order of first appearance (lexicographic order).
262262
263263 For example::
264264
265265 >>> P = ParamSpec('P')
266266 >>> T = TypeVar('T')
267- >>> _collect_parameters ((T, Callable[P, T]))
267+ >>> _collect_type_parameters ((T, Callable[P, T]))
268268 (~T, ~P)
269269 """
270270 # required type parameter cannot appear after parameter with default
@@ -280,7 +280,7 @@ def _collect_parameters(args, *, enforce_default_ordering: bool = True):
280280 # `t` might be a tuple, when `ParamSpec` is substituted with
281281 # `[T, int]`, or `[int, *Ts]`, etc.
282282 for x in t :
283- for collected in _collect_parameters ([x ]):
283+ for collected in _collect_type_parameters ([x ]):
284284 if collected not in parameters :
285285 parameters .append (collected )
286286 elif hasattr (t , '__typing_subst__' ):
@@ -320,7 +320,7 @@ def _check_generic_specialization(cls, arguments):
320320 if actual_len < expected_len :
321321 # If the parameter at index `actual_len` in the parameters list
322322 # 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 ().
324324 # That means that no error needs to be raised here, despite
325325 # the number of arguments being passed not matching the number
326326 # of parameters: all parameters that aren't explicitly
@@ -1255,7 +1255,7 @@ def _generic_init_subclass(cls, *args, **kwargs):
12551255 if error :
12561256 raise TypeError ("Cannot inherit from plain Generic" )
12571257 if '__orig_bases__' in cls .__dict__ :
1258- tvars = _collect_parameters (cls .__orig_bases__ )
1258+ tvars = _collect_type_parameters (cls .__orig_bases__ )
12591259 # Look for Generic[T1, ..., Tn].
12601260 # If found, tvars must be a subset of it.
12611261 # If not found, tvars is it.
@@ -1417,7 +1417,7 @@ def __init__(self, origin, args, *, inst=True, name=None):
14171417 self .__args__ = tuple (... if a is _TypingEllipsis else
14181418 a for a in args )
14191419 enforce_default_ordering = origin in (Generic , Protocol )
1420- self .__parameters__ = _collect_parameters (
1420+ self .__parameters__ = _collect_type_parameters (
14211421 args ,
14221422 enforce_default_ordering = enforce_default_ordering ,
14231423 )
@@ -3770,6 +3770,16 @@ def __getattr__(attr):
37703770 elif attr in {"ContextManager" , "AsyncContextManager" }:
37713771 import contextlib
37723772 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
37733783 else :
37743784 raise AttributeError (f"module { __name__ !r} has no attribute { attr !r} " )
37753785 globals ()[attr ] = obj
0 commit comments