Skip to content

Commit 7ca3954

Browse files
Cleanup type ignores in mysql provider where possible (#53288)
* Cleanup type ignores in mysql provider where possible * Revert two type ignore cleanups as long as imports with task sdk inconsistent * Fix typing error and handling of undefined unicode * Uuups Co-authored-by: GPK <[email protected]> * Fix typing errors next round * Fix typing errors next round, v2 --------- Co-authored-by: GPK <[email protected]>
1 parent 47fda18 commit 7ca3954

File tree

1 file changed

+12
-7
lines changed
  • providers/mysql/src/airflow/providers/mysql/hooks

1 file changed

+12
-7
lines changed

providers/mysql/src/airflow/providers/mysql/hooks/mysql.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@
3030
logger = logging.getLogger(__name__)
3131

3232
if TYPE_CHECKING:
33-
from airflow.models import Connection
33+
from airflow.providers.mysql.version_compat import AIRFLOW_V_3_0_PLUS
34+
35+
if AIRFLOW_V_3_0_PLUS:
36+
from airflow.sdk import Connection
37+
else:
38+
from airflow.models.connection import Connection # type: ignore[assignment]
3439

3540
try:
3641
from mysql.connector.abstracts import MySQLConnectionAbstract
@@ -130,7 +135,7 @@ def _get_conn_config_mysql_client(self, conn: Connection) -> dict:
130135

131136
if conn.extra_dejson.get("charset", False):
132137
conn_config["charset"] = conn.extra_dejson["charset"]
133-
if conn_config["charset"].lower() in ("utf8", "utf-8"):
138+
if str(conn_config.get("charset", "undef")).lower() in ("utf8", "utf-8"):
134139
conn_config["use_unicode"] = True
135140
if conn.extra_dejson.get("cursor", False):
136141
try:
@@ -220,7 +225,7 @@ def get_conn(self) -> MySQLConnectionTypes:
220225
"installed in case you see compilation error during installation."
221226
)
222227

223-
conn_config = self._get_conn_config_mysql_client(conn) # type: ignore[arg-type]
228+
conn_config = self._get_conn_config_mysql_client(conn)
224229
return MySQLdb.connect(**conn_config)
225230

226231
if client_name == "mysql-connector-python":
@@ -233,7 +238,7 @@ def get_conn(self) -> MySQLConnectionTypes:
233238
"'mysql-connector-python'. Warning! It might cause dependency conflicts."
234239
)
235240

236-
conn_config = self._get_conn_config_mysql_connector_python(conn) # type: ignore[arg-type]
241+
conn_config = self._get_conn_config_mysql_connector_python(conn)
237242
return mysql.connector.connect(**conn_config)
238243

239244
raise ValueError("Unknown MySQL client name provided!")
@@ -253,7 +258,7 @@ def bulk_load(self, table: str, tmp_file: str) -> None:
253258
(tmp_file,),
254259
)
255260
conn.commit()
256-
conn.close() # type: ignore[misc]
261+
conn.close()
257262

258263
def bulk_dump(self, table: str, tmp_file: str) -> None:
259264
"""Dump a database table into a tab-delimited file."""
@@ -270,7 +275,7 @@ def bulk_dump(self, table: str, tmp_file: str) -> None:
270275
(tmp_file,),
271276
)
272277
conn.commit()
273-
conn.close() # type: ignore[misc]
278+
conn.close()
274279

275280
@staticmethod
276281
def _serialize_cell(cell: object, conn: Connection | None = None) -> Any:
@@ -337,7 +342,7 @@ def bulk_load_custom(
337342

338343
cursor.close()
339344
conn.commit()
340-
conn.close() # type: ignore[misc]
345+
conn.close()
341346

342347
def get_openlineage_database_info(self, connection):
343348
"""Return MySQL specific information for OpenLineage."""

0 commit comments

Comments
 (0)