@@ -894,8 +894,6 @@ def _next_in_mro(cls):
894894class GenericMeta (TypingMeta , abc .ABCMeta ):
895895 """Metaclass for generic types."""
896896
897- __extra__ = None
898-
899897 def __new__ (cls , name , bases , namespace ,
900898 tvars = None , args = None , origin = None , extra = None ):
901899 self = super ().__new__ (cls , name , bases , namespace , _root = True )
@@ -943,10 +941,7 @@ def __new__(cls, name, bases, namespace,
943941 self .__parameters__ = tvars
944942 self .__args__ = args
945943 self .__origin__ = origin
946- if extra is not None :
947- self .__extra__ = extra
948- # Else __extra__ is inherited, eventually from the
949- # (meta-)class default above.
944+ self .__extra__ = extra
950945 # Speed hack (https://github.com/python/typing/issues/196).
951946 self .__next_in_mro__ = _next_in_mro (self )
952947 return self
@@ -1307,6 +1302,7 @@ def _get_protocol_attrs(self):
13071302 attr != '__next_in_mro__' and
13081303 attr != '__parameters__' and
13091304 attr != '__origin__' and
1305+ attr != '__extra__' and
13101306 attr != '__module__' ):
13111307 attrs .add (attr )
13121308
@@ -1470,7 +1466,7 @@ class ByteString(Sequence[int], extra=collections_abc.ByteString):
14701466ByteString .register (type (memoryview (b'' )))
14711467
14721468
1473- class List (list , MutableSequence [T ]):
1469+ class List (list , MutableSequence [T ], extra = list ):
14741470
14751471 def __new__ (cls , * args , ** kwds ):
14761472 if _geqv (cls , List ):
@@ -1479,7 +1475,7 @@ def __new__(cls, *args, **kwds):
14791475 return list .__new__ (cls , * args , ** kwds )
14801476
14811477
1482- class Set (set , MutableSet [T ]):
1478+ class Set (set , MutableSet [T ], extra = set ):
14831479
14841480 def __new__ (cls , * args , ** kwds ):
14851481 if _geqv (cls , Set ):
@@ -1502,7 +1498,8 @@ def __subclasscheck__(self, cls):
15021498 return super ().__subclasscheck__ (cls )
15031499
15041500
1505- class FrozenSet (frozenset , AbstractSet [T_co ], metaclass = _FrozenSetMeta ):
1501+ class FrozenSet (frozenset , AbstractSet [T_co ], metaclass = _FrozenSetMeta ,
1502+ extra = frozenset ):
15061503 __slots__ = ()
15071504
15081505 def __new__ (cls , * args , ** kwds ):
@@ -1538,15 +1535,16 @@ class ContextManager(Generic[T_co], extra=contextlib.AbstractContextManager):
15381535 __all__ .append ('ContextManager' )
15391536
15401537
1541- class Dict (dict , MutableMapping [KT , VT ]):
1538+ class Dict (dict , MutableMapping [KT , VT ], extra = dict ):
15421539
15431540 def __new__ (cls , * args , ** kwds ):
15441541 if _geqv (cls , Dict ):
15451542 raise TypeError ("Type Dict cannot be instantiated; "
15461543 "use dict() instead" )
15471544 return dict .__new__ (cls , * args , ** kwds )
15481545
1549- class DefaultDict (collections .defaultdict , MutableMapping [KT , VT ]):
1546+ class DefaultDict (collections .defaultdict , MutableMapping [KT , VT ],
1547+ extra = collections .defaultdict ):
15501548
15511549 def __new__ (cls , * args , ** kwds ):
15521550 if _geqv (cls , DefaultDict ):
0 commit comments