Enums
With this release it's now possible to create mappings for enums (using `enum_mapper` and `enum_mapper_from`).
py
class Foo(Enum):
A = 1
B = 2
OTHER = 99
enum_mapper(Foo, {"ELSE": "OTHER"})
class Bar(str, Enum):
A = "A"
B = "B"
ELSE = "ELSE"
Notice, that the order of the mapping parameters is exactly the other way round. It's not `target: source`. That is important for dataclasses, as every target field needs to be mapped by something - and can potentially be defined via a lambda. So every target field had at most one definition, that relied of one or multiple other pieces.
But with enums it's important, that every single member of the source enum is mapped to something. And it's possible that multiple source values map to the same target field. So the mapping definition `source:target` makes a lot more sense.
Pydantic's alias
Also there is now full support for Pydantic's aliases. If an alias was defined for a field, you need to create object with those alias.
py
class Baz(BaseModel):
x: int = Field(alias="y")
baz = Baz(y=42)
The `dataclass-mapper<1.4.0` library would have instantiated those class objects wrongly with `Baz(x=42)`. With this release, it will use the alias if required by the class/field definition. But it will fallback to the field name, if the option `allow_population_by_field_name` is set - just in case non-Python variable names are use as aliases.