Skip to content

Commit

Permalink
bpo-43024: improve signature (in help, etc) for functions taking sent… (
Browse files Browse the repository at this point in the history
GH-24331)

…inel defaults
  • Loading branch information
iritkatriel authored Jun 17, 2021
1 parent ba2f32a commit f73377d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
16 changes: 16 additions & 0 deletions Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from io import StringIO
import linecache
import sys
import inspect
import unittest
import re
from test import support
Expand Down Expand Up @@ -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):

Expand Down
5 changes: 4 additions & 1 deletion Lib/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve the help signature of :func:`traceback.print_exception`, :func:`traceback.format_exception` and :func:`traceback.format_exception_only`.

0 comments on commit f73377d

Please sign in to comment.