Feature request: ForwardRef support for dataclasses
See original GitHub issueBug
With python 3.7+ from __future__ import annotations
the example is broken and raises an exception.
- OS: OS X 10.13.6 (17G4015)
- Python version: 3.7.1
- Pydantic version: 0.19
# 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()
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Feature request: ForwardRef support for dataclasses #397
With python 3.7+ from __future__ import annotations the example is broken and raises an exception. OS: OS X 10.13.6 (17G4015); Python version: ...
Read more >Issue 41370: PEP 585 and ForwardRef - Python tracker
I asked for a brief example that explains your issue to me. Instead you sent me links to production code and patches to...
Read more >pydantic — pydantic v0.28 documentation
Both postponed annotations via the future import and ForwardRef require python 3.7+. Support for those features starts from pydantic v0.18. Postponed ...
Read more >Changelog - pydantic
Refactor the whole pydantic dataclass decorator to really act like its standard ... Fix implicitly importing ForwardRef and Callable from pydantic.typing ...
Read more >2.0 Changelog — SQLAlchemy 2.0 Documentation
Added support custom user-defined types which extend the Python enum. ... Fixed bug in Declarative Dataclass Mapping feature where using ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
should be fixed by #399, let me know if this fixes the issue for you.
Ah, got it. Thank you for clarification and the fast implementation of the new feature!