From 6a06b7627bcdd285418a460acdeab9f31615d3b2 Mon Sep 17 00:00:00 2001 From: Tomas R Date: Tue, 3 Dec 2024 17:08:39 +0100 Subject: [PATCH 1/3] gh-127347: Document `traceback.print_list` (GH-127348) Previously, `traceback.print_list` didn't have a documentation entry and was not exposed in `traceback.__all__`. Now it has a documentation entry and is exposed in `__all__`. (cherry picked from commit 8ba9f5bca9c0ce6130e1f4ba761a68f74f8457d0) Co-authored-by: Tomas R. --- Doc/library/traceback.rst | 7 +++++++ Lib/test/test_traceback.py | 3 +-- Lib/traceback.py | 2 +- .../2024-11-27-22-56-48.gh-issue-127347.xyddWS.rst | 1 + 4 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Documentation/2024-11-27-22-56-48.gh-issue-127347.xyddWS.rst diff --git a/Doc/library/traceback.rst b/Doc/library/traceback.rst index 9d57c354523370..07960e4b1042d4 100644 --- a/Doc/library/traceback.rst +++ b/Doc/library/traceback.rst @@ -157,6 +157,13 @@ Module-Level Functions arguments have the same meaning as for :func:`print_stack`. +.. function:: print_list(extracted_list, file=None) + + Print the list of tuples as returned by :func:`extract_tb` or + :func:`extract_stack` as a formatted stack trace to the given file. + If *file* is ``None``, the output is written to :data:`sys.stderr`. + + .. function:: format_list(extracted_list) Given a list of tuples or :class:`FrameSummary` objects as returned by diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 119143e4f3a009..0b0ef1d3394d0e 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -3612,9 +3612,8 @@ class MiscTest(unittest.TestCase): def test_all(self): expected = set() - denylist = {'print_list'} for name in dir(traceback): - if name.startswith('_') or name in denylist: + if name.startswith('_'): continue module_object = getattr(traceback, name) if getattr(module_object, '__module__', None) == 'traceback': diff --git a/Lib/traceback.py b/Lib/traceback.py index 8247d8ff8cd1e7..3f23797b2bb41b 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -12,7 +12,7 @@ 'format_tb', 'print_exc', 'format_exc', 'print_exception', 'print_last', 'print_stack', 'print_tb', 'clear_frames', 'FrameSummary', 'StackSummary', 'TracebackException', - 'walk_stack', 'walk_tb'] + 'walk_stack', 'walk_tb', 'print_list'] # # Formatting and printing lists of traceback lines. diff --git a/Misc/NEWS.d/next/Documentation/2024-11-27-22-56-48.gh-issue-127347.xyddWS.rst b/Misc/NEWS.d/next/Documentation/2024-11-27-22-56-48.gh-issue-127347.xyddWS.rst new file mode 100644 index 00000000000000..79b3faa3d0d385 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2024-11-27-22-56-48.gh-issue-127347.xyddWS.rst @@ -0,0 +1 @@ +Publicly expose :func:`traceback.print_list` in :attr:`!traceback.__all__`. From c6abcad4cbc03100efa46d164ef08467b01a1126 Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Tue, 3 Dec 2024 22:53:26 +0100 Subject: [PATCH 2/3] Remove news entry --- .../Documentation/2024-11-27-22-56-48.gh-issue-127347.xyddWS.rst | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Misc/NEWS.d/next/Documentation/2024-11-27-22-56-48.gh-issue-127347.xyddWS.rst diff --git a/Misc/NEWS.d/next/Documentation/2024-11-27-22-56-48.gh-issue-127347.xyddWS.rst b/Misc/NEWS.d/next/Documentation/2024-11-27-22-56-48.gh-issue-127347.xyddWS.rst deleted file mode 100644 index 79b3faa3d0d385..00000000000000 --- a/Misc/NEWS.d/next/Documentation/2024-11-27-22-56-48.gh-issue-127347.xyddWS.rst +++ /dev/null @@ -1 +0,0 @@ -Publicly expose :func:`traceback.print_list` in :attr:`!traceback.__all__`. From c369b01d8fb6ea19b0edf7b606250dce27e2003c Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Tue, 3 Dec 2024 22:55:07 +0100 Subject: [PATCH 3/3] Remove print_list from __all__ --- Lib/test/test_traceback.py | 3 ++- Lib/traceback.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 0b0ef1d3394d0e..119143e4f3a009 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -3612,8 +3612,9 @@ class MiscTest(unittest.TestCase): def test_all(self): expected = set() + denylist = {'print_list'} for name in dir(traceback): - if name.startswith('_'): + if name.startswith('_') or name in denylist: continue module_object = getattr(traceback, name) if getattr(module_object, '__module__', None) == 'traceback': diff --git a/Lib/traceback.py b/Lib/traceback.py index 3f23797b2bb41b..8247d8ff8cd1e7 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -12,7 +12,7 @@ 'format_tb', 'print_exc', 'format_exc', 'print_exception', 'print_last', 'print_stack', 'print_tb', 'clear_frames', 'FrameSummary', 'StackSummary', 'TracebackException', - 'walk_stack', 'walk_tb', 'print_list'] + 'walk_stack', 'walk_tb'] # # Formatting and printing lists of traceback lines.