Skip to content

Add builtin.PythonFinalizationError#7966

Merged
youknowone merged 4 commits into
RustPython:mainfrom
ShaharNaveh:python-finalization-error
May 24, 2026
Merged

Add builtin.PythonFinalizationError#7966
youknowone merged 4 commits into
RustPython:mainfrom
ShaharNaveh:python-finalization-error

Conversation

@ShaharNaveh
Copy link
Copy Markdown
Contributor

@ShaharNaveh ShaharNaveh commented May 24, 2026

Summary by CodeRabbit

  • New Features
    • PythonFinalizationError exception is now available in the builtins module for proper error handling during finalization processes.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 24, 2026

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • Lib/test/exception_hierarchy.txt is excluded by !Lib/**

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 486a3b66-c4d7-49e6-9306-02874c55a22e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR adds PythonFinalizationError to the builtin exceptions exported by the virtual machine's init_module function. This single-line change registers the exception alongside other exception type mappings so it is accessible from the builtins module.

Changes

Exception type exports

Layer / File(s) Summary
PythonFinalizationError builtin exception
crates/vm/src/stdlib/builtins.rs
PythonFinalizationError exception is registered in the init_module exception list to make it available as a builtin.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

A tiny hop adds exception's grace,
PythonFinalizationError finds its place,
In builtins bright, so clean and right,
One line brings order to the night! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (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 change: adding PythonFinalizationError to builtins, which matches the file summary showing this exception is now exported via init_module.
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.

Comment thread Lib/test/test_builtin.py
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These changes are unrelated, but failed on my machine. I guess that they are skipped on thr CI

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 24, 2026

📦 Library Dependencies

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

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

dependencies:

dependent tests: (no tests depend on builtin)

[x] lib: cpython/Lib/pickle.py
[ ] lib: cpython/Lib/_compat_pickle.py
[x] test: cpython/Lib/test/picklecommon.py
[ ] test: cpython/Lib/test/test_pickle.py (TODO: 19)
[ ] test: cpython/Lib/test/test_picklebuffer.py (TODO: 12)
[ ] test: cpython/Lib/test/test_pickletools.py (TODO: 8)
[x] test: cpython/Lib/test/test_xpickle.py
[x] test: cpython/Lib/test/xpickle_worker.py

dependencies:

  • pickle (native: _pickle, itertools, sys)
    • _compat_pickle
    • _compat_pickle
    • argparse, codecs, copyreg, functools, io, pprint, struct, types

dependent tests: (100 tests)

  • pickle: test_annotationlib test_argparse test_array test_ast test_asyncio test_bool test_builtin test_bytes test_bz2 test_codecs test_collections test_concurrent_futures test_configparser test_coroutines test_csv test_ctypes test_decimal test_defaultdict test_deque test_descr test_dict test_dictviews test_email test_enum test_enumerate test_exceptions test_fractions test_functools test_generators test_genericalias test_http_cookies test_importlib test_inspect test_io test_ipaddress test_iter test_itertools test_list test_logging test_lzma test_memoryio test_memoryview test_minidom test_opcache test_operator test_ordered_dict test_os test_pathlib test_pickle test_picklebuffer test_pickletools test_platform test_plistlib test_positional_only_arg test_posix test_random test_range test_re test_set test_shelve test_slice test_socket test_statistics test_str test_string test_structseq test_time test_trace test_tuple test_type_aliases test_type_params test_types test_typing test_unittest test_uuid test_xml_dom_minicompat test_xml_etree test_xpickle test_zipfile test_zlib test_zoneinfo
    • logging: test_asyncio test_concurrent_futures test_hashlib test_pkgutil test_support test_urllib2net
      • asyncio.futures: test_asyncio
      • concurrent.futures._base: test_concurrent_futures
      • hashlib: test_hmac test_smtplib test_tarfile test_unicodedata test_urllib2_localnet
      • http.cookiejar: test_http_cookiejar test_urllib2
      • multiprocessing.util: test_asyncio test_compileall test_concurrent_futures
      • venv: test_venv

Legend:

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

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.

Actionable comments posted: 1

🤖 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/stdlib/builtins.rs`:
- Line 1477: The builtins mapping adds "PythonFinalizationError" pointing to
ctx.exceptions.python_finalization_error but the exception_hierarchy.txt doesn’t
include that symbol so the “ordered by exception_hierarchy.txt” guarantee is
invalid; update exception_hierarchy.txt to include PythonFinalizationError in
the proper place in the hierarchy (or adjust the ordering comment in
crates/vm/src/stdlib/builtins.rs) and ensure the symbol name matches the
constructor defined in crates/vm/src/exceptions.rs (PythonFinalizationError /
ctx.exceptions.python_finalization_error) so the wiring and ordering are
consistent.
🪄 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: 646474cc-d196-4510-bfa6-8d6286e519c1

📥 Commits

Reviewing files that changed from the base of the PR and between e1d9a11 and 709c11c.

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

"TimeoutError" => ctx.exceptions.timeout_error.to_owned(),
"ReferenceError" => ctx.exceptions.reference_error.to_owned(),
"RuntimeError" => ctx.exceptions.runtime_error.to_owned(),
"PythonFinalizationError" => ctx.exceptions.python_finalization_error.to_owned(),
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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash

# Check if exception_hierarchy.txt exists and verify PythonFinalizationError placement
echo "=== Checking exception_hierarchy.txt ==="
fd -t f 'exception_hierarchy' --exec cat {}

# Verify python_finalization_error field exists in the exceptions context
echo -e "\n=== Verifying python_finalization_error field exists ==="
rg -n 'python_finalization_error' --type rust

# Check for any related tests or documentation
echo -e "\n=== Checking for related tests ==="
rg -n 'PythonFinalizationError' --type rust -g '!builtins.rs'

Repository: RustPython/RustPython

Length of output: 14832


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== exception_hierarchy* files ==="
fd -t f 'exception_hierarchy' .

echo
echo "=== exception_hierarchy* occurrences of PythonFinalizationError ==="
for f in $(fd -t f 'exception_hierarchy' .); do
  if rg -n 'PythonFinalizationError' "$f" >/dev/null; then
    echo "-- $f"
    rg -n 'PythonFinalizationError' "$f"
  fi
done

echo
echo "=== builtins.rs context around line 1477 ==="
nl -ba crates/vm/src/stdlib/builtins.rs | sed -n '1455,1505p'

echo
echo "=== builtins.rs comment about exception_hierarchy.txt ==="
nl -ba crates/vm/src/stdlib/builtins.rs | sed -n '1405,1445p'

echo
echo "=== exceptions.rs definition of PyPythonFinalizationError base ==="
nl -ba crates/vm/src/exceptions.rs | sed -n '2425,2475p'

Repository: RustPython/RustPython

Length of output: 1964


Confirm PythonFinalizationError wiring; hierarchy ordering can’t be checked from exception_hierarchy.txt

  • ctx.exceptions.python_finalization_error exists (crates/vm/src/exceptions.rs) and the builtins mapping follows the same pattern as other exceptions.
  • The exception_hierarchy/exception_hierarchy.txt content available here doesn’t include PythonFinalizationError, so the “ordered by exception_hierarchy.txt” requirement can’t be validated—add it to the hierarchy file (or adjust the ordering comment) to keep this guarantee accurate.
🤖 Prompt for 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.

In `@crates/vm/src/stdlib/builtins.rs` at line 1477, The builtins mapping adds
"PythonFinalizationError" pointing to ctx.exceptions.python_finalization_error
but the exception_hierarchy.txt doesn’t include that symbol so the “ordered by
exception_hierarchy.txt” guarantee is invalid; update exception_hierarchy.txt to
include PythonFinalizationError in the proper place in the hierarchy (or adjust
the ordering comment in crates/vm/src/stdlib/builtins.rs) and ensure the symbol
name matches the constructor defined in crates/vm/src/exceptions.rs
(PythonFinalizationError / ctx.exceptions.python_finalization_error) so the
wiring and ordering are consistent.

@youknowone youknowone merged commit 7011942 into RustPython:main May 24, 2026
27 checks passed
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