Typing and Generics
typing.ForwardRef
Represents a string forward reference to a type in Python 3.13. Primarily internal metadata; use string annotations and get_type_hints for normal resolution. Only evaluate trusted annotations.
Formal Syntax & Structure
python syntaxpython
typing.ForwardRef(arg)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| arg | str | Forward reference expression. |
Return Value
ForwardRef
Typing construct or runtime result as described; static typing rules are not runtime validation.
Working Example
Example Snippetpython
from typing import ForwardRef, get_type_hints
class Item: passdef read(value:'Item')->'Item': return valueref=ForwardRef('Item')print((isinstance(ref,ForwardRef),get_type_hints(read,globals())['value'] is Item))