gh-119180: Add VALUE_WITH_FAKE_GLOBALS format to annotationlib (#124415)

This commit is contained in:
Jelle Zijlstra 2024-11-26 07:40:13 -08:00 committed by GitHub
parent 2b0e2b2893
commit dcf629213b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 73 additions and 26 deletions

View file

@ -2936,10 +2936,13 @@ def _make_eager_annotate(types):
checked_types = {key: _type_check(val, f"field {key} annotation must be a type")
for key, val in types.items()}
def annotate(format):
if format in (annotationlib.Format.VALUE, annotationlib.Format.FORWARDREF):
return checked_types
else:
return annotationlib.annotations_to_string(types)
match format:
case annotationlib.Format.VALUE | annotationlib.Format.FORWARDREF:
return checked_types
case annotationlib.Format.STRING:
return annotationlib.annotations_to_string(types)
case _:
raise NotImplementedError(format)
return annotate
@ -3229,8 +3232,10 @@ class _TypedDictMeta(type):
}
elif format == annotationlib.Format.STRING:
own = annotationlib.annotations_to_string(own_annotations)
else:
elif format in (annotationlib.Format.FORWARDREF, annotationlib.Format.VALUE):
own = own_checked_annotations
else:
raise NotImplementedError(format)
annos.update(own)
return annos