]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
refactor: simplify and clean up dialect-specific code
authorShamil <ashm.tech@proton.me>
Thu, 17 Apr 2025 15:23:21 +0000 (11:23 -0400)
committerMichael Bayer <mike_mp@zzzcomputing.com>
Mon, 21 Apr 2025 15:08:22 +0000 (15:08 +0000)
**Title:** Removed unused variables and redundant functions across multiple dialects. Improves code readability and reduces maintenance complexity without altering functionality.
### Description
This pull request introduces several minor refactorings across different dialect modules:
- **MSSQL:**
    - Simplified the initialization of the `fkeys` dictionary in `_get_foreign_keys` using `util.defaultdict` directly.

- **MySQL:** Removed the unused variable in `_get_table_comment`. `rp`
- **PostgreSQL (_psycopg_common):** Removed the unused variable `cursor` in `do_ping`.
- **PostgreSQL (base):** Removed the unused variable `args` in `_get_column_info`.
- **SQLite:** Removed the unused variable `new_filename` in `generate_driver_url`.

These changes focus purely on code cleanup and simplification, removing dead code and improving clarity. They do not alter the existing logic or functionality of the dialects.
### Checklist
This pull request is:
- [ ] A documentation / typographical / small typing error fix
- [x] A short code fix
    - _Note: This is a general cleanup refactor rather than a fix for a specific reported issue._

- [ ] A new feature implementation

**Have a nice day!**

Closes: #12534
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12534
Pull-request-sha: 2c7ae17b73192ba6bff6bec953b307a88ea31847

Change-Id: I1ec3b48f42aea7e45bc20f81add03051eb30bb98

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..2931a53abb2d9345f6e7832b39ceb878bd4734a8 100644 (file)
@@ -3950,10 +3950,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 +3959,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: