gh-104741: Add line number attribute to indentation error exception (#104743)

This commit is contained in:
Marta Gómez Macías 2023-05-22 13:30:18 +02:00 committed by GitHub
parent 0a7796052a
commit 729b252241
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 8 deletions

View file

@ -92,9 +92,18 @@ def k(x):
readline = BytesIO(indent_error_file).readline
with self.assertRaisesRegex(IndentationError,
"unindent does not match any "
"outer indentation level"):
"outer indentation level") as e:
for tok in tokenize(readline):
pass
self.assertEqual(e.exception.lineno, 3)
self.assertEqual(e.exception.filename, '<string>')
self.assertEqual(e.exception.end_lineno, None)
self.assertEqual(e.exception.end_offset, None)
self.assertEqual(
e.exception.msg,
'unindent does not match any outer indentation level')
self.assertEqual(e.exception.offset, 9)
self.assertEqual(e.exception.text, ' x += 5\n')
def test_int(self):
# Ordinary integers and binary operators