]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
refactor (sql): simplify and optimize internal SQL handling
authorShamil <ashm.tech@proton.me>
Mon, 21 Apr 2025 16:36:21 +0000 (12:36 -0400)
committersqla-tester <sqla-tester@sqlalchemy.org>
Mon, 21 Apr 2025 16:36:21 +0000 (12:36 -0400)
Replaced redundant variable assignments with direct operations. Used `dict.get()` for safer dictionary lookups to streamline logic. Improves code readability and reduces unnecessary lines.

Closes: #12538
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12538
Pull-request-sha: d322d1508cfc37668099e6624816aba9c647ad51

Change-Id: Ib3dfc7086ec35117fdad65e136a17aa014b96ae5

lib/sqlalchemy/sql/cache_key.py
lib/sqlalchemy/sql/compiler.py
lib/sqlalchemy/sql/crud.py
lib/sqlalchemy/sql/lambdas.py

index 5ac11878bac5214528ef7de8491980057aecb3a6..c8fa20569175a7dd897e32a62fc5bbfcbb846628 100644 (file)
@@ -516,7 +516,7 @@ class CacheKey(NamedTuple):
                             e2,
                         )
             else:
-                pickup_index = stack.pop(-1)
+                stack.pop(-1)
                 break
 
     def _diff(self, other: CacheKey) -> str:
index cdcf9f5c72d0811fcdad8439ccb1102e7f20f4a6..b123acbff1461a48f42bb26437e6d8fd3095d407 100644 (file)
@@ -4266,7 +4266,7 @@ class SQLCompiler(Compiled):
                 inner = "(%s)" % (inner,)
             return inner
         else:
-            enclosing_alias = kwargs["enclosing_alias"] = alias
+            kwargs["enclosing_alias"] = alias
 
         if asfrom or ashint:
             if isinstance(alias.name, elements._truncated_label):
index ca7448b58b76baef89d5af22fe28e1d513044321..265b15c1e9fb0e3f19149ff6e754b7c6284981ac 100644 (file)
@@ -236,7 +236,7 @@ def _get_crud_params(
         stmt_parameter_tuples = list(spd.items())
         spd_str_key = {_column_as_key(key) for key in spd}
     else:
-        stmt_parameter_tuples = spd = spd_str_key = None
+        stmt_parameter_tuples = spd_str_key = None
 
     # if we have statement parameters - set defaults in the
     # compiled params
index 8d70f800e74614be694952f4e32f18b8809a5440..ce755c1f8327678a84e8554226a1b151d63f16d3 100644 (file)
@@ -256,10 +256,7 @@ class LambdaElement(elements.ClauseElement):
 
                 self.closure_cache_key = cache_key
 
-                try:
-                    rec = lambda_cache[tracker_key + cache_key]
-                except KeyError:
-                    rec = None
+                rec = lambda_cache.get(tracker_key + cache_key)
             else:
                 cache_key = _cache_key.NO_CACHE
                 rec = None
@@ -1173,7 +1170,7 @@ class AnalyzedFunction:
                         closure_pywrappers.append(bind)
                 else:
                     value = fn.__globals__[name]
-                    new_globals[name] = bind = PyWrapper(fn, name, value)
+                    new_globals[name] = PyWrapper(fn, name, value)
 
             # rewrite the original fn.   things that look like they will
             # become bound parameters are wrapped in a PyWrapper.