Skip to content

fix(bitfield): Raise the intended error for empty dict flags - #127886

Draft
joshuarli wants to merge 1 commit into
masterfrom
fix/bitfield-empty-dict-flags-error
Draft

joshuarli wants to merge 1 commit into
masterfrom
fix/bitfield-empty-dict-flags-error

Conversation

@joshuarli

Copy link
Copy Markdown
Member

BitField.__init__ collected the valid integer keys of a flags dict into a generator. A generator is always truthy, so the if not valid_keys guard never fired, and a dict with no valid keys ({} or only non-integer or out-of-range keys) fell through to max(valid_keys) and failed with ValueError: max() arg is an empty sequence instead of the intended Wrong keys or empty dictionary.

Build valid_keys as a list so the guard works. Both cases still raise ValueError; only the message changes, so no behavior is relied on elsewhere.

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 16, 2026
@getsantry

getsantry Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

This pull request has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you add the label WIP, I will leave it alone unless WIP is removed ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@getsantry getsantry Bot added the Stale label Nov 7, 2026
@joshuarli
joshuarli force-pushed the fix/bitfield-empty-dict-flags-error branch from a63911b to ebfd7cb Compare November 12, 2026 19:02
@getsantry getsantry Bot removed the Stale label Nov 13, 2026
valid_keys was a generator, so the emptiness check never triggered and max() raised a confusing 'empty sequence' ValueError instead of 'Wrong keys or empty dictionary'. Use a list so the guard works.
@joshuarli
joshuarli force-pushed the fix/bitfield-empty-dict-flags-error branch from ebfd7cb to b453b6b Compare November 26, 2026 00:02

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

GitHub Team: python-typing Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant