Skip to content

Commit

Permalink
Add 'iex' convenience function as a decorator version of launch_ipdb_…
Browse files Browse the repository at this point in the history
…on_exception
  • Loading branch information
alanbernstein authored and gotcha committed May 26, 2021
1 parent 6694611 commit 11f7434
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ipdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Redistributable under the revised BSD license
# https://opensource.org/licenses/BSD-3-Clause

from ipdb.__main__ import set_trace, post_mortem, pm, run # noqa
from ipdb.__main__ import set_trace, post_mortem, pm, run, iex # noqa
from ipdb.__main__ import runcall, runeval, launch_ipdb_on_exception # noqa

from ipdb.stdout import sset_trace, spost_mortem, spm # noqa
Expand Down
23 changes: 23 additions & 0 deletions ipdb/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,29 @@ def launch_ipdb_on_exception():
pass


class Decontext(object):
"""
Makes a context manager also act as decorator.
"""
def __init__(self, context_manager):
self._cm = context_manager

def __enter__(self):
return self._cm.__enter__()

def __exit__(self, *args, **kwds):
return self._cm.__exit__(*args, **kwds)

def __call__(self, func):
def wrapper(*args, **kwds):
with self:
return func(*args, **kwds)
return wrapper


iex = Decontext(launch_ipdb_on_exception())


_usage = """\
usage: python -m ipdb [-m] [-c command] ... pyfile [arg] ...
Expand Down

0 comments on commit 11f7434

Please sign in to comment.