@@ -120,7 +120,7 @@ def test_eval_str_invalid_escape(self):
120
120
r'Such sequences will not work in the future. '
121
121
r'Did you mean "\\z"? A raw string is also an option.' )
122
122
self .assertEqual (w [0 ].filename , '<string>' )
123
- self .assertEqual (w [0 ].lineno , 1 )
123
+ self .assertEqual (w [0 ].lineno , 2 )
124
124
125
125
with warnings .catch_warnings (record = True ) as w :
126
126
warnings .simplefilter ('error' , category = SyntaxWarning )
@@ -131,7 +131,7 @@ def test_eval_str_invalid_escape(self):
131
131
self .assertEqual (exc .msg , r'"\z" is an invalid escape sequence. '
132
132
r'Did you mean "\\z"? A raw string is also an option.' )
133
133
self .assertEqual (exc .filename , '<string>' )
134
- self .assertEqual (exc .lineno , 1 )
134
+ self .assertEqual (exc .lineno , 2 )
135
135
self .assertEqual (exc .offset , 1 )
136
136
137
137
# Check that the warning is raised only once if there are syntax errors
@@ -160,7 +160,7 @@ def test_eval_str_invalid_octal_escape(self):
160
160
r'Such sequences will not work in the future. '
161
161
r'Did you mean "\\407"? A raw string is also an option.' )
162
162
self .assertEqual (w [0 ].filename , '<string>' )
163
- self .assertEqual (w [0 ].lineno , 1 )
163
+ self .assertEqual (w [0 ].lineno , 2 )
164
164
165
165
with warnings .catch_warnings (record = True ) as w :
166
166
warnings .simplefilter ('error' , category = SyntaxWarning )
@@ -171,9 +171,32 @@ def test_eval_str_invalid_octal_escape(self):
171
171
self .assertEqual (exc .msg , r'"\407" is an invalid octal escape sequence. '
172
172
r'Did you mean "\\407"? A raw string is also an option.' )
173
173
self .assertEqual (exc .filename , '<string>' )
174
- self .assertEqual (exc .lineno , 1 )
174
+ self .assertEqual (exc .lineno , 2 )
175
175
self .assertEqual (exc .offset , 1 )
176
176
177
+ def test_invalid_escape_locations_with_offset (self ):
178
+ with warnings .catch_warnings (record = True ) as w :
179
+ warnings .simplefilter ('always' , category = SyntaxWarning )
180
+ eval ("\" '''''''''''''''''''''invalid\ Escape\" " )
181
+ self .assertEqual (len (w ), 1 )
182
+ self .assertEqual (str (w [0 ].message ),
183
+ r'"\ " is an invalid escape sequence. Such sequences '
184
+ r'will not work in the future. Did you mean "\\ "? '
185
+ r'A raw string is also an option.' )
186
+ self .assertEqual (w [0 ].filename , '<string>' )
187
+ self .assertEqual (w [0 ].lineno , 1 )
188
+
189
+ with warnings .catch_warnings (record = True ) as w :
190
+ warnings .simplefilter ('always' , category = SyntaxWarning )
191
+ eval ("\" ''Incorrect \ logic?\" " )
192
+ self .assertEqual (len (w ), 1 )
193
+ self .assertEqual (str (w [0 ].message ),
194
+ r'"\ " is an invalid escape sequence. Such sequences '
195
+ r'will not work in the future. Did you mean "\\ "? '
196
+ r'A raw string is also an option.' )
197
+ self .assertEqual (w [0 ].filename , '<string>' )
198
+ self .assertEqual (w [0 ].lineno , 1 )
199
+
177
200
def test_eval_str_raw (self ):
178
201
self .assertEqual (eval (""" r'x' """ ), 'x' )
179
202
self .assertEqual (eval (r""" r'\x01' """ ), '\\ ' + 'x01' )
@@ -215,7 +238,7 @@ def test_eval_bytes_invalid_escape(self):
215
238
r'Such sequences will not work in the future. '
216
239
r'Did you mean "\\z"? A raw string is also an option.' )
217
240
self .assertEqual (w [0 ].filename , '<string>' )
218
- self .assertEqual (w [0 ].lineno , 1 )
241
+ self .assertEqual (w [0 ].lineno , 2 )
219
242
220
243
with warnings .catch_warnings (record = True ) as w :
221
244
warnings .simplefilter ('error' , category = SyntaxWarning )
@@ -226,7 +249,7 @@ def test_eval_bytes_invalid_escape(self):
226
249
self .assertEqual (exc .msg , r'"\z" is an invalid escape sequence. '
227
250
r'Did you mean "\\z"? A raw string is also an option.' )
228
251
self .assertEqual (exc .filename , '<string>' )
229
- self .assertEqual (exc .lineno , 1 )
252
+ self .assertEqual (exc .lineno , 2 )
230
253
231
254
def test_eval_bytes_invalid_octal_escape (self ):
232
255
for i in range (0o400 , 0o1000 ):
@@ -241,7 +264,7 @@ def test_eval_bytes_invalid_octal_escape(self):
241
264
r'Such sequences will not work in the future. '
242
265
r'Did you mean "\\407"? A raw string is also an option.' )
243
266
self .assertEqual (w [0 ].filename , '<string>' )
244
- self .assertEqual (w [0 ].lineno , 1 )
267
+ self .assertEqual (w [0 ].lineno , 2 )
245
268
246
269
with warnings .catch_warnings (record = True ) as w :
247
270
warnings .simplefilter ('error' , category = SyntaxWarning )
@@ -252,7 +275,7 @@ def test_eval_bytes_invalid_octal_escape(self):
252
275
self .assertEqual (exc .msg , r'"\407" is an invalid octal escape sequence. '
253
276
r'Did you mean "\\407"? A raw string is also an option.' )
254
277
self .assertEqual (exc .filename , '<string>' )
255
- self .assertEqual (exc .lineno , 1 )
278
+ self .assertEqual (exc .lineno , 2 )
256
279
257
280
def test_eval_bytes_raw (self ):
258
281
self .assertEqual (eval (""" br'x' """ ), b'x' )
0 commit comments