summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/typing.py')
-rw-r--r--Lib/typing.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index 84f0fd1..bdc14e3 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -1796,7 +1796,9 @@ class Generic:
if '__orig_bases__' in cls.__dict__:
error = Generic in cls.__orig_bases__
else:
- error = Generic in cls.__bases__ and cls.__name__ != 'Protocol'
+ error = (Generic in cls.__bases__ and
+ cls.__name__ != 'Protocol' and
+ type(cls) != _TypedDictMeta)
if error:
raise TypeError("Cannot inherit from plain Generic")
if '__orig_bases__' in cls.__dict__:
@@ -2868,14 +2870,19 @@ class _TypedDictMeta(type):
Subclasses and instances of TypedDict return actual dictionaries.
"""
for base in bases:
- if type(base) is not _TypedDictMeta:
+ if type(base) is not _TypedDictMeta and base is not Generic:
raise TypeError('cannot inherit from both a TypedDict type '
'and a non-TypedDict base class')
- tp_dict = type.__new__(_TypedDictMeta, name, (dict,), ns)
+
+ if any(issubclass(b, Generic) for b in bases):
+ generic_base = (Generic,)
+ else:
+ generic_base = ()
+
+ tp_dict = type.__new__(_TypedDictMeta, name, (*generic_base, dict), ns)
annotations = {}
own_annotations = ns.get('__annotations__', {})
- own_annotation_keys = set(own_annotations.keys())
msg = "TypedDict('Name', {f0: t0, f1: t1, ...}); each t must be a type"
own_annotations = {
n: _type_check(tp, msg, module=tp_dict.__module__)