Skip to content

Commit 873b6da

Browse files
committed
Some extra hints
1 parent fc8af0a commit 873b6da

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/django_mysql/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ def collapse_spaces(string: str) -> str:
132132
return " ".join(filter(None, bits))
133133

134134

135-
def index_name(model: Model, *field_names: str, using: str = DEFAULT_DB_ALIAS) -> str:
135+
def index_name(
136+
model: type[Model], *field_names: str, using: str = DEFAULT_DB_ALIAS
137+
) -> str:
136138
"""
137139
Returns the name of the index existing on field_names, or raises KeyError
138140
if no such index exists.

tests/testapp/test_locks.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import queue
44
from threading import Thread
55
from typing import TYPE_CHECKING
6+
from typing import cast
67

78
import pytest
89
from django.db import OperationalError
910
from django.db import connection
1011
from django.db import connections
12+
from django.db.backends.mysql.base import DatabaseWrapper
1113
from django.db.transaction import TransactionManagementError
1214
from django.db.transaction import atomic
1315
from django.test import TestCase
@@ -34,7 +36,7 @@ class LockTests(TestCase):
3436
def setUpClass(cls):
3537
super().setUpClass()
3638

37-
cls.supports_lock_info = connection.mysql_is_mariadb
39+
cls.supports_lock_info = cast(DatabaseWrapper, connection).mysql_is_mariadb
3840
if cls.supports_lock_info:
3941
with connection.cursor() as cursor:
4042
cursor.execute(
@@ -229,7 +231,7 @@ def tearDown(self):
229231
Customer.objects.using("other").all().delete()
230232
super().tearDown()
231233

232-
def is_locked(self, connection_name, table_name):
234+
def is_locked(self, connection_name: str, table_name: str) -> bool:
233235
conn = connections[connection_name]
234236
with conn.cursor() as cursor:
235237
cursor.execute(
@@ -239,7 +241,9 @@ def is_locked(self, connection_name, table_name):
239241
rows = cursor.fetchall()
240242
if rows:
241243
assert len(rows) == 1
242-
return rows[0][2] > 0
244+
value = rows[0][2]
245+
assert isinstance(value, int)
246+
return value > 0
243247
else: # pragma: no cover
244248
# MySQL 8+ closes the table really quickly. If it's closed,
245249
# it's not locked.

tests/testapp/test_size_fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
forceDataError = override_mysql_variables(SQL_MODE="STRICT_TRANS_TABLES")
2323

2424

25-
def migrate(name):
25+
def migrate(name: str) -> None:
2626
call_command(
2727
"migrate", "testapp", name, verbosity=0, skip_checks=True, interactive=False
2828
)

0 commit comments

Comments
 (0)