Skip to content

Commit 58b8b95

Browse files
committed
In Pdb, stop assigning values to __builtin__._ which interferes with the one commonly installed by gettext.
1 parent 3864459 commit 58b8b95

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

Lib/pdb.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ def interaction(self, frame, traceback):
194194
self.cmdloop()
195195
self.forget()
196196

197+
def displayhook(self, obj):
198+
"""Custom displayhook for the exec in default(), which prevents
199+
assignment of the _ variable in the builtins.
200+
"""
201+
print obj
202+
197203
def default(self, line):
198204
if line[:1] == '!': line = line[1:]
199205
locals = self.curframe.f_locals
@@ -202,13 +208,16 @@ def default(self, line):
202208
code = compile(line + '\n', '<stdin>', 'single')
203209
save_stdout = sys.stdout
204210
save_stdin = sys.stdin
211+
save_displayhook = sys.displayhook
205212
try:
206213
sys.stdin = self.stdin
207214
sys.stdout = self.stdout
215+
sys.displayhook = self.displayhook
208216
exec code in globals, locals
209217
finally:
210218
sys.stdout = save_stdout
211219
sys.stdin = save_stdin
220+
sys.displayhook = save_displayhook
212221
except:
213222
t, v = sys.exc_info()[:2]
214223
if type(t) == type(''):

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ Core and Builtins
202202
Library
203203
-------
204204

205+
- In Pdb, prevent the reassignment of __builtin__._ by sys.displayhook on
206+
printing out values.
207+
205208
- Issue #4572: added SEEK_* symbolic constants to io module.
206209

207210
- Issue #1665206 (partially): Move imports in cgitb to the top of the module

0 commit comments

Comments
 (0)