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

dict cannot be matched if keys are specified as enums in dataclass #239

Open
gryznar opened this issue Jul 10, 2023 · 3 comments
Open

dict cannot be matched if keys are specified as enums in dataclass #239

gryznar opened this issue Jul 10, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@gryznar
Copy link

gryznar commented Jul 10, 2023

Describe the bug

dict is not matched if its keys are enums

To Reproduce

from enum import Enum
from dacite import Config, from_dict


class Bar(Enum):
    BAR_1 = 1
    BAR_2 = 2


@dataclass
class Foo:
    d: dict[Bar, str]

from_dict(Foo, {'d': {1: "1"}}, config=Config(cast=[Enum]))

Expected behavior

dataclass is created

Actual behavior

dacite.exceptions.WrongTypeError: wrong value type for field "d" - should be "dict" instead of value "{1: '1'}" of type "dict"

Environment

  • Python version: 3.10
  • dacite version: 1.8.1
@gryznar gryznar added the bug Something isn't working label Jul 10, 2023
@vrmaroli
Copy link

vrmaroli commented Oct 9, 2023

Is there a workaround for this?

@ali-raza-zaidi
Copy link

Facing similar issues. Was hoping to get this fixed if possible

@clintlombard
Copy link

@ali-raza-zaidi I had a similar issue, and ended up switching to msgspec to solve it.

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

4 participants