cpython: 294525aac5eb (original) (raw)

--- a/Lib/typing.py +++ b/Lib/typing.py @@ -100,16 +100,16 @@ def _trim_name(nm): class TypingMeta(type):

This overrides new() to require an extra keyword parameter '_root', which serves as a guard against naive subclassing of the typing classes. Any legitimate class defined using a metaclass

-

+

@@ -142,7 +142,7 @@ class TypingMeta(type): class _TypingBase(metaclass=TypingMeta, _root=True):

slots = () @@ -179,10 +179,10 @@ class _TypingBase(metaclass=TypingMeta, class _FinalTypingBase(_TypingBase, _root=True):

Prevents instantiation unless _root=True is given in class call.

slots = ('forward_arg', 'forward_code', 'forward_evaluated', 'forward_value') @@ -206,11 +206,11 @@ class _ForwardRef(_TypingBase, _root=Tru def init(self, arg): super().init(arg) if not isinstance(arg, str):

@@ -336,7 +336,7 @@ def _eval_type(t, globalns, localns): def _type_check(arg, msg):

As a special case, accept None and return type(None) instead. Also, _TypeAlias instances (e.g. Match, Pattern) are acceptable. @@ -363,7 +363,7 @@ def _type_check(arg, msg): def _type_repr(obj):

If obj is a type, we return a shorter version than the default type.repr, based on the module and qualified name, which is @@ -418,7 +418,7 @@ class TypeVar(_TypingBase, _root=True): as for generic function definitions. See class Generic for more information on generic types. Generic functions work as follows:

@@ -431,10 +431,7 @@ class TypeVar(_TypingBase, _root=True): that if the arguments are instances of some subclass of str, the return type is still plain str.

Type variables defined with covariant=True or contravariant=True can be used do declare covariant or contravariant generic types. @@ -509,7 +506,7 @@ AnyStr = TypeVar('AnyStr', bytes, str) def _replace_arg(arg, tvars, args):

+

@@ -796,10 +799,10 @@ def _gorg(a): def _geqv(a, b):

The intention is to consider generic class X and any of its

However, X is not equivalent to a subclass of X. @@ -825,6 +828,7 @@ def _next_in_mro(cls): def _valid_for_check(cls):

@@ -1083,8 +1087,8 @@ def _generic_new(base_cls, cls, *args, * class Generic(metaclass=GenericMeta): """Abstract base class for generic types.

class TupleMeta(GenericMeta):

@_tp_cache def getitem(self, parameters): @@ -1175,7 +1179,7 @@ class Tuple(tuple, extra=tuple, metaclas class CallableMeta(GenericMeta):

def repr(self): if self.origin is None: @@ -1199,7 +1203,7 @@ class CallableMeta(GenericMeta): '[[%s], %s]' % (', '.join(arg_list[:-1]), arg_list[-1])) def getitem(self, parameters):

@@ -1236,7 +1240,7 @@ class Callable(extra=collections_abc.Cal The subscription syntax must always be used with exactly two values: the argument list and the return type. The argument list

There is no syntax to indicate optional or keyword arguments, such function types are rarely used as callback types. @@ -1565,7 +1569,7 @@ class _ProtocolMeta(GenericMeta): class _Protocol(metaclass=_ProtocolMeta): """Internal base class for protocol classes.