Files
pydantic/docs/examples/forward_ref.py
T
Samuel Colvin 25b5d98030 support postponed annotations and ForwardRef in python 3.7 (#348)
* support postponed annotations in python 3.7

* support for full ForwardRef

* tweak update_forward_refs

* better ForwardRef resolution

* remove debug, fix linting

* fix comments

* docs and history
2019-01-11 21:01:07 +00:00

16 lines
266 B
Python

from typing import ForwardRef
from pydantic import BaseModel
Foo = ForwardRef('Foo')
class Foo(BaseModel):
a: int = 123
b: Foo = None
Foo.update_forward_refs()
print(Foo())
#> Foo a=123 b=None
print(Foo(b={'a': '321'}))
#> Foo a=123 b=<Foo a=321 b=None>