Skip to content

Fix frozenset subclass keyword arguments - #8287

Merged
youknowone merged 1 commit into
RustPython:mainfrom
kyokuping:codex/frozenset-subclass-keywords
Jul 17, 2026
Merged

Fix frozenset subclass keyword arguments#8287
youknowone merged 1 commit into
RustPython:mainfrom
kyokuping:codex/frozenset-subclass-keywords

Conversation

@kyokuping

@kyokuping kyokuping commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Assisted-by: Codex:gpt-5.6

Summary

  • Fix frozenset subclass construction to match CPython’s keyword-argument behavior.
  • Allow subclasses with a custom __init__ to receive keyword arguments while frozenset.__new__ consumes the positional iterable.
  • Preserve strict argument validation for exact frozenset and subclasses inheriting frozenset.__init__.
  • Keep exact-type reuse and empty-singleton optimizations limited to exact frozenset instances.
  • Re-enable TestFrozenSetSubclass.test_keywords_in_subclass by removing its expectedFailure marker.

Summary by CodeRabbit

  • Bug Fixes
    • Improved frozenset construction by detecting the exact builtin type for a faster initialization path.
    • Returns existing builtin frozenset inputs directly when appropriate.
    • For frozenset subclasses, enforces “at most 1 argument” and raises TypeError when more than one positional argument is provided.
    • Optimized empty frozenset creation to reuse the existing empty singleton instead of allocating a new one.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 792cb6db-1876-41aa-9252-418645ffe34f

📥 Commits

Reviewing files that changed from the base of the PR and between 3d5c9b6 and 67e489b.

⛔ Files ignored due to path filters (1)
  • Lib/test/test_set.py is excluded by !Lib/**
📒 Files selected for processing (1)
  • crates/vm/src/builtins/set.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/vm/src/builtins/set.rs

📝 Walkthrough

Walkthrough

Refactors PyFrozenSet::slot_new to select optimized or subclass argument handling based on type and __init__ compatibility, reuse builtin frozenset inputs, enforce argument limits, and consolidate empty frozenset singleton construction.

Changes

Frozenset construction

Layer / File(s) Summary
Constructor dispatch and result handling
crates/vm/src/builtins/set.rs
slot_new distinguishes exact and builtin-compatible constructors, validates subclass argument counts, reuses builtin frozenset inputs, converts iterables, and returns the empty singleton for empty exact frozensets.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: frozenset subclass construction now handles keyword arguments correctly.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/vm/src/builtins/set.rs`:
- Around line 992-1002: Update the argument match in the subclass-instantiation
branch to add an explicit zero-positional-arguments arm that returns an empty
vector, matching the fallback used by the main branch. Keep the single-iterable
handling and TypeError for more than one positional argument unchanged.
- Around line 992-1002: Update the argument match in the frozenset subclass
constructor path to handle zero positional arguments explicitly with an empty
collection value. Keep the existing single-iterable handling and
excessive-argument TypeError behavior unchanged.
- Around line 975-1002: Update the element-selection logic in the frozenset
constructor to first derive a single optional iterable: preserve the
exact-frozenset fast path, accept one positional argument, and treat zero
positional arguments as absent while still rejecting more than one. Then perform
iterable.try_to_value(vm)? or return an empty vector once after the branches,
eliminating the duplicated extraction logic and allowing subclass construction
with only keyword arguments.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 276b5a7e-2889-4764-ba5f-a4c53b02d53f

📥 Commits

Reviewing files that changed from the base of the PR and between c1bc99a and 845acfd.

⛔ Files ignored due to path filters (1)
  • Lib/test/test_set.py is excluded by !Lib/**
📒 Files selected for processing (1)
  • crates/vm/src/builtins/set.rs

Comment thread crates/vm/src/builtins/set.rs
Comment thread crates/vm/src/builtins/set.rs
@kyokuping
kyokuping force-pushed the codex/frozenset-subclass-keywords branch from 845acfd to e37b7c9 Compare July 15, 2026 17:51
@kyokuping
kyokuping marked this pull request as draft July 15, 2026 18:41
@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[ ] test: cpython/Lib/test/test_set.py (TODO: 4)

dependencies:

dependent tests: (no tests depend on set)

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

@kyokuping
kyokuping marked this pull request as ready for review July 16, 2026 08:26
@moreal moreal added the z-ca-2026 Tag to track Contribution Academy 2026 label Jul 16, 2026
@kyokuping
kyokuping force-pushed the codex/frozenset-subclass-keywords branch from 592806f to 3d5c9b6 Compare July 16, 2026 12:49
@fanninpm

Copy link
Copy Markdown
Contributor

If the CI failure bothers you, you can rebase this branch onto a fresh copy of main.

Assisted-by: Codex:gpt-5.6
@kyokuping
kyokuping force-pushed the codex/frozenset-subclass-keywords branch from 3d5c9b6 to 67e489b Compare July 16, 2026 18:12

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!

@youknowone
youknowone merged commit ea6880b into RustPython:main Jul 17, 2026
27 checks passed
@kyokuping
kyokuping deleted the codex/frozenset-subclass-keywords branch August 8, 2026 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

z-ca-2026 Tag to track Contribution Academy 2026

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants