Skip to content

Fix IndexedSet.pop integer-index validation - #535

Closed
harbinresearcher wants to merge 1 commit into
mahmoud:masterfrom
harbinresearcher:codex/fix-indexedset-pop-index
Closed

harbinresearcher wants to merge 1 commit into
mahmoud:masterfrom
harbinresearcher:codex/fix-indexedset-pop-index

Conversation

@harbinresearcher

Copy link
Copy Markdown

The change

Normalize explicit IndexedSet.pop() indices with operator.index() before
comparisons or mutation, matching the existing __getitem__ behavior. Currently
IndexedSet(range(4)).pop(3.0) silently removes the last element, while valid
__index__ objects are rejected or compared before normalization.

Keep the existing None default, integer/bool behavior, dead-slot mapping and
compaction unchanged. Regression coverage checks rejected indices leave state
intact and accepted indices agree with list.pop() in dense/sparse layouts.

The backstory

I'm contributing to learn and build open-source experience, and hadn't used
boltons before this contribution. This was found during a Codex-assisted source
audit, not in production: __getitem__ already uses the integer-index protocol,
but the last-item shortcut in pop() bypasses it.

Verification

  • Windows / Python 3.12.14: pristine setutils baseline 16 passed; all tests and
    doctests 678 passed, 12 subtests passed.
  • New regressions on pristine code: 17 failed, 12 passed (two runs).
  • Changed setutils: 45 passed; all tests and doctests: 707 passed,
    12 subtests passed.
  • Upstream tox -e py314 on Windows / Python 3.14.6 builds and installs the
    package, then passes all 707 tests/doctests (five unrelated deprecation warnings).
  • Independent read-only code review: no actionable findings; independently
    repeated the same full suite and git diff --check successfully.
  • git diff --check passes. No dependency or unrelated changes.

AI assistance

  • Harness/tooling: OpenAI Codex desktop, plus an independent read-only Codex reviewer.
  • Model(s): GPT-5-based Codex; the exact backend model identifier is not exposed in this session.
  • Original prompt(s): "继续做开源 可以做进阶一点的" ("Continue open-source contributions; a more advanced change is welcome"), followed by "继续" ("Continue"). Earlier workflow instruction: "你可以自动进行 完成每次pr之后再停止" ("You may proceed automatically; stop after completing each PR").
  • Background confirmed by the contributor: "为了学习和积累开源经验,之前没用过 Boltons" ("To learn and build open-source experience; I hadn't used Boltons before").

@mahmoud

mahmoud commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Folded into #609 (see the PR description for credit). Thanks for the report and the repro.

@mahmoud mahmoud closed this Oct 25, 2026
blebo pushed a commit to blebo/boltons that referenced this pull request Nov 1, 2026
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