Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for Enums

See original GitHub issue


very cool library, thanks for it.

Is there any intention to add support for Enums in order let the following code work:

from dataclasses import dataclass
from enum import Enum

from dacite import from_dict

class SomeEnum(Enum):
    FIRST_VALUE = "first"
    SECOND_VALUE = "second"

class DataClass:
    message: str
    value: SomeEnum

data = {"message": "hello", "value": "first"}
from_dict(data_class=DataClass, data=data)

Currently this raises

dacite.exceptions.WrongTypeError: wrong type for field "value" - should be "SomeEnum" instead of "str"

But actually it should be quite easy to do the conversion to the enum along the deserialization (SomeEnum("first") yields <SomeEnum.FIRST_VALUE: 'first'>)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

konradhalascommented, Dec 12, 2019

@antonagestam it almost ready 😃 I hope I will push it during upcoming weekend.

antonagestamcommented, Dec 12, 2019

@konradhalas Oh, very cool! Thanks for working on it! 🙌

Read more comments on GitHub >

github_iconTop Results From Across the Web

enum — Support for enumerations — Python 3.11.1 ...
enum — Support for enumerations¶ · is a set of symbolic names (members) bound to unique values · can be iterated over to...
Read more >
Handbook - Enums - TypeScript
Enums allow a developer to define a set of named constants. Using enums can make it easier to document intent, or create a...
Read more >
Documentation: 15: 8.7. Enumerated Types - PostgreSQL
Enumerated (enum) types are data types that comprise a static, ordered set of values. They are equivalent to the enum types supported in...
Read more >
In 5.0, the Java™ programming language gets linguistic support for enumerated types. In their simplest form, these enums look just like their C,...
Read more >
PHP 8.1: Enums
PHP 8.1 adds support for Enumerations. An Enumeration, or an Enum for short, is an enumerated type that has a fixed number of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found