8000 bpo-43024: improve signature (in help, etc) for functions taking sent… · python/cpython@f73377d · GitHub
[go: up one dir, main page]

Skip to content

Commit f73377d

Browse files
authored
bpo-43024: improve signature (in help, etc) for functions taking sent… (GH-24331)
…inel defaults
1 parent ba2f32a commit f73377d

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

Lib/test/test_traceback.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from io import StringIO
55
import linecache
66
import sys
7+
import inspect
78
import unittest
89
import re
910
from test import support
@@ -255,6 +256,21 @@ def test_exception_is_None(self):
255256
self.assertEqual(
256257
traceback.format_exception_only(None, None), [NONE_EXC_STRING])
257258

259+
def test_signatures(self):
260+
self.assertEqual(
261+
str(inspect.signature(traceback.print_exception)),
262+
('(exc, /, value=<implicit>, tb=<implicit>, '
263+
'limit=None, file=None, chain=True)'))
264+
265+
self.assertEqual(
266+
str(inspect.signature(traceback.format_exception)),
267+
('(exc, /, value=<implicit>, tb=<implicit>, limit=None, '
268+
'chain=True)'))
269+
270+
self.assertEqual(
271+
str(inspect.signature(traceback.format_exception_only)),
272+
'(exc, /, value=<implicit>)')
273+
258274

259275
class TracebackFormatTests(unittest.TestCase):
260276

Lib/traceback.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,11 @@ def extract_tb(tb, limit=None):
8484
"another exception occurred:\n\n")
8585

8686

87-
_sentinel = object()
87+
class _Sentinel:
88+
def __repr__(self):
89+
return "<implicit>"
8890

91+
_sentinel = _Sentinel()
8992

9093
def _parse_value_tb(exc, value, tb):
9194
if (value is _sentinel) != (tb is _sentinel):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve the help signature of :func:`traceback.print_exception`, :func:`traceback.format_exception` and :func:`traceback.format_exception_only`.

0 commit comments

Comments
 (0)
0