From 0374b5837821d7ee095dfc6d4c5f6e53e03a36aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Tue, 10 Sep 2024 01:37:48 +0300 Subject: [PATCH] Allow arbitrary keyword arguments in several functions and methods This changes the signatures to match their standard library counterparts. Fixes #133. --- CHANGES.rst | 5 +++++ src/exceptiongroup/_formatting.py | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index a9c19c5..9b3dcd6 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -3,6 +3,11 @@ Version history This library adheres to `Semantic Versioning 2.0 `_. +**UNRELEASED** + +- Added ``**kwargs`` to function and method signatures as appropriate to match the + signatures in the standard library + **1.2.2** - Removed an ``assert`` in ``exceptiongroup._formatting`` that caused compatibility diff --git a/src/exceptiongroup/_formatting.py b/src/exceptiongroup/_formatting.py index 4c52d77..c383c50 100644 --- a/src/exceptiongroup/_formatting.py +++ b/src/exceptiongroup/_formatting.py @@ -215,7 +215,7 @@ def __init__( if exceptions: queue.extend(zip(te.exceptions, e.exceptions)) - def format(self, *, chain=True, _ctx=None): + def format(self, *, chain=True, _ctx=None, **kwargs): if _ctx is None: _ctx = _ExceptionPrintContext() @@ -304,7 +304,7 @@ def format(self, *, chain=True, _ctx=None): assert _ctx.exception_group_depth == 1 _ctx.exception_group_depth = 0 - def format_exception_only(self): + def format_exception_only(self, **kwargs): """Format the exception part of the traceback. The return value is a generator of strings, each ending in a newline. Normally, the generator emits a single string; however, for @@ -399,7 +399,7 @@ def format_exception_only(self): @singledispatch -def format_exception_only(__exc: BaseException) -> List[str]: +def format_exception_only(__exc: BaseException, **kwargs: Any) -> List[str]: return list( PatchedTracebackException( type(__exc), __exc, None, compact=True @@ -408,15 +408,13 @@ def format_exception_only(__exc: BaseException) -> List[str]: @format_exception_only.register -def _(__exc: type, value: BaseException) -> List[str]: +def _(__exc: type, value: BaseException, **kwargs: Any) -> List[str]: return format_exception_only(value) @singledispatch def format_exception( - __exc: BaseException, - limit: Optional[int] = None, - chain: bool = True, + __exc: BaseException, limit: Optional[int] = None, chain: bool = True, **kwargs: Any ) -> List[str]: return list( PatchedTracebackException( @@ -432,6 +430,7 @@ def _( tb: TracebackType, limit: Optional[int] = None, chain: bool = True, + **kwargs: Any, ) -> List[str]: return format_exception(value, limit, chain) @@ -442,6 +441,7 @@ def print_exception( limit: Optional[int] = None, file: Any = None, chain: bool = True, + **kwargs: Any, ) -> None: if file is None: file = sys.stderr