Python Glossary Русский

Python 3.14+annotationlibfunction

annotationlib.call_evaluate_function()

low-level helpers

Evaluates the lazy value of a type alias or a TypeVar bound in the requested format: VALUE, FORWARDREF or STRING.

Syntax

annotationlib.call_evaluate_function(evaluate, format, *, owner=None)

The right-hand side of type Alias = ... is lazy too: a typo there is not caught at definition but surfaces as NameError on the first access to Alias.__value__. call_evaluate_function(Alias.evaluate_value, Format.STRING) shows the expression without evaluating anything, and FORWARDREF replaces unknown names with ForwardRef. Unlike call_annotate_function, it returns a single value rather than a dict.

Examples

# Python 3.14+
from annotationlib import call_evaluate_function, Format
type Rows = list[Row]  # Row не объявлен — определение проходит
print(call_evaluate_function(Rows.evaluate_value, Format.STRING))  # → list[Row]
print(call_evaluate_function(Rows.evaluate_value, Format.FORWARDREF))  # → list[ForwardRef('Row')]
try:
    Rows.__value__
except NameError as e:
    print(e)  # → name 'Row' is not defined

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy