@@ -894,8 +894,6 @@ def _next_in_mro(cls):
894
894
class GenericMeta (TypingMeta , abc .ABCMeta ):
895
895
"""Metaclass for generic types."""
896
896
897
- __extra__ = None
898
-
899
897
def __new__ (cls , name , bases , namespace ,
900
898
tvars = None , args = None , origin = None , extra = None ):
901
899
self = super ().__new__ (cls , name , bases , namespace , _root = True )
@@ -943,10 +941,7 @@ def __new__(cls, name, bases, namespace,
943
941
self .__parameters__ = tvars
944
942
self .__args__ = args
945
943
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
950
945
# Speed hack (https://github.com/python/typing/issues/196).
951
946
self .__next_in_mro__ = _next_in_mro (self )
952
947
return self
@@ -1307,6 +1302,7 @@ def _get_protocol_attrs(self):
1307
1302
attr != '__next_in_mro__' and
1308
1303
attr != '__parameters__' and
1309
1304
attr != '__origin__' and
1305
+ attr != '__extra__' and
1310
1306
attr != '__module__' ):
1311
1307
attrs .add (attr )
1312
1308
@@ -1470,7 +1466,7 @@ class ByteString(Sequence[int], extra=collections_abc.ByteString):
1470
1466
ByteString .register (type (memoryview (b'' )))
1471
1467
1472
1468
1473
- class List (list , MutableSequence [T ]):
1469
+ class List (list , MutableSequence [T ], extra = list ):
1474
1470
1475
1471
def __new__ (cls , * args , ** kwds ):
1476
1472
if _geqv (cls , List ):
@@ -1479,7 +1475,7 @@ def __new__(cls, *args, **kwds):
1479
1475
return list .__new__ (cls , * args , ** kwds )
1480
1476
1481
1477
1482
- class Set (set , MutableSet [T ]):
1478
+ class Set (set , MutableSet [T ], extra = set ):
1483
1479
1484
1480
def __new__ (cls , * args , ** kwds ):
1485
1481
if _geqv (cls , Set ):
@@ -1502,7 +1498,8 @@ def __subclasscheck__(self, cls):
1502
1498
return super ().__subclasscheck__ (cls )
1503
1499
1504
1500
1505
- class FrozenSet (frozenset , AbstractSet [T_co ], metaclass = _FrozenSetMeta ):
1501
+ class FrozenSet (frozenset , AbstractSet [T_co ], metaclass = _FrozenSetMeta ,
1502
+ extra = frozenset ):
1506
1503
__slots__ = ()
1507
1504
1508
1505
def __new__ (cls , * args , ** kwds ):
@@ -1538,15 +1535,16 @@ class ContextManager(Generic[T_co], extra=contextlib.AbstractContextManager):
1538
1535
__all__ .append ('ContextManager' )
1539
1536
1540
1537
1541
- class Dict (dict , MutableMapping [KT , VT ]):
1538
+ class Dict (dict , MutableMapping [KT , VT ], extra = dict ):
1542
1539
1543
1540
def __new__ (cls , * args , ** kwds ):
1544
1541
if _geqv (cls , Dict ):
1545
1542
raise TypeError ("Type Dict cannot be instantiated; "
1546
1543
"use dict() instead" )
1547
1544
return dict .__new__ (cls , * args , ** kwds )
1548
1545
1549
- class DefaultDict (collections .defaultdict , MutableMapping [KT , VT ]):
1546
+ class DefaultDict (collections .defaultdict , MutableMapping [KT , VT ],
1547
+ extra = collections .defaultdict ):
1550
1548
1551
1549
def __new__ (cls , * args , ** kwds ):
1552
1550
if _geqv (cls , DefaultDict ):
0 commit comments