[Python-checkins] bpo-43024: improve signature (in help, etc) for functions taking sent… (GH-24331)
miss-islington
webhook-mailer at python.org
Thu Jun 17 12:14:38 EDT 2021
https://github.com/python/cpython/commit/f73377d57c5272390de63cccc3c292c44689310a
commit: f73377d57c5272390de63cccc3c292c44689310a
branch: main
author: Irit Katriel <1055913+iritkatriel at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2021-06-17T09:14:30-07:00
summary:
bpo-43024: improve signature (in help, etc) for functions taking sent… (GH-24331)
…inel defaults
files:
A Misc/NEWS.d/next/Library/2021-01-25-21-24-55.bpo-43024.vAUrIi.rst
M Lib/test/test_traceback.py
M Lib/traceback.py
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
index e9df1ce9c79c0..78b2851d38494 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -4,6 +4,7 @@
from io import StringIO
import linecache
import sys
+import inspect
import unittest
import re
from test import support
@@ -255,6 +256,21 @@ def test_exception_is_None(self):
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):
diff --git a/Lib/traceback.py b/Lib/traceback.py
index e19745df6def6..b4c7641addec7 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -84,8 +84,11 @@ def extract_tb(tb, limit=None):
"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
index 0000000000000..56596ce3c2a97
--- /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`.
More information about the Python-checkins
mailing list