summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2016-05-18 15:35:00 (GMT)
committerGuido van Rossum <guido@python.org>2016-05-18 15:35:00 (GMT)
commit1cea70f08c0b6aa3fccb246416b367e9afc1932a (patch)
treeb38bb9c6fa03a2bdbdb7a9c7d73e3287e5a63923 /Lib/typing.py
parente5ea1abf91f79b5eaa8ab638c28400285a8fabfd (diff)
downloadcpython-1cea70f08c0b6aa3fccb246416b367e9afc1932a.zip
cpython-1cea70f08c0b6aa3fccb246416b367e9afc1932a.tar.gz
cpython-1cea70f08c0b6aa3fccb246416b367e9afc1932a.tar.bz2
Fix #27014 -- infinite recursion using typing.py.
Diffstat (limited to 'Lib/typing.py')
-rw-r--r--Lib/typing.py20
1 files changed, 9 insertions, 11 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index d275011..841e778 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -894,8 +894,6 @@ def _next_in_mro(cls):
class GenericMeta(TypingMeta, abc.ABCMeta):
"""Metaclass for generic types."""
- __extra__ = None
-
def __new__(cls, name, bases, namespace,
tvars=None, args=None, origin=None, extra=None):
self = super().__new__(cls, name, bases, namespace, _root=True)
@@ -943,10 +941,7 @@ class GenericMeta(TypingMeta, abc.ABCMeta):
self.__parameters__ = tvars
self.__args__ = args
self.__origin__ = origin
- if extra is not None:
- self.__extra__ = extra
- # Else __extra__ is inherited, eventually from the
- # (meta-)class default above.
+ self.__extra__ = extra
# Speed hack (https://github.com/python/typing/issues/196).
self.__next_in_mro__ = _next_in_mro(self)
return self
@@ -1307,6 +1302,7 @@ class _ProtocolMeta(GenericMeta):
attr != '__next_in_mro__' and
attr != '__parameters__' and
attr != '__origin__' and
+ attr != '__extra__' and
attr != '__module__'):
attrs.add(attr)
@@ -1470,7 +1466,7 @@ class ByteString(Sequence[int], extra=collections_abc.ByteString):
ByteString.register(type(memoryview(b'')))
-class List(list, MutableSequence[T]):
+class List(list, MutableSequence[T], extra=list):
def __new__(cls, *args, **kwds):
if _geqv(cls, List):
@@ -1479,7 +1475,7 @@ class List(list, MutableSequence[T]):
return list.__new__(cls, *args, **kwds)
-class Set(set, MutableSet[T]):
+class Set(set, MutableSet[T], extra=set):
def __new__(cls, *args, **kwds):
if _geqv(cls, Set):
@@ -1502,7 +1498,8 @@ class _FrozenSetMeta(GenericMeta):
return super().__subclasscheck__(cls)
-class FrozenSet(frozenset, AbstractSet[T_co], metaclass=_FrozenSetMeta):
+class FrozenSet(frozenset, AbstractSet[T_co], metaclass=_FrozenSetMeta,
+ extra=frozenset):
__slots__ = ()
def __new__(cls, *args, **kwds):
@@ -1538,7 +1535,7 @@ if hasattr(contextlib, 'AbstractContextManager'):
__all__.append('ContextManager')
-class Dict(dict, MutableMapping[KT, VT]):
+class Dict(dict, MutableMapping[KT, VT], extra=dict):
def __new__(cls, *args, **kwds):
if _geqv(cls, Dict):
@@ -1546,7 +1543,8 @@ class Dict(dict, MutableMapping[KT, VT]):
"use dict() instead")
return dict.__new__(cls, *args, **kwds)
-class DefaultDict(collections.defaultdict, MutableMapping[KT, VT]):
+class DefaultDict(collections.defaultdict, MutableMapping[KT, VT],
+ extra=collections.defaultdict):
def __new__(cls, *args, **kwds):
if _geqv(cls, DefaultDict):