Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
[#145] Reformatted rest of iota package for PEP-8.
Browse files Browse the repository at this point in the history
  • Loading branch information
todofixthis committed Jun 15, 2018
1 parent 1dcad0a commit 1879c01
Show file tree
Hide file tree
Showing 5 changed files with 1,121 additions and 1,035 deletions.
41 changes: 26 additions & 15 deletions iota/exceptions.py
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
Loading

0 comments on commit 1879c01

Please sign in to comment.