Skip to content

Commit d02e635

Browse files
committed
Create new locals dict when necessary
1 parent 2630802 commit d02e635

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

Lib/annotationlib.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,21 @@ def evaluate(
150150
if globals is None:
151151
globals = {}
152152

153+
if type_params is None and owner is not None:
154+
type_params = getattr(owner, "__type_params__", None)
155+
153156
if locals is None:
154157
locals = {}
155158
if isinstance(owner, type):
156159
locals.update(vars(owner))
157-
158-
if type_params is None and owner is not None:
159-
type_params = getattr(owner, "__type_params__", None)
160+
elif (
161+
type_params is not None
162+
or isinstance(self.__cell__, dict)
163+
or self.__extra_names__
164+
):
165+
# Create a new locals dict if necessary,
166+
# to avoid mutating the argument.
167+
locals = dict(locals)
160168

161169
# "Inject" type parameters into the local namespace
162170
# (unless they are shadowed by assignments *in* the local namespace),

0 commit comments

Comments
 (0)