-
Notifications
You must be signed in to change notification settings - Fork 154
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
[BUG] Nested tuple with union of tuple does not deserialize correctly #502
Comments
Will take a look soon, sorry bit slow on our side here. Tough times. |
No worries, thank you for your work. |
Apparently this is how python converts a compatible collection into tuples (3.11):
So the library in general will get into trouble with nested generics like this one. It can technically be fixed by traversing the type args, but I fear things might go wrong there. Currently we do this:
where
gives |
le me know your thoughts @Edgeworth |
It looks to me like the library currently works for nested tuples, see the OP print(TestInput2.from_json('{"cols": [["a", "b"], ["c", "d"]]}')) gives For my personal use case, I worked around this. But I think it's reasonable to expect
w.r.t. whether to implement this now or in the new version, personally I don't mind. Since I have a workaround, I think it's reasonable to leave it unless there are other people who need this to work. WDYT? |
It is because DCJ relies on outer type only. So when you have coherent types inside (only tuples), it will work fine. But when there is a variation - stuff will look ugly. I'll think if there is an easy way to fix this w/o blowing the rest of the lib |
This works
|
Description
With this code:
The output should contain only tuples. However, with the
tuple[(tuple[str, str] | str), ...]
type, the inner tuple is actually converted as a list. Output:Describe the results you expected
Python version you are using
Python 3.11.5
Environment description
dataclasses-json==0.6.2
The text was updated successfully, but these errors were encountered: