Skip to content

Commit a808521

Browse files
committed
Remove no longer used encoding
1 parent 069a0a6 commit a808521

File tree

5 files changed

+16
-46
lines changed

5 files changed

+16
-46
lines changed

bpython/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2005,7 +2005,7 @@ def main_curses(
20052005
curses.raw(True)
20062006
main_win, statusbar = init_wins(scr, config)
20072007

2008-
interpreter = repl.Interpreter(locals_, getpreferredencoding())
2008+
interpreter = repl.Interpreter(locals_)
20092009

20102010
clirepl = CLIRepl(main_win, interpreter, statusbar, config, idle)
20112011
clirepl._C = cols

bpython/curtsiesfrontend/interpreter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,13 @@ class Interp(ReplInterpreter):
6363
def __init__(
6464
self,
6565
locals: Optional[Dict[str, Any]] = None,
66-
encoding: Optional[str] = None,
6766
) -> None:
6867
"""Constructor.
6968
7069
We include an argument for the outfile to pass to the formatter for it
7170
to write to.
7271
"""
73-
super().__init__(locals, encoding)
72+
super().__init__(locals)
7473

7574
# typically changed after being instantiated
7675
# but used when interpreter used corresponding REPL

bpython/repl.py

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,8 @@ class Interpreter(code.InteractiveInterpreter):
110110

111111
def __init__(
112112
self,
113-
locals: Optional[MutableMapping[str, str]] = None,
114-
encoding: Optional[str] = None,
115-
):
113+
locals: Optional[MutableMapping[str, Any]] = None,
114+
) -> None:
116115
"""Constructor.
117116
118117
The optional 'locals' argument specifies the dictionary in which code
@@ -126,14 +125,8 @@ def __init__(
126125
callback can be added to the Interpreter instance afterwards - more
127126
specifically, this is so that autoindentation does not occur after a
128127
traceback.
129-
130-
encoding is only used in Python 2, where it may be necessary to add an
131-
encoding comment to a source bytestring before running it.
132-
encoding must be a bytestring in Python 2 because it will be templated
133-
into a bytestring source as part of an encoding comment.
134128
"""
135129

136-
self.encoding = encoding or getpreferredencoding()
137130
self.syntaxerror_callback: Optional[Callable] = None
138131

139132
if locals is None:
@@ -145,36 +138,21 @@ def __init__(
145138
super().__init__(locals)
146139
self.timer = RuntimeTimer()
147140

148-
def runsource(self, source, filename=None, symbol="single", encode="auto"):
141+
def runsource(
142+
self,
143+
source: str,
144+
filename: Optional[str] = None,
145+
symbol: str = "single",
146+
) -> bool:
149147
"""Execute Python code.
150148
151149
source, filename and symbol are passed on to
152-
code.InteractiveInterpreter.runsource. If encode is True,
153-
an encoding comment will be added to the source.
154-
On Python 3.X, encode will be ignored.
155-
156-
encode should only be used for interactive interpreter input,
157-
files should always already have an encoding comment or be ASCII.
158-
By default an encoding line will be added if no filename is given.
159-
160-
source must be a string
161-
162-
Because adding an encoding comment to a unicode string in Python 2
163-
would cause a syntax error to be thrown which would reference code
164-
the user did not write, setting encoding to True when source is a
165-
unicode string in Python 2 will throw a ValueError."""
166-
if encode and filename is not None:
167-
# files have encoding comments or implicit encoding of ASCII
168-
if encode != "auto":
169-
raise ValueError("shouldn't add encoding line to file contents")
170-
encode = False
150+
code.InteractiveInterpreter.runsource."""
171151

172152
if filename is None:
173153
filename = filename_for_console_input(source)
174154
with self.timer:
175-
return code.InteractiveInterpreter.runsource(
176-
self, source, filename, symbol
177-
)
155+
return super().runsource(source, filename, symbol)
178156

179157
def showsyntaxerror(self, filename=None):
180158
"""Override the regular handler, the code's copied and pasted from
@@ -532,7 +510,7 @@ def startup(self) -> None:
532510
encoding = inspection.get_encoding_file(filename)
533511
with open(filename, encoding=encoding) as f:
534512
source = f.read()
535-
self.interp.runsource(source, filename, "exec", encode=False)
513+
self.interp.runsource(source, filename, "exec")
536514

537515
def current_string(self, concatenate=False):
538516
"""If the line ends in a string get it, otherwise return ''"""

bpython/test/test_interpreter.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_syntaxerror(self):
3838
if (3, 10, 1) <= sys.version_info[:3]:
3939
expected = (
4040
" File "
41-
+ green('"<bpython-input-148>"')
41+
+ green('"<bpython-input-147>"')
4242
+ ", line "
4343
+ bold(magenta("1"))
4444
+ "\n 1.1.1.1\n ^^\n"
@@ -50,7 +50,7 @@ def test_syntaxerror(self):
5050
elif (3, 10) <= sys.version_info[:2]:
5151
expected = (
5252
" File "
53-
+ green('"<bpython-input-148>"')
53+
+ green('"<bpython-input-147>"')
5454
+ ", line "
5555
+ bold(magenta("1"))
5656
+ "\n 1.1.1.1\n ^^^^^\n"
@@ -129,13 +129,6 @@ def gfunc():
129129
self.assertMultiLineEqual(str(plain("").join(a)), str(expected))
130130
self.assertEqual(plain("").join(a), expected)
131131

132-
def test_runsource_bytes_over_128_syntax_error_py3(self):
133-
i = interpreter.Interp(encoding="latin-1")
134-
i.showsyntaxerror = mock.Mock(return_value=None)
135-
136-
i.runsource("a = b'\xfe'")
137-
i.showsyntaxerror.assert_called_with(mock.ANY)
138-
139132
def test_getsource_works_on_interactively_defined_functions(self):
140133
source = "def foo(x):\n return x + 1\n"
141134
i = interpreter.Interp()

bpython/urwid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ def options_callback(group):
12431243
extend_locals["service"] = serv
12441244
reactor.callWhenRunning(serv.startService)
12451245
exec_args = []
1246-
interpreter = repl.Interpreter(locals_, locale.getpreferredencoding())
1246+
interpreter = repl.Interpreter(locals_)
12471247
# TODO: replace with something less hack-ish
12481248
interpreter.locals.update(extend_locals)
12491249

0 commit comments

Comments
 (0)