Skip to content

Fix __set_name__ error handling to match Python 3.12+ - #6937

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowone:set_name_error
Feb 1, 2026
Merged

Fix __set_name__ error handling to match Python 3.12+#6937
youknowone merged 1 commit into
RustPython:mainfrom
youknowone:set_name_error

Conversation

@youknowone

@youknowone youknowone commented Feb 1, 2026

Copy link
Copy Markdown
Member

Changed type.rs to add notes to original exceptions instead of wrapping them in RuntimeError, following PEP 678 (gh-77757).

This allows enum.py's exception handling to work correctly when super().new() is misused in Enum subclasses, enabling the proper TypeError to propagate instead of being hidden behind a RuntimeError wrapper.

Fixes test_bad_new_super test case.

Summary by CodeRabbit

Bug Fixes

  • Improved error reporting in type initialization by adding contextual annotations to error messages, providing better debugging information when errors occur.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Feb 1, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Modified error handling in type initialization by replacing error wrapping with best-effort note augmentation. Instead of creating a new runtime error with the original as cause, the code now uses inspect_err to attempt adding a note to the original exception while preserving the original error flow.

Changes

Cohort / File(s) Summary
Error Handling Refactoring
crates/vm/src/builtins/type.rs
Changed error handling strategy in type initialization from wrapping errors with a new runtime error to performing best-effort note augmentation on the original exception using inspect_err.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A note so gently placed,
No wrapping, just a trace,
Errors flow with grace,
Exceptions find their space,
Better paths we chase! 📝

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 accurately describes the main change: modifying error handling for set_name to match Python 3.12+ behavior by using PEP 678 exception notes instead of wrapping errors.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

github-actions Bot commented Feb 1, 2026

Copy link
Copy Markdown
Contributor

Code has been automatically formatted

The code in this PR has been formatted using:

  • cargo fmt --all
    Please pull the latest changes before pushing again:
git pull origin set_name_error

@youknowone
youknowone force-pushed the set_name_error branch 2 times, most recently from 9a8fcf3 to bc9a8d4 Compare February 1, 2026 15:21
Changed type.rs to add notes to original exceptions instead of
wrapping them in RuntimeError, following PEP 678 (gh-77757).

This allows enum.py's exception handling to work correctly when
super().__new__() is misused in Enum subclasses, enabling the
proper TypeError to propagate instead of being hidden behind
a RuntimeError wrapper.

Fixes test_bad_new_super test case.
@github-actions

github-actions Bot commented Feb 1, 2026

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

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

[x] lib: cpython/Lib/enum.py
[x] test: cpython/Lib/test/test_enum.py (TODO: 5)

dependencies:

  • enum

dependent tests: (10 tests)

  • enum: test_argparse test_ast test_enum test_httplib test_json test_patma test_signal test_ssl test_time test_uuid

[x] lib: cpython/Lib/functools.py
[ ] test: cpython/Lib/test/test_functools.py (TODO: 10)

dependencies:

  • functools

dependent tests: (37 tests)

  • functools: test_argparse test_ast test_asyncio test_builtin test_bytes test_context test_ctypes test_datetime test_dbm_dumb test_dbm_sqlite3 test_dis test_doctest test_fileio test_fractions test_functools test_genericalias test_gettext test_gzip test_hmac test_inspect test_itertools test_math_property test_posixpath test_py_compile test_random test_shutil test_signal test_sort test_sqlite3 test_ssl test_sys_settrace test_timeout test_traceback test_typing test_unittest test_xml_etree test_zoneinfo

[ ] test: cpython/Lib/test/test_class.py (TODO: 16)
[x] test: cpython/Lib/test/test_genericclass.py (TODO: 1)
[x] test: cpython/Lib/test/test_subclassinit.py

dependencies:

dependent tests: (no tests depend on class)

Legend:

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

@youknowone
youknowone marked this pull request as ready for review February 1, 2026 16:19
@youknowone

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Feb 1, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@youknowone
youknowone merged commit 019e754 into RustPython:main Feb 1, 2026
14 checks passed
@youknowone
youknowone deleted the set_name_error branch February 1, 2026 23:11
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.

1 participant