From 730fdc1f241753138a4f9adc7ebc471372c9f3ce Mon Sep 17 00:00:00 2001 From: ruang Date: Mon, 21 Oct 2024 18:27:01 +0800 Subject: [PATCH 1/3] Fix non-existent tracebacklimit attribute. --- Include/internal/pycore_traceback.h | 3 +++ Lib/test/test_sys.py | 3 +++ .../Library/2024-10-20-11-45-50.gh-issue-123596.HONVYS.rst | 1 + Python/sysmodule.c | 3 +++ Python/traceback.c | 2 -- 5 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2024-10-20-11-45-50.gh-issue-123596.HONVYS.rst diff --git a/Include/internal/pycore_traceback.h b/Include/internal/pycore_traceback.h index 10922bff98bd4b..82529ffec3c113 100644 --- a/Include/internal/pycore_traceback.h +++ b/Include/internal/pycore_traceback.h @@ -8,6 +8,9 @@ extern "C" { # error "this header requires Py_BUILD_CORE define" #endif +/* Maximum number of error tracebacks to print */ +#define PyTraceBack_LIMIT 1000 + // Export for '_ctypes' shared extension PyAPI_FUNC(int) _Py_DisplaySourceLine(PyObject *, PyObject *, int, int, int *, PyObject **); diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 9689ef8e96e072..fc1461cebddf45 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1187,6 +1187,9 @@ def check(tracebacklimit, expected): b' ~~^~~', b'ZeroDivisionError: division by zero' ] + self.assertTrue(hasattr(sys, "tracebacklimit"), + 'tracebacklimit attribute does not exist') + self.assertEqual(getattr(sys, 'tracebacklimit', 1_000), 1_000) check(10, traceback) check(3, traceback) check(2, traceback[:1] + traceback[4:]) diff --git a/Misc/NEWS.d/next/Library/2024-10-20-11-45-50.gh-issue-123596.HONVYS.rst b/Misc/NEWS.d/next/Library/2024-10-20-11-45-50.gh-issue-123596.HONVYS.rst new file mode 100644 index 00000000000000..da7f815d835973 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-10-20-11-45-50.gh-issue-123596.HONVYS.rst @@ -0,0 +1 @@ +Fix non-existent :attr:`sys.tracebacklimit` in :mod:`sys`. Patch by RUANG. diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 8b9209324002ce..3d0953480a6c2c 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -35,6 +35,7 @@ Data members: #include "pycore_structseq.h" // _PyStructSequence_InitBuiltinWithFlags() #include "pycore_sysmodule.h" // export _PySys_GetSizeOf() #include "pycore_tuple.h" // _PyTuple_FromArray() +#include "pycore_traceback.h" // PyTraceBack_LIMIT #include "pydtrace.h" // PyDTrace_AUDIT() #include "osdefs.h" // DELIM @@ -3666,6 +3667,8 @@ _PySys_UpdateConfig(PyThreadState *tstate) COPY_LIST("path", config->module_search_paths); } + SET_SYS("tracebacklimit", PyLong_FromLong(PyTraceBack_LIMIT)); + COPY_WSTR("executable", config->executable); COPY_WSTR("_base_executable", config->base_executable); COPY_WSTR("prefix", config->prefix); diff --git a/Python/traceback.c b/Python/traceback.c index 47b77c9108dd9a..69836d0a5bb379 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -704,8 +704,6 @@ tb_printinternal(PyTracebackObject *tb, PyObject *f, long limit) return -1; } -#define PyTraceBack_LIMIT 1000 - int _PyTraceBack_Print(PyObject *v, const char *header, PyObject *f) { From 9a324f4e1d6ee601335c0be45609bb59c8afd03f Mon Sep 17 00:00:00 2001 From: "RUANG (Roy James)" Date: Tue, 22 Oct 2024 16:53:52 +0800 Subject: [PATCH 2/3] Change NEWS --- .../next/Library/2024-10-20-11-45-50.gh-issue-123596.HONVYS.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2024-10-20-11-45-50.gh-issue-123596.HONVYS.rst b/Misc/NEWS.d/next/Library/2024-10-20-11-45-50.gh-issue-123596.HONVYS.rst index da7f815d835973..1d4444e6038a14 100644 --- a/Misc/NEWS.d/next/Library/2024-10-20-11-45-50.gh-issue-123596.HONVYS.rst +++ b/Misc/NEWS.d/next/Library/2024-10-20-11-45-50.gh-issue-123596.HONVYS.rst @@ -1 +1 @@ -Fix non-existent :attr:`sys.tracebacklimit` in :mod:`sys`. Patch by RUANG. +Fix missing :attr:`sys.tracebacklimit` in :mod:`sys`. Patch by RUANG. From 4f2c585917de5881a90962a9deca6770cd5e2aec Mon Sep 17 00:00:00 2001 From: "RUANG (Roy James)" Date: Tue, 22 Oct 2024 16:54:47 +0800 Subject: [PATCH 3/3] Change test --- Lib/test/test_sys.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index fc1461cebddf45..bdb3c1db287168 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1189,7 +1189,7 @@ def check(tracebacklimit, expected): ] self.assertTrue(hasattr(sys, "tracebacklimit"), 'tracebacklimit attribute does not exist') - self.assertEqual(getattr(sys, 'tracebacklimit', 1_000), 1_000) + self.assertEqual(sys.tracebacklimit, 1_000) check(10, traceback) check(3, traceback) check(2, traceback[:1] + traceback[4:])