Skip to content

Commit 6524f5a

Browse files
committed
Update pre-commit hook, and fix style and typing
Change-Id: I4c9cdd79029ebac51f1b46f30651a9fc02546e71
1 parent ae20163 commit 6524f5a

12 files changed

+24
-11
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,22 @@
2828

2929
repos:
3030
- repo: https://github.com/psf/black
31-
rev: 24.2.0
31+
rev: 24.4.2
3232
hooks:
3333
- id: black
3434
- repo: https://github.com/pycqa/isort
3535
rev: 5.13.2
3636
hooks:
3737
- id: isort
3838
- repo: https://github.com/pre-commit/mirrors-mypy
39-
rev: v1.8.0
39+
rev: v1.10.0
4040
hooks:
4141
- id: mypy
4242
additional_dependencies: [
4343
django,
4444
django-stubs,
4545
gssapi==1.8.1,
46-
dnspython==2.1.0,
46+
dnspython==2.6.1,
4747
Deprecated>=1.2.6,
4848
typing-extensions>=3.7.4,
4949
zipp>=0.5,

mysql-connector-python/lib/mysql/connector/abstracts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,7 @@ def reconnect(self, attempts: int = 1, delay: int = 0) -> None:
14491449
span = None
14501450

14511451
if self._tracer:
1452+
# pylint: disable=possibly-used-before-assignment
14521453
span = self._tracer.start_span(
14531454
name=CONNECTION_SPAN_NAME, kind=trace.SpanKind.CLIENT
14541455
)

mysql-connector-python/lib/mysql/connector/aio/connection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,7 @@ async def cmd_refresh(self, options: int) -> OkPacketType:
11711171
):
11721172
raise ValueError("Invalid command REFRESH option")
11731173

1174+
res = None
11741175
if options & RefreshOption.GRANT:
11751176
res = await self.cmd_query("FLUSH PRIVILEGES")
11761177
if options & RefreshOption.LOG:

mysql-connector-python/lib/mysql/connector/connection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ def shutdown(self) -> None:
417417
def close(self) -> None:
418418
"""Disconnect from the MySQL server"""
419419
if self._span and self._span.is_recording():
420+
# pylint: disable=possibly-used-before-assignment
420421
record_exception_event(self._span, sys.exc_info()[1])
421422

422423
if not self._socket:
@@ -935,6 +936,7 @@ def cmd_refresh(self, options: int) -> OkPacketType:
935936
):
936937
raise ValueError("Invalid command REFRESH option")
937938

939+
res = None
938940
if options & RefreshOption.GRANT:
939941
res = self.cmd_query("FLUSH PRIVILEGES")
940942
if options & RefreshOption.LOG:

mysql-connector-python/lib/mysql/connector/connection_cext.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ def _open_connection(self) -> None:
359359
def close(self) -> None:
360360
"""Disconnect from the MySQL server"""
361361
if self._span and self._span.is_recording():
362+
# pylint: disable=possibly-used-before-assignment
362363
record_exception_event(self._span, sys.exc_info()[1])
363364

364365
if not self._cmysql:

mysql-connector-python/lib/mysql/connector/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104

105105
CNX_POOL_ARGS: Tuple[str, str, str] = ("pool_name", "pool_size", "pool_reset_session")
106106

107-
CONN_ATTRS_DN: Tuple[str] = (
107+
CONN_ATTRS_DN: Tuple[str, ...] = (
108108
"_pid",
109109
"_platform",
110110
"_source_host",
@@ -118,7 +118,7 @@
118118
)
119119

120120
# List of deprecated cursor class names
121-
DEPRECATED_CURSOR_CLASS_NAMES: Tuple[str] = (
121+
DEPRECATED_CURSOR_CLASS_NAMES: Tuple[str, ...] = (
122122
"MySQLCursorPreparedRaw",
123123
"MySQLCursorNamedTuple",
124124
"MySQLCursorBufferedNamedTuple",

mysql-connector-python/lib/mysql/connector/cursor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
Sequence,
5151
Tuple,
5252
Union,
53+
cast,
5354
)
5455

5556
from .abstracts import NAMED_TUPLE_CACHE, MySQLCursorAbstract
@@ -253,6 +254,7 @@ class MySQLCursor(MySQLCursorAbstract):
253254
def __init__(self, connection: Optional[MySQLConnection] = None) -> None:
254255
"""Initialize"""
255256
super().__init__(connection)
257+
self._connection: MySQLConnection = cast("MySQLConnection", self._connection)
256258

257259
def __iter__(self) -> Iterator[RowType]:
258260
"""

mysql-connector-python/lib/mysql/connector/cursor_cext.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
Sequence,
4848
Tuple,
4949
Union,
50+
cast,
5051
)
5152

5253
# pylint: disable=import-error,no-name-in-module
@@ -130,6 +131,7 @@ def __init__(self, connection: CMySQLConnection) -> None:
130131
self._affected_rows: int = -1
131132
self._raw_as_string: bool = False
132133
self._buffered: bool = False
134+
self._connection: CMySQLConnection = cast("CMySQLConnection", self._connection)
133135

134136
def reset(self, free: bool = True) -> None:
135137
"""Reset the cursor

mysql-connector-python/lib/mysql/connector/opentelemetry/context_propagation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def build_traceparent_header(span: Any) -> str:
6464
References:
6565
[1]: https://www.w3.org/TR/trace-context/#traceparent-header
6666
"""
67+
# pylint: disable=possibly-used-before-assignment
6768
ctx = span.get_span_context()
6869

6970
version = "00" # version 0 of the W3C specification
@@ -91,6 +92,7 @@ def with_context_propagation(method: Callable) -> Callable:
9192

9293
def wrapper(cnx: "MySQLConnectionAbstract", *args: Any, **kwargs: Any) -> Any:
9394
"""Context propagation decorator."""
95+
# pylint: disable=possibly-used-before-assignment
9496
if not OTEL_ENABLED or not cnx.otel_context_propagation:
9597
return method(cnx, *args, **kwargs)
9698

mysql-connector-python/lib/mysql/connector/opentelemetry/instrumentation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
from opentelemetry.semconv.trace import SpanAttributes # check semconv
6464
except ImportError as missing_dependencies_err:
6565
raise connector.errors.ProgrammingError(
66-
"OpenTelemetry installation not found. " "You must install the API and SDK."
66+
"OpenTelemetry installation not found. You must install the API and SDK."
6767
) from missing_dependencies_err
6868

6969

@@ -425,7 +425,7 @@ def cmd_ping(self, *args: Any, **kwargs: Any) -> Any:
425425

426426
@property
427427
@with_cnx_query_span
428-
def database(self, *args: Any, **kwargs: Any) -> str:
428+
def database(self) -> str:
429429
"""Instrument method."""
430430
return self._wrapped.database
431431

@@ -481,19 +481,19 @@ def cmd_reset_connection(self, *args: Any, **kwargs: Any) -> Any:
481481

482482
@property
483483
@with_cnx_query_span
484-
def time_zone(self, *args: Any, **kwargs: Any) -> str:
484+
def time_zone(self) -> str:
485485
"""Instrument method."""
486486
return self._wrapped.time_zone
487487

488488
@property
489489
@with_cnx_query_span
490-
def sql_mode(self, *args: Any, **kwargs: Any) -> str:
490+
def sql_mode(self) -> str:
491491
"""Instrument method."""
492492
return self._wrapped.sql_mode
493493

494494
@property
495495
@with_cnx_query_span
496-
def autocommit(self, *args: Any, **kwargs: Any) -> bool:
496+
def autocommit(self) -> bool:
497497
"""Instrument method."""
498498
return self._wrapped.autocommit
499499

mysql-connector-python/lib/mysql/connector/protocol.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,9 @@ def _parse_binary_integer(
677677
elif field[1] == FieldType.LONGLONG:
678678
format_ = "<q"
679679
length = 8
680+
else:
681+
# length is undefined
682+
raise ValueError("Unknown integer type")
680683

681684
if field[7] & FieldFlag.UNSIGNED:
682685
format_ = format_.upper()

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ skip_glob = [
4747
'mysqlx-connector-python/lib/mysqlx/locales/eng',
4848
'mysqlx-connector-python/lib/mysqlx/protobuf',
4949
'venv/*',
50-
'mysql-connector-python/lib/mysql/opentelemetry',
5150
]
5251

5352
[tool.black]

0 commit comments

Comments
 (0)