Skip to content

Reject non-set objects for concrete set annotations - #594

Open
jakezwang wants to merge 2 commits into
agronholm:masterfrom
jakezwang:fix/concrete-set-type-check
Open

jakezwang wants to merge 2 commits into
agronholm:masterfrom
jakezwang:fix/concrete-set-type-check

Conversation

@jakezwang

Copy link
Copy Markdown

Changes

check_type(frozenset({1}), set[int]) currently passes because concrete sets use the same instance check as AbstractSet. Dictionary key views are also accepted, although neither provides the mutable set API.

Require a set instance for concrete set annotations. Keep accepting set subclasses, and preserve the broader behavior of AbstractSet. Tests cover built-in and typing annotations, empty/nonempty frozen sets, key views, and subclass controls.

Validation: full tox suite on Python 3.10–3.15, pre-commit and package checks passed. The strict docs build has the same two typing.Union cross-reference warnings as unmodified master.

Checklist

  • Added tests that fail without the patch.
  • Updated the supported-type documentation.
  • Added a changelog entry.

@coveralls

coveralls commented Sep 19, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 94.862% (+0.009%) from 94.853% — jakezwang:fix/concrete-set-type-check into agronholm:master

This branch has not been deployed

No deployments
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.

2 participants