From e855ca61f87427e5a47ef74e120d1e0fbc1ddd02 Mon Sep 17 00:00:00 2001 From: Christopher Rowley Date: Thu, 4 Jun 2026 09:33:24 +0100 Subject: [PATCH] remove auto-sys-last-traceback functionality --- CHANGELOG.md | 2 ++ docs/src/compat.md | 4 ---- docs/src/faq.md | 6 ++++++ docs/src/v1-migration-guide.md | 6 ++++++ src/Core/config.jl | 1 - src/Core/err.jl | 11 ----------- 6 files changed, 14 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc221b66..09c528ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ * Comparisons like `==`, `<` and `isless` between `Py`s now return `Bool` instead of `Py`. * Removed comparisons between `Py` and `Number` (like `Py(3) < 5`). * Removed arithmetic between `Py` and `Number` (like `Py(2) * 10`). + * Python errors no longer automatically set `sys.last_traceback` etc. when displayed from Julia. + * Removed `CONFIG.auto_sys_last_traceback`. * Changes to `PythonCall.GC` (now more like `Base.GC`): * `enable(true)` replaces `enable()`. * `enable(false)` replaces `disable()`. diff --git a/docs/src/compat.md b/docs/src/compat.md index 7f859c13..7ed44491 100644 --- a/docs/src/compat.md +++ b/docs/src/compat.md @@ -5,10 +5,6 @@ Some packages require a little extra help to work nicely with PythonCall. Some of these are "fixes" that are silently applied for you, and some are just extra functions to bridge a gap. We aim to keep these as minimal as possible. -## Python standard library - -Whenever a Python exception is displayed by Julia, `sys.last_traceback` and friends are set. This allows the post-mortem debugger `pdb.pm()` to work. Disable by setting `PythonCall.CONFIG.auto_sys_last_traceback = false`. - ## Julia standard library Python objects can be serialised with the [`Serialization`](https://docs.julialang.org/en/v1/stdlib/Serialization/) stdlib. diff --git a/docs/src/faq.md b/docs/src/faq.md index fd9f2260..260f980f 100644 --- a/docs/src/faq.md +++ b/docs/src/faq.md @@ -116,3 +116,9 @@ Each release of PythonCall and JuliaCall will support and require: - The current Julia LTS version and newer, [see here](https://julialang.org/downloads/#long_term_support_release). Currently 1.10+. Only the latest patch release within each minor version is supported. + +## Can I use the Python debugger `pdb` from Julia? + +Yes! If you are used to using the post-mortem debugger `pdb.pm()` in Python, then you +can instead use `pdb.post_mortem(err[1].exception)` at the Julia REPL to debug the +most recent Python error (a [`PyException`](@ref)). diff --git a/docs/src/v1-migration-guide.md b/docs/src/v1-migration-guide.md index e62926b6..7fa2cc09 100644 --- a/docs/src/v1-migration-guide.md +++ b/docs/src/v1-migration-guide.md @@ -24,6 +24,12 @@ between Python and Julia is explicit. * Instead of `Py(5) * 6` use `Py(5) * Py(6)` or `pymul(Py(5), 6)`. * Instead of `np.array([1,2,3]) < 3` use `pylt(np.array([1,2,3]), 3)`. +When a Python error is displayed in Julia, PythonCall no longer sets `sys.last_traceback` +and friends. This means that the Python post-mortem debugger `pdb.pm()` will no longer +work. + +* Instead of `pdb.pm()` use `pdb.post_mortem(err[1].exception)`. + ## `PythonCall.GC` This submodule has been changed to closer mimic the `Base.GC` API. diff --git a/src/Core/config.jl b/src/Core/config.jl index 55154cd3..967bd33e 100644 --- a/src/Core/config.jl +++ b/src/Core/config.jl @@ -1,6 +1,5 @@ @kwdef mutable struct Config meta::String = "" - auto_sys_last_traceback::Bool = true auto_fix_qt_plugin_path::Bool = true end diff --git a/src/Core/err.jl b/src/Core/err.jl index d6431237..4ee00c74 100644 --- a/src/Core/err.jl +++ b/src/Core/err.jl @@ -105,17 +105,6 @@ function _showerror(io::IO, e::PyException, bt; backtrace = true) return end - if CONFIG.auto_sys_last_traceback - try - sys = pyimport("sys") - sys.last_type = e.t - sys.last_value = e.v - sys.last_traceback = e.b - catch err - print(io, "") - end - end - if !pyisnull(pyJuliaError) && pyissubclass(e.t, pyJuliaError) # handle Julia exceptions specially try