Skip to content
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

Allow arbitrary keyword arguments in several functions and methods #135

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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