8000 bpo-43024: improve signature (in help, etc) for functions taking sent… by iritkatriel · Pull Request #24331 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-43024: improve signature (in help, etc) for functions taking sent… #24331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations 8000
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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