Skip to content

Use _print_exception_bltin in excepthook, register source in linecache#7177

Merged
youknowone merged 1 commit intoRustPython:mainfrom
youknowone:_print_exception_bltin
Feb 17, 2026
Merged

Use _print_exception_bltin in excepthook, register source in linecache#7177
youknowone merged 1 commit intoRustPython:mainfrom
youknowone:_print_exception_bltin

Conversation

@youknowone
Copy link
Member

@youknowone youknowone commented Feb 17, 2026

  • excepthook: call traceback._print_exception_bltin instead of traceback.print_exception to match PyErr_Display behavior
  • run_string: register compiled code in linecache._interactive_cache so traceback can display source lines and caret indicators
  • Remove test_sys_tracebacklimit expectedFailure

Summary by CodeRabbit

  • Bug Fixes

    • Improved exception traceback output for clearer error messages.
    • Enhanced debugging by registering executed source so stack traces show more accurate line information.
  • Chores

    • Updated spell-check dictionary with an additional symbol.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 17, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Switches sys.excepthook to call an internal traceback builtin and registers executed code objects in linecache during run_string; also adds "bltin" to the cspell dictionary. (41 words)

Changes

Cohort / File(s) Summary
Dictionary
/.cspell.dict/cpython.txt
Added the token bltin to the spell-check dictionary.
Exception handling
crates/vm/src/stdlib/sys.rs
excepthook now imports traceback and calls traceback._print_exception_bltin before falling back to the Rust-level printing path.
Code execution / linecache
crates/vm/src/vm/python_run.rs
In run_string, registers created PyCode in linecache via a new private helper that calls linecache._register_code(code, source, filename). Added type imports to support this.

Sequence Diagram(s)

sequenceDiagram
    participant VM as "VM (run_string)"
    participant PyCode as "PyCode (builtins::PyCode)"
    participant Linecache as "linecache._register_code"
    VM->>PyCode: create code object from source
    VM->>Linecache: call _register_code(code, source, filename)
    Linecache-->>VM: confirmation (implicit)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A nibble, a hop, a humble small spin,
I tucked code in cache and let tracebacks begin,
"bltin" now whispers in dictionary light,
Exceptions dress neat for a clearer sight. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures both main changes: switching to _print_exception_bltin in excepthook and registering source in linecache.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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
Copy link
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 _print_exception_bltin

@youknowone youknowone force-pushed the _print_exception_bltin branch 3 times, most recently from 1d6566f to 76ffed4 Compare February 17, 2026 14:01
@youknowone youknowone marked this pull request as ready for review February 17, 2026 15:41
Copy link
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 the current code and only fix it if needed.

Inline comments:
In `@crates/vm/src/vm/python_run.rs`:
- Around line 31-40: In register_code_in_linecache, change the direct field
access to use the public accessor: replace the use of code.source_path.as_str()
with code.source_path().as_str(); update the call that creates filename (in the
register_code_in_linecache function) so it uses PyCode::source_path() rather
than the private field, keeping the rest of the call to linecache._register_code
unchanged.

- excepthook: call traceback._print_exception_bltin instead of
  traceback.print_exception to match PyErr_Display behavior
- run_string: register compiled code in linecache._interactive_cache
  so traceback can display source lines and caret indicators
- Remove test_sys_tracebacklimit expectedFailure
@youknowone youknowone force-pushed the _print_exception_bltin branch from 5baab1d to 27390dc Compare February 17, 2026 16:50
@youknowone youknowone merged commit b5785e2 into RustPython:main Feb 17, 2026
12 of 14 checks passed
@youknowone youknowone deleted the _print_exception_bltin branch February 17, 2026 16:50
@github-actions
Copy link
Contributor

📦 Library Dependencies

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

[ ] lib: cpython/Lib/csv.py
[ ] test: cpython/Lib/test/test_csv.py (TODO: 27)

dependencies:

  • csv (native: _csv)
    • types
    • io

dependent tests: (2 tests)

  • csv: test_csv test_genericalias

[ ] test: cpython/Lib/test/test_sys.py (TODO: 14)
[ ] test: cpython/Lib/test/test_syslog.py (TODO: 2)
[ ] test: cpython/Lib/test/test_sys_setprofile.py (TODO: 14)
[ ] test: cpython/Lib/test/test_sys_settrace.py (TODO: 85)

dependencies:

dependent tests: (212 tests)

  • sys: regrtestdata test___all__ test__colorize test__locale test__osx_support test_android test_annotationlib test_argparse test_array test_ast test_asyncio test_audit test_bdb test_bigaddrspace test_bigmem test_bisect test_buffer test_builtin test_bytes test_bz2 test_c_locale_coercion test_calendar test_call test_cmath test_cmd test_cmd_line test_cmd_line_script test_code test_code_module test_codeccallbacks test_codecs test_collections test_compile test_compileall test_complex test_concurrent_futures test_context test_contextlib test_coroutines test_csv test_ctypes test_datetime test_dbm test_dbm_sqlite3 test_descr test_dict test_difflib test_dis test_doctest test_doctest2 test_docxmlrpc test_dtrace test_dynamic test_dynamicclassattribute test_email test_ensurepip test_enum test_enumerate test_eof test_except_star test_exceptions test_faulthandler test_fcntl test_file test_file_eintr test_fileinput test_fileio test_float test_fork1 test_format test_fractions test_frozen test_functools test_future_stmt test_generators test_genericpath test_getopt test_glob test_grammar test_gzip test_hash test_hashlib test_http_cookiejar test_httpservers test_importlib test_inspect test_int test_io test_iter test_itertools test_json test_largefile test_launcher test_list test_locale test_logging test_long test_lzma test_mailbox test_marshal test_math test_memoryio test_memoryview test_metaclass test_mimetypes test_mmap test_msvcrt test_multiprocessing_fork test_multiprocessing_main_handling test_ntpath test_numeric_tower test_operator test_optparse test_ordered_dict test_os test_osx_env test_pathlib test_patma test_peepholer test_pickle test_pkg test_pkgutil test_platform test_plistlib test_posix test_posixpath test_print test_property test_pty test_pwd test_py_compile test_pyclbr test_pydoc test_pyexpat test_quopri test_raise test_range test_re test_regrtest test_repl test_reprlib test_resource test_runpy test_script_helper test_select test_selectors test_shutil test_signal test_site test_slice test_smtplib test_socket test_sqlite3 test_ssl test_stat test_statistics test_str test_strftime test_string_literals test_strtod test_struct test_subprocess test_support test_symtable test_sys test_sys_setprofile test_sys_settrace test_sysconfig test_syslog test_tarfile test_tempfile test_termios test_threadedtempfile test_threading test_threading_local test_threadsignals test_time test_timeit test_tomllib test_tools test_trace test_traceback test_type_comments test_types test_typing test_unicode_file test_unicode_file_functions test_unicodedata test_unittest test_univnewlines test_urllib test_urllib2 test_urllib2net test_urlparse test_utf8_mode test_uuid test_venv test_wait3 test_wait4 test_wave test_weakref test_webbrowser test_winconsoleio test_with test_wsgiref test_xml_etree test_xmlrpc test_zipapp test_zipfile test_zipfile64 test_zipimport test_zlib

[ ] test: cpython/Lib/test/test_unpack.py (TODO: 8)
[ ] test: cpython/Lib/test/test_unpack_ex.py (TODO: 11)

dependencies:

dependent tests: (no tests depend on unpack)

[x] lib: cpython/Lib/warnings.py
[x] lib: cpython/Lib/_py_warnings.py
[ ] test: cpython/Lib/test/test_warnings (TODO: 13)

dependencies:

  • warnings

dependent tests: (49 tests)

  • warnings: test_argparse test_array test_asyncio test_buffer test_builtin test_codecs test_codeop test_coroutines test_ctypes test_decimal test_descr test_fnmatch test_fstring test_funcattrs test_genericpath test_glob test_global test_grammar test_gzip test_hashlib test_hmac test_importlib test_inspect test_io test_logging test_ntpath test_os test_pickle test_posix test_pty test_pyclbr test_random test_re test_runpy test_set test_socket test_sqlite3 test_str test_string_literals test_support test_sys test_tempfile test_threading test_typing test_unicode_file_functions test_unittest test_unparse test_xml_etree test_zipimport

[x] test: cpython/Lib/test/test_winsound.py

dependencies:

dependent tests: (no tests depend on winsound)

Legend:

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

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