From f73377d57c5272390de63cccc3c292c44689310a Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Thu, 17 Jun 2021 17:14:30 +0100 Subject: [PATCH] =?UTF-8?q?bpo-43024:=20improve=20signature=20(in=20help,?= =?UTF-8?q?=20etc)=20for=20functions=20taking=20sent=E2=80=A6=20(GH-24331)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …inel defaults --- Lib/test/test_traceback.py | 16 ++++++++++++++++ Lib/traceback.py | 5 ++++- .../2021-01-25-21-24-55.bpo-43024.vAUrIi.rst | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2021-01-25-21-24-55.bpo-43024.vAUrIi.rst diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index e9df1ce9c79..78b2851d384 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -4,6 +4,7 @@ from collections import namedtuple from io import StringIO import linecache import sys +import inspect import unittest import re from test import support @@ -255,6 +256,21 @@ class TracebackCases(unittest.TestCase): self.assertEqual( traceback.format_exception_only(None, None), [NONE_EXC_STRING]) + def test_signatures(self): + self.assertEqual( + str(inspect.signature(traceback.print_exception)), + ('(exc, /, value=, tb=, ' + 'limit=None, file=None, chain=True)')) + + self.assertEqual( + str(inspect.signature(traceback.format_exception)), + ('(exc, /, value=, tb=, limit=None, ' + 'chain=True)')) + + self.assertEqual( + str(inspect.signature(traceback.format_exception_only)), + '(exc, /, value=)') + class TracebackFormatTests(unittest.TestCase): diff --git a/Lib/traceback.py b/Lib/traceback.py index e19745df6de..b4c7641adde 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -84,8 +84,11 @@ _context_message = ( "another exception occurred:\n\n") -_sentinel = object() +class _Sentinel: + def __repr__(self): + return "" +_sentinel = _Sentinel() def _parse_value_tb(exc, value, tb): if (value is _sentinel) != (tb is _sentinel): diff --git a/Misc/NEWS.d/next/Library/2021-01-25-21-24-55.bpo-43024.vAUrIi.rst b/Misc/NEWS.d/next/Library/2021-01-25-21-24-55.bpo-43024.vAUrIi.rst new file mode 100644 index 00000000000..56596ce3c2a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-01-25-21-24-55.bpo-43024.vAUrIi.rst @@ -0,0 +1 @@ +Improve the help signature of :func:`traceback.print_exception`, :func:`traceback.format_exception` and :func:`traceback.format_exception_only`.