nh3 icon indicating copy to clipboard operation
nh3 copied to clipboard

Allow frozenset in attributes parameter of clean function

Open ashrub-holvi opened this issue 1 year ago • 6 comments

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.

ashrub-holvi avatar Nov 28 '23 12:11 ashrub-holvi

also MappingProxyType can be allowed instead of dictionary

ashrub-holvi avatar Nov 28 '23 14:11 ashrub-holvi

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.

adamchainz avatar Dec 07 '23 11:12 adamchainz

Adding support for frozenset in https://github.com/PyO3/pyo3/pull/3632

messense avatar Dec 07 '23 12:12 messense

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.

ashrub-holvi avatar Jan 02 '24 08:01 ashrub-holvi

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.

messense avatar Dec 06 '24 01:12 messense