gh-132426: Add get_annotate_from_class_namespace replacing get_annotate_function (#132490)

As noted on the issue, making get_annotate_function() support both types and
mappings is problematic because one object may be both. So let's add a new one
that works with any mapping.

This leaves get_annotate_function() not very useful, so remove it.
This commit is contained in:
Jelle Zijlstra 2025-05-04 07:26:42 -07:00 committed by GitHub
parent 5a57248b22
commit 7cb86c5def
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 136 additions and 65 deletions

View file

@ -2906,7 +2906,7 @@ class NamedTupleMeta(type):
types = ns["__annotations__"]
field_names = list(types)
annotate = _make_eager_annotate(types)
elif (original_annotate := _lazy_annotationlib.get_annotate_function(ns)) is not None:
elif (original_annotate := _lazy_annotationlib.get_annotate_from_class_namespace(ns)) is not None:
types = _lazy_annotationlib.call_annotate_function(
original_annotate, _lazy_annotationlib.Format.FORWARDREF)
field_names = list(types)
@ -3092,7 +3092,7 @@ class _TypedDictMeta(type):
if "__annotations__" in ns:
own_annotate = None
own_annotations = ns["__annotations__"]
elif (own_annotate := _lazy_annotationlib.get_annotate_function(ns)) is not None:
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
)