Skip to content

Fix set operations on frame flags - #172

Open
shkyyy18 wants to merge 1 commit into
python-hyper:masterfrom
shkyyy18:fix/flags-set-operations
Open

shkyyy18 wants to merge 1 commit into
python-hyper:masterfrom
shkyyy18:fix/flags-set-operations

Conversation

@shkyyy18

@shkyyy18 shkyyy18 commented Oct 1, 2026

Copy link
Copy Markdown

Bug

Flags inherits the MutableSet operations, but its constructor expects flag definitions rather than the flag-name iterable that those operations supply. As a result, even frame.flags &= {"END_HEADERS"} raises AttributeError: 'str' object has no attribute 'name' when another flag must be removed. Non-mutating intersection, union, difference and symmetric difference fail in the same way, including reflected operations with a plain set.

Change

Override the set mixin's _from_iterable factory to return an ordinary set. That avoids treating string elements as Flag definitions. Non-mutating results do not carry frame-specific validation; in-place operations still retain the original Flags object and validate additions. This matches the regular-set behavior described by Flags and avoids changing the constructor or the frame's valid-flag definitions.

Add coverage for all four non-mutating operations in both operand orders, all four in-place operations, an empty result, and invalid additions. Include a changelog entry.

Validation

On Python 3.12 / Windows, using the repository's pinned public HTTP/2 fixture submodule:

  • Baseline full suite: 148 passed, 100% branch coverage.
  • Flags tests before the fix: 10 failed, 9 passed (nine AttributeError regressions and one empty-result type assertion).
  • Full suite after the fix: 163 passed, 100% branch coverage.
  • ruff check src/: passed.
  • mypy src/ (strict): passed.
  • Other Python/platform environments, docs and packaging checks were not run.

AI assistance was used to identify, implement, and test this fix. Tests use synthetic flags and the existing public fixture collection.

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.

1 participant