]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43024: improve signature (in help, etc) for functions taking sent… (GH-24331)
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>
Thu, 17 Jun 2021 16:14:30 +0000 (17:14 +0100)
committerGitHub <noreply@github.com>
Thu, 17 Jun 2021 16:14:30 +0000 (09:14 -0700)
…inel defaults

Lib/test/test_traceback.py
Lib/traceback.py
Misc/NEWS.d/next/Library/2021-01-25-21-24-55.bpo-43024.vAUrIi.rst [new file with mode: 0644]

index e9df1ce9c79c0855bbf04653c1d0637a2f103f53..78b2851d3849423bfa4e507d1a6955fc79c06a73 100644 (file)
@@ -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=<implicit>, tb=<implicit>, '
+             'limit=None, file=None, chain=True)'))
+
+        self.assertEqual(
+            str(inspect.signature(traceback.format_exception)),
+            ('(exc, /, value=<implicit>, tb=<implicit>, limit=None, '
+             'chain=True)'))
+
+        self.assertEqual(
+            str(inspect.signature(traceback.format_exception_only)),
+            '(exc, /, value=<implicit>)')
+
 
 class TracebackFormatTests(unittest.TestCase):
 
index e19745df6def65485d2936cb59f8c42678677687..b4c7641addec773fff59aa6cff17cd178f332299 100644 (file)
@@ -84,8 +84,11 @@ _context_message = (
     "another exception occurred:\n\n")
 
 
-_sentinel = object()
+class _Sentinel:
+    def __repr__(self):
+        return "<implicit>"
 
+_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 (file)
index 0000000..56596ce
--- /dev/null
@@ -0,0 +1 @@
+Improve the help signature of :func:`traceback.print_exception`, :func:`traceback.format_exception` and :func:`traceback.format_exception_only`.