Releases: rednafi/exert
Releases · rednafi/exert
v0.3.3
v0.3.1
v0.3.0
- Redesign the public API to be compatible with other bespoke tools that might be working on the same class.
- To apply a converter, now, you'll have to wrap it with
Mark
. Otherwise, it'll be ignored. Credit to @adriangb.
from __future__ import annotations
from typing import Annotated
from exert import exert, Mark
from dataclasses import dataclass
@exert(converters=(str, ), apply_last=True)
@dataclass
class Foo:
a: Annotated[int, Mark(lambda x: x**2)] # First the marked converter and then the common converter will be applied.
b: Annotated[float, lambda x: x / 2] # Only the common converter `str` will be applied.
c: int # No conversion will happen here.
foo = Foo(2, 42.0, 22)
print(foo.a) # prints '4'. [2**2=4, str(4)='4']
print(foo.b) # prints '42' [str(42.0) = '42.0']
print(foo.c) # prints 22