Skip to content

Commit

Permalink
Replace Decontext and contextlib.contextmanager with decorator.contex…
Browse files Browse the repository at this point in the history
…tmanager
  • Loading branch information
alanbernstein authored and gotcha committed May 26, 2021
1 parent 8f61f21 commit df4ae3d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
25 changes: 3 additions & 22 deletions ipdb/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os
import sys

from contextlib import contextmanager
from decorator import contextmanager

__version__ = '0.13.8.dev0'

Expand Down Expand Up @@ -228,27 +228,8 @@ 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())
# iex is a concise alias
iex = launch_ipdb_on_exception()


_usage = """\
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
'toml >= 0.10.2'
],
# No support for python 3.0, 3.1, 3.2.
# decorator is also a dependency of Ipython.
':python_version == "3.4"': ['ipython >= 6.0.0, < 7.0.0', 'toml >= 0.10.2', 'decorator < 5.0.0'],
':python_version == "3.5"': ['ipython >= 7.0.0, < 7.10.0', 'toml >= 0.10.2'],
':python_version == "3.6"': ['ipython >= 7.10.0, < 7.17.0', 'toml >= 0.10.2'],
Expand Down

0 comments on commit df4ae3d

Please sign in to comment.