dacite icon indicating copy to clipboard operation
dacite copied to clipboard

improve Data typing

Open trim21 opened this issue 1 year ago • 0 comments

Data does not need to be a Mapping[str, Any] but just object with keys and __getitem__

This make it possible to use some dict-like object, for example asyncpg.Record without typing error.

for example, asyncpg.Record has keys() -> Iterable[str] bot not keys() -> KeysView[str], and we convert keys to set so it also doesn't need keys to return KeysView

before:

row = pg.fetchrow(...)
v = from_dict(..., row) # mypy raise typing error, asyncpg.Record doesn't satisfy Mapping[str, Any]

trim21 avatar Aug 31 '24 06:08 trim21