ProtixIT / dataclass-binder

Python library to bind TOML data to dataclasses in a type-safe way
MIT License
13 stars 2 forks source link

Object bound to `Mapping` doesn't implement mapping interface #6

Closed mthuurne closed 1 year ago

mthuurne commented 1 year ago

Currently a dict_items object is bound, which was a misguided attempt in getting a read-only dictionary. The main problem is that it doesn't allow item access (get() and []).

The correct solution would be to return a mapping proxy, either via types.MappingProxyType or via items().mapping. The former exists since Python 3.3 and the latter since 3.10, so in case we ever want to backport the library to older Python versions I'll go with MappingProxyType.