Skip to content

Commit 5ab2311

Browse files
committed
Bring back the TOCTOU for readability
1 parent 32aa69d commit 5ab2311

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
@@ -1128,15 +1128,17 @@ def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None,
11281128
+ "add the site-packages directory to sys.path "
11291129
+ "or to enable your virtual environment?")
11301130
elif exc_type and issubclass(exc_type, AttributeError) and \
1131-
(wrong_name := getattr(exc_value, "name", None)) is not None:
1131+
getattr(exc_value, "name", None) is not None:
1132+
wrong_name = getattr(exc_value, "name", None)
11321133
suggestion = _compute_suggestion_error(exc_value, exc_traceback, wrong_name)
11331134
if suggestion:
11341135
if suggestion.isascii():
11351136
self._str += f". Did you mean: '.{suggestion}' instead of '.{wrong_name}'?"
11361137
else:
11371138
self._str += f". Did you mean: '.{suggestion}' ({suggestion!a}) instead of '.{wrong_name}'?"
11381139
elif exc_type and issubclass(exc_type, NameError) and \
1139-
(wrong_name := getattr(exc_value, "name", None)) is not None:
1140+
getattr(exc_value, "name", None) is not None:
1141+
wrong_name = getattr(exc_value, "name", None)
11401142
suggestion = _compute_suggestion_error(exc_value, exc_traceback, wrong_name)
11411143
if suggestion:
11421144
if suggestion.isascii():

0 commit comments

Comments
 (0)