typehint for dataclass asdict()
Closed this issue · 6 comments
as commented here,
pylance or mypy does not infer types asdict(x).values()
results for x is dataclass.
this is not ideal, since typecheck is almost disable at start of the functions.
is there anyway to workaround this?
just not using
a,b,c = asdict(x).values()
but accessor
x.a
x.b
x.c
yes. but in the function, x
or a
should be readable name which is much longer like transform_arg.circle
.
destruction is useful to reduce typing transform_arg.
all the way.
using attrgetter
:
https://stackoverflow.com/questions/54785148/destructuring-dicts-and-objects-in-python
type is not infer. Any type is applied.
pyserde type check:
https://github.com/yukinarit/pyserde/blob/main/docs/en/type-check.md
kind of runtime check, not static check.
pydantic: serialization to return Any. if you want to override it, have to write down.
https://docs.pydantic.dev/latest/usage/serialization/#overriding-the-return-type-when-dumping-a-model
I decided to implement to_tuple
method if needed. and add abstract class Tuplable
for that common method.