@@ -169,25 +169,7 @@ def _fstring_chunks(
169169 # We have an f-string AST node.
170170 # Now prepare the namespaces that we will use to evaluate the components.
171171 global_vars = frame .f_globals
172- local_vars = {** frame .f_locals }
173- # Add any values in kwargs (i.e. attributes) to `local_vars` so that they take precedence.
174- # Warn the user if there's a conflict.
175- for kwarg_name , kwarg_value in kwargs .items ():
176- # Check the same namespaces that Python uses, in the same order.
177- for namespace in (local_vars , global_vars , frame .f_builtins ):
178- if kwarg_name in namespace :
179- # No need to warn if they just passed the same value as an attribute, e.g. `foo=foo`.
180- if namespace [kwarg_name ] is not kwarg_value :
181- warnings .warn (
182- f'The attribute { kwarg_name !r} has the same name as a variable with a different value. '
183- f'Using the attribute.' ,
184- stacklevel = get_stacklevel (frame ),
185- )
186- # No need to check the other namespaces either way,
187- # since the earlier namespaces take precedence even in normal variable lookups.
188- break
189- # Set the attribute value regardless of whether it's also an existing variable.
190- local_vars [kwarg_name ] = kwarg_value
172+ local_vars = {** frame .f_locals , ** kwargs }
191173
192174 # Now for the actual formatting!
193175 result : list [LiteralChunk | ArgChunk ] = []
0 commit comments