gh-137078: Fix keyword typo recognition when executed over files (#137079)

This commit is contained in:
Pablo Galindo Salgado 2025-08-15 16:14:13 +01:00 committed by GitHub
parent dc53a3e52a
commit 4e08a9f97a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 56 additions and 7 deletions

View file

@ -1322,7 +1322,6 @@ class TracebackException:
lines = source.splitlines()
error_code = lines[line -1 if line > 0 else 0:end_line]
error_code[0] = error_code[0][offset:]
error_code = textwrap.dedent('\n'.join(error_code))
# Do not continue if the source is too large
@ -1338,7 +1337,8 @@ class TracebackException:
if token.type != tokenize.NAME:
continue
# Only consider NAME tokens on the same line as the error
if from_filename and token.start[0]+line != end_line+1:
the_end = end_line if line == 0 else end_line + 1
if from_filename and token.start[0]+line != the_end:
continue
wrong_name = token.string
if wrong_name in keyword.kwlist: