messense / nh3

Python binding to Ammonia HTML sanitizer Rust crate
https://nh3.readthedocs.io
MIT License
260 stars 8 forks source link

Allow frozenset in attributes parameter of clean function #29

Open ashrub-holvi opened 11 months ago

ashrub-holvi commented 11 months ago

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 commented 11 months ago

also MappingProxyType can be allowed instead of dictionary

adamchainz commented 11 months ago

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.

messense commented 11 months ago

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

ashrub-holvi commented 10 months ago

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.