Skip to content

Commit b5dac4d

Browse files
thomasballingermlauter
authored andcommitted
Incorporate new interpreter class into the main repl and use our write traceback method to send to standard error.
1 parent 8edeadc commit b5dac4d

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

bpython/curtsiesfrontend/interpreter.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
Name.Class:'d',
3030
}
3131

32-
3332
class BPythonFormatter(Formatter):
3433
"""This is subclassed from the custom formatter for bpython.
3534
Its format() method receives the tokensource
@@ -58,7 +57,7 @@ def format(self, tokensource, outfile):
5857
outfile.write(str(parse(o.rstrip())))
5958

6059
class Interp(code.InteractiveInterpreter):
61-
def __init__(self, locals=None, outfile=sys.__stderr__):
60+
def __init__(self, locals=None):
6261
"""Constructor.
6362
6463
The optional 'locals' argument specifies the dictionary in
@@ -73,7 +72,10 @@ def __init__(self, locals=None, outfile=sys.__stderr__):
7372
locals = {"__name__": "__console__", "__doc__": None}
7473
self.locals = locals
7574
self.compile = CommandCompiler()
76-
self.outfile = outfile
75+
76+
# typically changed after being instantiated
77+
self.write = lambda stuff: sys.stderr.write(stuff)
78+
self.outfile = self
7779

7880
def showsyntaxerror(self, filename=None):
7981
"""Display the syntax error that just occurred.
@@ -113,10 +115,10 @@ def showsyntaxerror(self, filename=None):
113115
if text.endswith('\n'):
114116
cur_line.append((token,text))
115117
if no_format_mode:
116-
traceback_code_formatter.format(cur_line,self.outfile)
118+
traceback_code_formatter.format(cur_line, self.outfile)
117119
no_format_mode = False
118120
else:
119-
traceback_informative_formatter.format(cur_line,self.outfile)
121+
traceback_informative_formatter.format(cur_line, self.outfile)
120122
cur_line = []
121123
elif text == ' ' and cur_line == []:
122124
no_format_mode = True
@@ -154,10 +156,10 @@ def showtraceback(self):
154156
if text.endswith('\n'):
155157
cur_line.append((token,text))
156158
if no_format_mode:
157-
traceback_code_formatter.format(cur_line,self.outfile)
159+
traceback_code_formatter.format(cur_line, self.outfile)
158160
no_format_mode = False
159161
else:
160-
traceback_informative_formatter.format(cur_line,self.outfile)
162+
traceback_informative_formatter.format(cur_line, self.outfile)
161163
cur_line = []
162164
elif text == ' ' and cur_line == []:
163165
no_format_mode = True

bpython/curtsiesfrontend/repl.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ def __init__(self,
239239
# state was passed in
240240
if interp is None:
241241
interp = Interp(locals=locals_)
242+
interp.writetb = self.send_to_stderr
242243
if banner is None:
243244
banner = _('Welcome to bpython! Press <%s> for help.') % config.help_key
244245
config.autocomplete_mode = autocomplete.SIMPLE # only one implemented currently
@@ -1107,6 +1108,7 @@ def reevaluate(self, insert_into_history=False):
11071108

11081109
if not self.weak_rewind:
11091110
self.interp = self.interp.__class__()
1111+
self.interp.writetb = self.send_to_stderr
11101112
self.coderunner.interp = self.interp
11111113

11121114
self.buffer = []

0 commit comments

Comments
 (0)