-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
self-referencing/forward-references dataclasses are not supported #28
Comments
FYI, the current workaround we are using is to declare the class once first, and then redefine it. This allows mashumaro to have a stub for the class being defined during code generation: @dataclasses.dataclass
class Node(DataClassJSONMixin):
pass
@dataclasses.dataclass
class Node(DataClassJSONMixin):
value: str
next: Optional['Node'] = None This hasn't introduced any problems in our use-cases, other than the minor issue of confusing some code analysis tools. |
Seems like another popular library has the same issue pydantic/pydantic#2678 👀 |
@qubidt Hi. I've fixed forward references in this branch, which you can play around with for now. There are a few things I want to experiment with before I release a new version. |
Fixed in 2.3. |
Mashumaro does not currently support self-referencing classes, the code-generation fails when it attempts to reflect on the field's type (which is a forward reference)
For example, consider the following case:
This gives us the expected:
The equivalent classes using mashumaro:
throws an error during Mashumaro's code generation:
The text was updated successfully, but these errors were encountered: