Skip to content

Commit

Permalink
Allow arbitrary keyword arguments in several functions and methods
Browse files Browse the repository at this point in the history
This changes the signatures to match their standard library counterparts.

Fixes #133.
  • Loading branch information
agronholm committed Sep 9, 2024
1 parent fdf48e0 commit 0374b58
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ Version history

This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.

**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
Expand Down
14 changes: 7 additions & 7 deletions src/exceptiongroup/_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -432,6 +430,7 @@ def _(
tb: TracebackType,
limit: Optional[int] = None,
chain: bool = True,
**kwargs: Any,
) -> List[str]:
return format_exception(value, limit, chain)

Expand All @@ -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
Expand Down

0 comments on commit 0374b58

Please # to comment.