Skip to content

Commit 730fdc1

Browse files
committed
Fix non-existent tracebacklimit attribute.
1 parent 9256be7 commit 730fdc1

File tree

5 files changed

+10
-2
lines changed

5 files changed

+10
-2
lines changed

Include/internal/pycore_traceback.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11+
/* Maximum number of error tracebacks to print */
12+
#define PyTraceBack_LIMIT 1000
13+
1114
// Export for '_ctypes' shared extension
1215
PyAPI_FUNC(int) _Py_DisplaySourceLine(PyObject *, PyObject *, int, int, int *, PyObject **);
1316

Lib/test/test_sys.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,9 @@ def check(tracebacklimit, expected):
11871187
b' ~~^~~',
11881188
b'ZeroDivisionError: division by zero'
11891189
]
1190+
self.assertTrue(hasattr(sys, "tracebacklimit"),
1191+
'tracebacklimit attribute does not exist')
1192+
self.assertEqual(getattr(sys, 'tracebacklimit', 1_000), 1_000)
11901193
check(10, traceback)
11911194
check(3, traceback)
11921195
check(2, traceback[:1] + traceback[4:])
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix non-existent :attr:`sys.tracebacklimit` in :mod:`sys`. Patch by RUANG.

Python/sysmodule.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Data members:
3535
#include "pycore_structseq.h" // _PyStructSequence_InitBuiltinWithFlags()
3636
#include "pycore_sysmodule.h" // export _PySys_GetSizeOf()
3737
#include "pycore_tuple.h" // _PyTuple_FromArray()
38+
#include "pycore_traceback.h" // PyTraceBack_LIMIT
3839

3940
#include "pydtrace.h" // PyDTrace_AUDIT()
4041
#include "osdefs.h" // DELIM
@@ -3666,6 +3667,8 @@ _PySys_UpdateConfig(PyThreadState *tstate)
36663667
COPY_LIST("path", config->module_search_paths);
36673668
}
36683669

3670+
SET_SYS("tracebacklimit", PyLong_FromLong(PyTraceBack_LIMIT));
3671+
36693672
COPY_WSTR("executable", config->executable);
36703673
COPY_WSTR("_base_executable", config->base_executable);
36713674
COPY_WSTR("prefix", config->prefix);

Python/traceback.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,8 +704,6 @@ tb_printinternal(PyTracebackObject *tb, PyObject *f, long limit)
704704
return -1;
705705
}
706706

707-
#define PyTraceBack_LIMIT 1000
708-
709707
int
710708
_PyTraceBack_Print(PyObject *v, const char *header, PyObject *f)
711709
{

0 commit comments

Comments
 (0)