Skip to content
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

Regression with nested classes #226

Open
quimey opened this issue Apr 24, 2023 · 0 comments
Open

Regression with nested classes #226

quimey opened this issue Apr 24, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@quimey
Copy link

quimey commented Apr 24, 2023

Describe the bug

Dacite failes to recognize a nested class structure involving tuples and lists.

To Reproduce

from typing import List, Tuple
from dataclasses import dataclass
from dacite import from_dict, Config


@dataclass
class A:
    i: List[str]
    t: str


@dataclass
class B:
    m: Tuple[str, A]


assert from_dict(
    data_class=B,
    data={"m": ["a", {"i": [], "t": "foo"}]},
    config=Config(cast=[tuple])
) == B(m=('a', A(i=[], t='foo')))

Running the code yields:

  File ".venv/lib/python3.10/site-packages/dacite/core.py", line 69, in from_dict
    raise WrongTypeError(field_path=field.name, field_type=field_type, value=value)
dacite.exceptions.WrongTypeError: wrong value type for field "m" - should be "Tuple" instead of value "('a', {'i': [], 't': 'foo'})" of type "tuple"

Expected behavior
No errors
Environment

  • Python version: 3.10.3
  • dacite version: 1.8.0

Additional context
The code works just fine with dacite 1.6.0

@quimey quimey added the bug Something isn't working label Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant