@@ -110,9 +110,8 @@ class Interpreter(code.InteractiveInterpreter):
110
110
111
111
def __init__ (
112
112
self ,
113
- locals : Optional [MutableMapping [str , str ]] = None ,
114
- encoding : Optional [str ] = None ,
115
- ):
113
+ locals : Optional [MutableMapping [str , Any ]] = None ,
114
+ ) -> None :
116
115
"""Constructor.
117
116
118
117
The optional 'locals' argument specifies the dictionary in which code
@@ -126,14 +125,8 @@ def __init__(
126
125
callback can be added to the Interpreter instance afterwards - more
127
126
specifically, this is so that autoindentation does not occur after a
128
127
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.
134
128
"""
135
129
136
- self .encoding = encoding or getpreferredencoding ()
137
130
self .syntaxerror_callback : Optional [Callable ] = None
138
131
139
132
if locals is None :
@@ -145,36 +138,21 @@ def __init__(
145
138
super ().__init__ (locals )
146
139
self .timer = RuntimeTimer ()
147
140
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 :
149
147
"""Execute Python code.
150
148
151
149
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."""
171
151
172
152
if filename is None :
173
153
filename = filename_for_console_input (source )
174
154
with self .timer :
175
- return code .InteractiveInterpreter .runsource (
176
- self , source , filename , symbol
177
- )
155
+ return super ().runsource (source , filename , symbol )
178
156
179
157
def showsyntaxerror (self , filename = None ):
180
158
"""Override the regular handler, the code's copied and pasted from
@@ -532,7 +510,7 @@ def startup(self) -> None:
532
510
encoding = inspection .get_encoding_file (filename )
533
511
with open (filename , encoding = encoding ) as f :
534
512
source = f .read ()
535
- self .interp .runsource (source , filename , "exec" , encode = False )
513
+ self .interp .runsource (source , filename , "exec" )
536
514
537
515
def current_string (self , concatenate = False ):
538
516
"""If the line ends in a string get it, otherwise return ''"""
0 commit comments