Skip to content

Match CPython error wording for __slots__ conflict and __doc__ delete - #7698

Merged
youknowone merged 1 commit into
RustPython:mainfrom
changjoon-park:match-cpython-type-attr-error-messages
Apr 27, 2026
Merged

Match CPython error wording for __slots__ conflict and __doc__ delete#7698
youknowone merged 1 commit into
RustPython:mainfrom
changjoon-park:match-cpython-type-attr-error-messages

Conversation

@changjoon-park

@changjoon-park changjoon-park commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Two small wording differences from CPython's type-attribute error messages, both flagged by test_descr.ClassPropertiesAndMethods:

Site RustPython CPython 3.14
__slots__ conflicts with class attr (type.rs:2007) "...conflicts with a class variable" "...conflicts with class variable"
del cls.__doc__ (type.rs:2407) "cannot delete '__doc__' attribute of type 'X'" "cannot delete '__doc__' attribute of immutable type 'X'"

The behavior in both cases already matched CPython (the conflict is detected, the delete is rejected); only the message text drifted. CPython surfaces the "immutable" phrase even for user-defined classes because the __doc__ descriptor refuses the delete unconditionally.

Tests unmasked

  • test_descr.ClassPropertiesAndMethods.test_slot_shadows_class_variable
  • test_descr.ClassPropertiesAndMethods.test_set_doc

Verification

  • 11 modules pass with no regressions: test_descr test_class test_super test_abc test_property test_metaclass test_call test_module test_typing test_inspect test_decorators (1,645 tests)
  • CPython 3.14.4 byte-identical wording for both messages
  • No other test or RustPython source references the old wording (grep'd Lib/test/ and crates/)

Summary by CodeRabbit

  • Bug Fixes
    • Refined error messages for improved clarity when encountering class attribute conflicts and immutable type modifications.

The behavior already matched CPython (the slot conflict is detected,
the __doc__ delete is rejected); only the message text drifted.

- "__slots__ conflicts with a class variable" -> drop the stray "a"
  to match CPython's "conflicts with class variable".
- "cannot delete '__doc__' attribute of type 'X'" -> insert "immutable"
  before "type" to match CPython's wording (CPython surfaces the same
  phrase even for user-defined classes since the descriptor refuses
  the delete unconditionally).
@coderabbitai

coderabbitai Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

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: eb91d418-0ddf-4694-ab32-7424a87f7dd3

📥 Commits

Reviewing files that changed from the base of the PR and between 02c454b and 3519255.

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

📝 Walkthrough

Walkthrough

Two exception message strings in the type module were refined: removing "a" from a class variable conflict error and clarifying __doc__ deletion as attempting to modify an "immutable" type. No logic changes.

Changes

Cohort / File(s) Summary
Error Message Updates
crates/vm/src/builtins/type.rs
Updated two exception messages: (1) __slots__/class attribute conflict now reports "class variable" instead of "a class variable"; (2) __doc__ deletion now indicates the type is "immutable" in TypeError.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Suggested reviewers

  • ShaharNaveh
  • youknowone

Poem

🐰 A message tweaked, a word removed,
"Immutable" truth now clearly proved,
Error strings polished, shining bright,
Type exceptions now ring just right!

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: updating error message wording in type.rs to match CPython for slots conflicts and doc deletion.
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.

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

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

@github-actions

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

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

[ ] test: cpython/Lib/test/test_descr.py (TODO: 39)
[ ] test: cpython/Lib/test/test_descrtut.py (TODO: 3)

dependencies:

dependent tests: (no tests depend on descr)

Legend:

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

@ShaharNaveh ShaharNaveh 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.

ty!

@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.

Thanks!

@youknowone
youknowone merged commit dc81c74 into RustPython:main Apr 27, 2026
21 checks passed
@changjoon-park
changjoon-park deleted the match-cpython-type-attr-error-messages branch April 27, 2026 13:24
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.

3 participants