mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
[3.14] gh-133701: Fix incorrect __annotations__
on TypedDict defined under PEP 563 (GH-133772) (#134003)
gh-133701: Fix incorrect `__annotations__` on TypedDict defined under PEP 563 (GH-133772)
(cherry picked from commit 9836503b48
)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
parent
a962934106
commit
d6cb8fa86e
4 changed files with 41 additions and 4 deletions
|
@ -3087,14 +3087,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
|
||||
|
@ -3165,7 +3167,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