Similar to #397, I'm using Python 3.7, importing annotations, and have a dataclass with a field that stores an optional instance of the same class.
This works fine under dataclasses.dataclass
but fails under pydantic.dataclasses.dataclass
:
For bugs/questions:
3.7.3 (default, Apr 20 2019, 07:46:47)
: ?0.31
: ?from __future__ import annotations from typing import Optional from pydantic.dataclasses import dataclass @dataclass class Resource: parent: Optional[Resource] = None print(Resource())
...yields:
pydantic.errors.ConfigError: field "parent" not yet prepared so type is still a ForwardRef, you might need to call MetaModel.update_forward_refs().
I can solve it by adding above the class Resource=ForwardRef('Resource')
but ForwardRef
is private (not in typing.__all__
) so I get a warning.
I'll continue by suppressing the warning. Just curious if I'm approaching this wrong.
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