konradhalas / dacite

Simple creation of data classes from dictionaries.
MIT License
1.76k stars 106 forks source link

improve Data typing #260

Open trim21 opened 2 months ago

trim21 commented 2 months ago

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]