mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
gh-133701: Fix incorrect __annotations__
on TypedDict defined under PEP 563 (#133772)
This commit is contained in:
parent
5d118d0a92
commit
9836503b48
4 changed files with 41 additions and 4 deletions
|
@ -3048,14 +3048,16 @@ class _TypedDictMeta(type):
|
|||
else:
|
||||
generic_base = ()
|
||||
|
||||
ns_annotations = ns.pop('__annotations__', None)
|
||||
|
||||
tp_dict = type.__new__(_TypedDictMeta, name, (*generic_base, dict), ns)
|
||||
|
||||
if not hasattr(tp_dict, '__orig_bases__'):
|
||||
tp_dict.__orig_bases__ = bases
|
||||
|
||||
if "__annotations__" in ns:
|
||||
if ns_annotations is not None:
|
||||
own_annotate = None
|
||||
own_annotations = ns["__annotations__"]
|
||||
own_annotations = ns_annotations
|
||||
elif (own_annotate := _lazy_annotationlib.get_annotate_from_class_namespace(ns)) is not None:
|
||||
own_annotations = _lazy_annotationlib.call_annotate_function(
|
||||
own_annotate, _lazy_annotationlib.Format.FORWARDREF, owner=tp_dict
|
||||
|
@ -3126,7 +3128,7 @@ class _TypedDictMeta(type):
|
|||
if base_annotate is None:
|
||||
continue
|
||||
base_annos = _lazy_annotationlib.call_annotate_function(
|
||||
base.__annotate__, format, owner=base)
|
||||
base_annotate, format, owner=base)
|
||||
annos.update(base_annos)
|
||||
if own_annotate is not None:
|
||||
own = _lazy_annotationlib.call_annotate_function(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue