This repository has been archived by the owner on Jan 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#145] Reformatted rest of
iota
package for PEP-8.
- Loading branch information
1 parent
1dcad0a
commit 1879c01
Showing
5 changed files
with
1,121 additions
and
1,035 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,36 @@ | ||
# coding=utf-8 | ||
from __future__ import absolute_import, division, print_function, \ | ||
unicode_literals | ||
unicode_literals | ||
|
||
__all__ = [ | ||
'with_context', | ||
] | ||
|
||
|
||
def with_context(exc, context): | ||
# type: (Exception, dict) -> Exception | ||
""" | ||
Attaches a ``context`` value to an Exception. | ||
# type: (Exception, dict) -> Exception | ||
""" | ||
Attaches a ``context`` value to an Exception. | ||
Before: | ||
.. code-block:: python | ||
Before:: | ||
exc = Exception('Frog blast the vent core!') | ||
exc.context = { ... } | ||
raise exc | ||
exc = Exception('Frog blast the vent core!') | ||
exc.context = { ... } | ||
raise exc | ||
After: | ||
After:: | ||
.. code-block:: python | ||
raise with_context(Exception('Frog blast the vent core!'), { ... }) | ||
""" | ||
if not hasattr(exc, 'context'): | ||
exc.context = {} | ||
raise with_context( | ||
exc=Exception('Frog blast the vent core!'), | ||
context={ ... }, | ||
) | ||
""" | ||
if not hasattr(exc, 'context'): | ||
exc.context = {} | ||
|
||
exc.context.update(context) | ||
return exc | ||
exc.context.update(context) | ||
return exc |
Oops, something went wrong.