nh3
nh3 copied to clipboard
Allow frozenset in attributes parameter of clean function
Now it's dict[str, set[str]], and attempt to use frozenset will return
TypeError: argument 'attributes': 'frozenset' object cannot be converted to 'PySet'
but IMO using frozenset is a good practice, because if data is immutable good to use immutable type, for example allowed attributes can be defined in configuration and it's safer to use immutable type.
also MappingProxyType can be allowed instead of dictionary
The TypeError comes from PyO3. It’s not clear to me from the PyO3 arg docs if there’s an easy way to allow all kinds of mappings or sets and have PyO3 convert them.
Adding support for frozenset in https://github.com/PyO3/pyo3/pull/3632
Thank you! Do you think it's possible to add support of MappingProxyType? As I understand it's only way to have read-only dictionaries without adding third-party libraries.
Thank you! Do you think it's possible to add support of MappingProxyType? As I understand it's only way to have read-only dictionaries without adding third-party libraries.
Should be possible now that https://github.com/PyO3/pyo3/pull/4644 is merged, will try to add support for it in nh3 later.