]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
refactor: simplify and clean up dialect-specific code
authorShamil Abdulaev <ashm.tech@proton.me>
Thu, 17 Apr 2025 14:43:25 +0000 (17:43 +0300)
committerShamil <ashm.tech@proton.me>
Thu, 17 Apr 2025 14:53:15 +0000 (17:53 +0300)
Removed unused variables and redundant functions across multiple dialects.
Improves code readability and reduces maintenance complexity without altering functionality.

lib/sqlalchemy/dialects/mssql/base.py
lib/sqlalchemy/dialects/mysql/base.py
lib/sqlalchemy/dialects/postgresql/_psycopg_common.py
lib/sqlalchemy/dialects/postgresql/base.py
lib/sqlalchemy/dialects/sqlite/provision.py

index 24425fc817092ce8f2332095264c9164cd689ca3..937eedf9c3b077f2ddf8345e68a83837d195a761 100644 (file)
@@ -1324,7 +1324,7 @@ class _BASETIMEIMPL(TIME):
 
 
 class _DateTimeBase:
-    def bind_processor(self, dialect):
+    def bind_processor(self):
         def process(value):
             if type(value) == datetime.date:
                 return datetime.datetime(value.year, value.month, value.day)
@@ -3949,11 +3949,8 @@ index_info AS (
             )
         )
 
-        # group rows by constraint ID, to handle multi-column FKs
-        fkeys = []
-
-        def fkey_rec():
-            return {
+        fkeys = util.defaultdict(
+            lambda: {
                 "name": None,
                 "constrained_columns": [],
                 "referred_schema": None,
@@ -3961,8 +3958,7 @@ index_info AS (
                 "referred_columns": [],
                 "options": {},
             }
-
-        fkeys = util.defaultdict(fkey_rec)
+        )
 
         for r in connection.execute(s).all():
             (
index c3bf5fee3b191124bb4849ddb93012dcb49c69eb..2951b17d3b56b55069b66c44192e2756b4f291b6 100644 (file)
@@ -3486,7 +3486,6 @@ class MySQLDialect(default.DefaultDialect):
             full_name = self.identifier_preparer.format_table(table)
         st = "SHOW CREATE TABLE %s" % full_name
 
-        rp = None
         try:
             rp = connection.execution_options(
                 skip_user_error_events=True
index e5b39e500406d2f4555861e35325b13e064feefe..e5a8867c2161c9424346970295e9ce65f3883db3 100644 (file)
@@ -175,7 +175,6 @@ class _PGDialect_common_psycopg(PGDialect):
         connection.autocommit = value
 
     def do_ping(self, dbapi_connection):
-        cursor = None
         before_autocommit = dbapi_connection.autocommit
 
         if not before_autocommit:
index 864445026baabfdbb254278c07d1599ee7554444..2966d3e7fdb94f25e319525935e9774993d159e3 100644 (file)
@@ -3938,7 +3938,6 @@ class PGDialect(default.DefaultDialect):
                 schema_type = ENUM
                 enum = enums[enum_or_domain_key]
 
-                args = tuple(enum["labels"])
                 kwargs["name"] = enum["name"]
 
                 if not enum["visible"]:
index 97f882e7f2807c25f51f05d2f085e168484814ef..e1df005e72ccd51f760be51f40dc6bc05bd037ff 100644 (file)
@@ -52,8 +52,6 @@ def _format_url(url, driver, ident):
         assert "test_schema" not in filename
         tokens = re.split(r"[_\.]", filename)
 
-        new_filename = f"{driver}"
-
         for token in tokens:
             if token in _drivernames:
                 if driver is None: