Skip to content

Make singleton builtin types immutable#7423

Merged
youknowone merged 1 commit intoRustPython:mainfrom
moreal:fix/fail-builtin-test-singleton-attribute-access
Mar 14, 2026
Merged

Make singleton builtin types immutable#7423
youknowone merged 1 commit intoRustPython:mainfrom
moreal:fix/fail-builtin-test-singleton-attribute-access

Conversation

@moreal
Copy link
Copy Markdown
Contributor

@moreal moreal commented Mar 13, 2026

This pull request just marks NotImplemented and Ellipsis as immutable type (IMMUTABLETYPE flag).

Summary by CodeRabbit

  • Chores
    • Internal improvements to built-in singleton types for enhanced type safety and immutability enforcement.

@github-actions
Copy link
Copy Markdown
Contributor

📦 Library Dependencies

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

[x] test: cpython/Lib/test/test_builtin.py (TODO: 18)

dependencies:

dependent tests: (no tests depend on builtin)

Legend:

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 13, 2026

📝 Walkthrough

Walkthrough

Two singleton type declarations in the virtual machine's built-in types are updated to include the IMMUTABLETYPE flag, marking PyNotImplemented and PyEllipsis as immutable types. No functional behavior or method implementations are changed.

Changes

Cohort / File(s) Summary
Singleton Type Immutability
crates/vm/src/builtins/singletons.rs, crates/vm/src/builtins/slice.rs
Added flags(IMMUTABLETYPE) to pyclass declarations for PyNotImplemented and PyEllipsis, marking these singleton types as immutable.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Suggested reviewers

  • youknowone

Poem

🐰 Two singletons stand firm and strong,
Now marked immutable all day long,
No changing ways for them, hooray!
The flags declare it here to stay ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Make singleton builtin types immutable' accurately describes the main change: adding the IMMUTABLETYPE flag to PyNotImplemented and PyEllipsis singleton classes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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 and usage tips.

Tip

You can make CodeRabbit's review stricter and more nitpicky using the `assertive` profile, if that's what you prefer.

Change the reviews.profile setting to assertive to make CodeRabbit's nitpick more issues in your PRs.

@moreal moreal marked this pull request as ready for review March 14, 2026 00:00
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
crates/vm/src/builtins/singletons.rs (1)

101-101: LGTM, but consider consistency with PyNone.

The IMMUTABLETYPE flag correctly marks NotImplementedType as immutable. However, PyNone (defined in this same file at lines 52-53) is also a singleton type but doesn't have the IMMUTABLETYPE flag. In CPython, NoneType is likewise immutable.

Consider adding IMMUTABLETYPE to PyNone for consistency:

-#[pyclass(with(Constructor, AsNumber, Representable))]
+#[pyclass(with(Constructor, AsNumber, Representable), flags(IMMUTABLETYPE))]
 impl PyNone {}

,

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/vm/src/builtins/singletons.rs` at line 101, The PyNone type should be
marked immutable like NotImplementedType for consistency; update the
#[pyclass(...)] attribute on PyNone to include flags(IMMUTABLETYPE) (mirror the
usage from NotImplementedType) so the PyNone singleton is treated as immutable
by the VM.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@crates/vm/src/builtins/singletons.rs`:
- Line 101: The PyNone type should be marked immutable like NotImplementedType
for consistency; update the #[pyclass(...)] attribute on PyNone to include
flags(IMMUTABLETYPE) (mirror the usage from NotImplementedType) so the PyNone
singleton is treated as immutable by the VM.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 467ef5bd-73ea-4fc0-9be9-944719979dd9

📥 Commits

Reviewing files that changed from the base of the PR and between 073adbd and 037b72d.

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

@youknowone youknowone merged commit ed032d3 into RustPython:main Mar 14, 2026
16 checks passed
youknowone pushed a commit to youknowone/RustPython that referenced this pull request Mar 19, 2026
youknowone pushed a commit to youknowone/RustPython that referenced this pull request Mar 22, 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