Features:
- If you pass a custom callable to the mapping, and the callable is annotated with types, the types will be checked and a typeerror is raised if the types are not compatible with the source class / target field. Fixes 32
python
dataclass
class Source:
x: int
dataclass
class Target:
x: str
def x_to_str(source: Source) -> str:
return str(source.x)
create_mapper(Source, Target, {"x": x_to_str})
- It's now also possible to map a subtype field to a super type field.
python
class FooBase: pass
class Foo(FooBase): pass
dataclass
class Source:
foo: Foo
dataclass
class Target:
foo: FooBase
create_mapper(Foo, FooBase)