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 f6b2aeb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 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
22 changes: 16 additions & 6 deletions jaraco/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,24 @@ 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)
if matches:
self.exc_info = exc_type, exc_val, traceback
return matches
@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):
self.exc_info = exc_info
return self.type and issubclass(self.type, self.exceptions)

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


Expand Down

0 comments on commit f6b2aeb

Please sign in to comment.