**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
(cherry picked from commit
bb5bfb4beb35450ee8db7a173b9b438e065a90a9)
)
# 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,
"referred_columns": [],
"options": {},
}
-
- fkeys = util.defaultdict(fkey_rec)
+ )
for r in connection.execute(s).all():
(
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
connection.autocommit = value
def do_ping(self, dbapi_connection):
- cursor = None
before_autocommit = dbapi_connection.autocommit
if not before_autocommit:
schema_type = ENUM
enum = enums[enum_or_domain_key]
- args = tuple(enum["labels"])
kwargs["name"] = enum["name"]
if not enum["visible"]:
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: