Skip to content

Commit

Permalink
ExceptionTrap now presents .type, .value, and .tb attributes, matchin…
Browse files Browse the repository at this point in the history
…g those found in a pytest ExceptionInfo.
  • Loading branch information
jaraco committed Nov 8, 2018
1 parent b1e9d4b commit 193b5a6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

* Dropped support for Python 3.3.
* Refreshed project metadata using declarative config.
* ``ExceptionTrap`` now presents ``type``, ``value``,
and ``tb`` attributes.

1.7
===
Expand Down
21 changes: 17 additions & 4 deletions jaraco/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,27 @@ def __init__(self, exceptions=(Exception,)):
def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, traceback):
matches = exc_type and issubclass(exc_type, self.exceptions)
@property
def type(self):
return self.exc_info[0]

@property
def value(self):
return self.exc_info[1]

@property
def tb(self):
return self.exc_info[2]

def __exit__(self, *exc_info):
type = exc_info[0]
matches = type and issubclass(type, self.exceptions)
if matches:
self.exc_info = exc_type, exc_val, traceback
self.exc_info = exc_info
return matches

def __bool__(self):
return bool(self.exc_info[0])
return bool(self.type)
__nonzero__ = __bool__


Expand Down

0 comments on commit 193b5a6

Please sign in to comment.