@@ -753,6 +753,37 @@ Functions
753753
754754 .. versionadded :: 4.2.0
755755
756+ .. function :: evaluate_forward_ref(forward_ref, *, owner=None, globals=None, locals=None, type_params=None, format=Format.VALUE)
757+
758+ Evaluate an :py:class: `typing.ForwardRef ` as a :py:term: `type hint `.
759+
760+ This is similar to calling :py:meth: `annotationlib.ForwardRef.evaluate `,
761+ but unlike that method, :func: `!evaluate_forward_ref ` also:
762+
763+ * Recursively evaluates forward references nested within the type hint.
764+ However, the amount of recursion is limited in Python 3.8 and 3.10.
765+ * Raises :exc: `TypeError ` when it encounters certain objects that are
766+ not valid type hints.
767+ * Replaces type hints that evaluate to :const: `!None ` with
768+ :class: `types.NoneType `.
769+ * Supports the :attr: `Format.FORWARDREF ` and
770+ :attr: `Format.STRING ` formats.
771+
772+ *forward_ref * must be an instance of :py:class: `typing.ForwardRef `.
773+ *owner *, if given, should be the object that holds the annotations that
774+ the forward reference derived from, such as a module, class object, or function.
775+ It is used to infer the namespaces to use for looking up names.
776+ *globals * and *locals * can also be explicitly given to provide
777+ the global and local namespaces.
778+ *type_params * is a tuple of :py:ref: `type parameters <type-params >` that
779+ are in scope when evaluating the forward reference.
780+ This parameter must be provided (though it may be an empty tuple) if *owner *
781+ is not given and the forward reference does not already have an owner set.
782+ *format * specifies the format of the annotation and is a member of
783+ the :class: `Format ` enum.
784+
785+ .. versionadded :: 4.13.0
786+
756787.. function :: get_annotations(obj, *, globals=None, locals=None, eval_str=False, format=Format.VALUE)
757788
758789 See :py:func: `inspect.get_annotations `. In the standard library since Python 3.10.
0 commit comments