Skip to content

Commit 8ca56fd

Browse files
only monkeypatch reload in Python 3
1 parent c56439d commit 8ca56fd

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

bpython/curtsiesfrontend/sitefix.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def monkeypatch_quit():
2121
if 'site' in sys.modules:
2222
resetquit(builtins)
2323

24+
2425
orig_reload = None
2526
if py3:
2627
import importlib
@@ -31,27 +32,23 @@ def monkeypatch_quit():
3132
else:
3233
orig_reload = builtins.reload
3334

34-
if orig_reload:
35-
def reload(module):
36-
if module is sys:
37-
orig_stdout = sys.stdout
38-
orig_stderr = sys.stderr
39-
orig_stdin = sys.stdin
40-
r = orig_reload(sys)
41-
sys.stdout = orig_stdout
42-
sys.stderr = orig_stderr
43-
sys.stdin = orig_stdin
44-
return r
45-
else:
46-
return orig_reload(module)
4735

48-
functools.update_wrapper(reload, orig_reload)
36+
def reload(module):
37+
if module is sys:
38+
orig_stdout = sys.stdout
39+
orig_stderr = sys.stderr
40+
orig_stdin = sys.stdin
41+
r = orig_reload(sys)
42+
sys.stdout = orig_stdout
43+
sys.stderr = orig_stderr
44+
sys.stdin = orig_stdin
45+
return r
46+
else:
47+
return orig_reload(module)
48+
49+
functools.update_wrapper(reload, orig_reload)
4950

5051

5152
def monkeypatch_reload():
52-
if py3 and hasattr(importlib, 'reload'):
53-
importlib.reload = reload
54-
elif py3 and hasattr(imp, 'reload'):
55-
imp.reload = reload
56-
else:
53+
if not py3:
5754
builtins.reload = reload

0 commit comments

Comments
 (0)