summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2016-11-29 17:46:29 (GMT)
committerGuido van Rossum <guido@python.org>2016-11-29 17:46:29 (GMT)
commit356ae170ef47af5561d0c39be56ef32b76d704a0 (patch)
treefb2988507309c3e4ad096121aba965695c1ca7ce /Lib/typing.py
parentf9c2405ff81fa1d3be9a9f49f0d5cbe811adfa31 (diff)
parentc349374ee6309a9e85d98c2c9c22b9ce0e48bdfc (diff)
downloadcpython-356ae170ef47af5561d0c39be56ef32b76d704a0.zip
cpython-356ae170ef47af5561d0c39be56ef32b76d704a0.tar.gz
cpython-356ae170ef47af5561d0c39be56ef32b76d704a0.tar.bz2
Issue #28790: Fix error when using Generic and __slots__ (Ivan L) (3.6->3.7)
Diffstat (limited to 'Lib/typing.py')
-rw-r--r--Lib/typing.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index 1a943ac..34845b7 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -870,6 +870,17 @@ def _make_subclasshook(cls):
return __extrahook__
+def _no_slots_copy(dct):
+ """Internal helper: copy class __dict__ and clean slots class variables.
+ (They will be re-created if necessary by normal class machinery.)
+ """
+ dict_copy = dict(dct)
+ if '__slots__' in dict_copy:
+ for slot in dict_copy['__slots__']:
+ dict_copy.pop(slot, None)
+ return dict_copy
+
+
class GenericMeta(TypingMeta, abc.ABCMeta):
"""Metaclass for generic types."""
@@ -967,7 +978,7 @@ class GenericMeta(TypingMeta, abc.ABCMeta):
return self
return self.__class__(self.__name__,
self.__bases__,
- dict(self.__dict__),
+ _no_slots_copy(self.__dict__),
tvars=_type_vars(ev_args) if ev_args else None,
args=ev_args,
origin=ev_origin,
@@ -1043,7 +1054,7 @@ class GenericMeta(TypingMeta, abc.ABCMeta):
args = params
return self.__class__(self.__name__,
self.__bases__,
- dict(self.__dict__),
+ _no_slots_copy(self.__dict__),
tvars=tvars,
args=args,
origin=self,
@@ -1059,7 +1070,8 @@ class GenericMeta(TypingMeta, abc.ABCMeta):
return issubclass(instance.__class__, self)
def __copy__(self):
- return self.__class__(self.__name__, self.__bases__, dict(self.__dict__),
+ return self.__class__(self.__name__, self.__bases__,
+ _no_slots_copy(self.__dict__),
self.__parameters__, self.__args__, self.__origin__,
self.__extra__, self.__orig_bases__)