Skip to content

Commit 47d4c25

Browse files
committed
Small opt
1 parent deb6d2a commit 47d4c25

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Lib/traceback.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,7 @@ def _find_keyword_typos(self):
13141314
if len(error_code) > 1024:
13151315
return
13161316

1317+
error_lines = error_code.splitlines()
13171318
tokens = tokenize.generate_tokens(io.StringIO(error_code).readline)
13181319
tokens_left_to_process = 10
13191320
import difflib
@@ -1339,12 +1340,13 @@ def _find_keyword_typos(self):
13391340
if not suggestion or suggestion == wrong_name:
13401341
continue
13411342
# Try to replace the token with the keyword
1342-
the_lines = error_code.splitlines()
1343-
the_line = the_lines[start[0] - 1]
1343+
the_lines = error_lines.copy()
1344+
the_line = the_lines[start[0] - 1][:]
13441345
chars = list(the_line)
13451346
chars[token.start[1]:token.end[1]] = suggestion
13461347
the_lines[start[0] - 1] = ''.join(chars)
13471348
code = '\n'.join(the_lines)
1349+
13481350
# Check if it works
13491351
try:
13501352
codeop.compile_command(code, symbol="exec", flags=codeop.PyCF_ONLY_AST)

0 commit comments

Comments
 (0)