Skip to content

Commit b448047

Browse files
committed
Second attempt at making b0efd741dfd7 compatible with Python 2.5.
1 parent 84c4f1d commit b448047

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

bpython/importcompletion.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@
2626
import os
2727
import sys
2828
import warnings
29+
try:
30+
from warnings import catch_warnings
31+
except ImportError:
32+
import contextlib
33+
@contextlib.contextmanager
34+
def catch_warnings():
35+
"""Stripped-down version of `warnings.catch_warnings()`
36+
(available in Py >= 2.6)."""
37+
filters = warnings.filters
38+
warnings.filters = list(filters)
39+
try:
40+
yield
41+
finally:
42+
warnings.filters = filters
2943

3044
py3 = sys.version_info[:2] >= (3, 0)
3145

@@ -107,7 +121,7 @@ def find_modules(path):
107121
continue
108122
name = os.path.splitext(name)[0]
109123
try:
110-
with warnings.catch_warnings():
124+
with catch_warnings():
111125
warnings.simplefilter("ignore", ImportWarning)
112126
fo, pathname, _ = imp.find_module(name, [path])
113127
except (ImportError, SyntaxError):

0 commit comments

Comments
 (0)