Skip to content

Commit e20da27

Browse files
committed
Use locals.setdefault() instead of manually checking if key in dict
1 parent 02b8a83 commit e20da27

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

Lib/annotationlib.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,14 @@ def evaluate(
171171
# as a way of emulating annotation scopes when calling `eval()`
172172
if type_params is not None:
173173
for param in type_params:
174-
if param.__name__ not in locals:
175-
locals[param.__name__] = param
174+
locals.setdefault(param.__name__, param)
176175

177176
# Similar logic can be used for nonlocals, which should not
178177
# override locals.
179178
if isinstance(self.__cell__, dict):
180179
for cell_name, cell_value in self.__cell__.items():
181180
try:
182-
if cell_name not in locals:
183-
locals[cell_name] = cell_value.cell_contents
181+
locals.setdefault(cell_name, cell_value.cell_contents)
184182
except ValueError:
185183
pass
186184

0 commit comments

Comments
 (0)