Support for Enums
See original GitHub issueHey,
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"
@dataclass
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:
- Created 4 years ago
- Reactions:8
- Comments:14 (10 by maintainers)
Top 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 >Enums
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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@antonagestam it almost ready 😃 I hope I will push it during upcoming weekend.
@konradhalas Oh, very cool! Thanks for working on it! 🙌