With python 3.7+ from __future__ import annotations
the example is broken and raises an exception.
# only the following line was changed compared to the example # in the docs https://pydantic-docs.helpmanual.io/#nested-dataclasses from __future__ import annotations from pydantic import UrlStr from pydantic.dataclasses import dataclass @dataclass class NavbarButton: href: UrlStr @dataclass class Navbar: button: NavbarButton navbar = Navbar(button=('https://example.com',)) print(navbar)
python foo.py Traceback (most recent call last): File "foo.py", line 13, in <module> navbar = Navbar(button=('https://example.com',)) File "<string>", line 3, in __init__ File "/tmp/env/lib/python3.7/site-packages/pydantic/dataclasses.py", line 25, in _pydantic_post_init d = validate_model(self.__pydantic_model__, self.__dict__) File "/tmp/env/lib/python3.7/site-packages/pydantic/main.py", line 508, in validate_model f"field {field.name} not yet prepared and type is still a ForwardRef, " pydantic.errors.ConfigError: field button not yet prepared and type is still a ForwardRef, you'll need to call MetaModel.update_forward_refs()
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4