diff --git a/pandas/core/computation/scope.py b/pandas/core/computation/scope.py index 426cd8fd81f28..d4fbe226a3ae2 100644 --- a/pandas/core/computation/scope.py +++ b/pandas/core/computation/scope.py @@ -133,18 +133,13 @@ def __init__( # shallow copy here because we don't want to replace what's in # scope when we align terms (alignment accesses the underlying # numpy array of pandas objects) - - # error: Incompatible types in assignment (expression has type - # "ChainMap[str, Any]", variable has type "DeepChainMap[str, Any]") - self.scope = self.scope.new_child( # type: ignore[assignment] - (global_dict or frame.f_globals).copy() - ) + scope_global = self.scope.new_child((global_dict or frame.f_globals).copy()) + self.scope = DeepChainMap(scope_global) if not isinstance(local_dict, Scope): - # error: Incompatible types in assignment (expression has type - # "ChainMap[str, Any]", variable has type "DeepChainMap[str, Any]") - self.scope = self.scope.new_child( # type: ignore[assignment] + scope_local = self.scope.new_child( (local_dict or frame.f_locals).copy() ) + self.scope = DeepChainMap(scope_local) finally: del frame @@ -257,9 +252,7 @@ def _get_vars(self, stack, scopes: list[str]) -> None: for scope, (frame, _, _, _, _, _) in variables: try: d = getattr(frame, "f_" + scope) - # error: Incompatible types in assignment (expression has type - # "ChainMap[str, Any]", variable has type "DeepChainMap[str, Any]") - self.scope = self.scope.new_child(d) # type: ignore[assignment] + self.scope = DeepChainMap(self.scope.new_child(d)) finally: # won't remove it, but DECREF it # in Py3 this probably isn't necessary since frame won't be