Skip to content

Accept frozenset and Mapping in type stubs#119

Merged
messense merged 1 commit intomessense:mainfrom
gghez:fix/frozenset-type-stubs
Mar 25, 2026
Merged

Accept frozenset and Mapping in type stubs#119
messense merged 1 commit intomessense:mainfrom
gghez:fix/frozenset-type-stubs

Conversation

@gghez
Copy link
Copy Markdown
Contributor

@gghez gghez commented Mar 25, 2026

PyO3 has supported extracting HashSet from both set and frozenset since
0.22, but the type stubs only declared Set[str] for set parameters and Dict
for mapping parameters. This meant type checkers like pyright would reject
perfectly valid calls like nh3.clean(html, tags=frozenset({"b"})).

I switched the parameter types to AbstractSet and Mapping — this correctly
reflects what PyO3 accepts at runtime. Constants like ALLOWED_TAGS stay typed
as Set[str] since they are concrete sets returned by ammonia.

Also added a couple of tests to verify frozenset works at runtime.

Closes #29

@messense messense merged commit d19279a into messense:main Mar 25, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow frozenset in attributes parameter of clean function

2 participants