Skip to content

Commit 546b7ed

Browse files
authored
Fix for flake8-bugbear rules B017 and B028 (#985)
1 parent d8360dc commit 546b7ed

File tree

12 files changed

+15
-15
lines changed

12 files changed

+15
-15
lines changed

src/django_mysql/cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ def decode(self, value: bytes, value_type: _EncodedKeyType) -> Any:
524524
return pickle.loads(raw_value)
525525

526526
raise ValueError(
527-
f"Unknown value_type '{value_type}' read from the cache table."
527+
f"Unknown value_type {value_type!r} read from the cache table."
528528
)
529529

530530
def _maybe_cull(self) -> None:

src/django_mysql/checks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def check_variables(
4646

4747
def innodb_strict_mode_warning(alias: str) -> checks.Warning:
4848
return checks.Warning(
49-
f"InnoDB Strict Mode is not set for database connection '{alias}'",
49+
f"InnoDB Strict Mode is not set for database connection {alias!r}",
5050
hint=(
5151
"InnoDB Strict Mode escalates several warnings around "
5252
+ "InnoDB-specific statements into errors. It's recommended you "
@@ -61,7 +61,7 @@ def innodb_strict_mode_warning(alias: str) -> checks.Warning:
6161

6262
def utf8mb4_warning(alias: str) -> checks.Warning:
6363
return checks.Warning(
64-
f"The character set is not utf8mb4 for database connection '{alias}'",
64+
f"The character set is not utf8mb4 for database connection {alias!r}",
6565
hint=(
6666
"The default 'utf8' character set does not include support for "
6767
+ "all Unicode characters. It's strongly recommended you move to "

src/django_mysql/management/commands/cull_mysql_caches.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ def handle(
4141
try:
4242
cache = caches[alias]
4343
except InvalidCacheBackendError:
44-
raise CommandError(f"Cache '{alias}' does not exist")
44+
raise CommandError(f"Cache {alias!r} does not exist")
4545

4646
if not isinstance(cache, MySQLCache): # pragma: no cover
4747
continue
4848

4949
if verbosity >= 1:
50-
self.stdout.write(f"Deleting from cache '{alias}'... ", ending="")
50+
self.stdout.write(f"Deleting from cache {alias!r}... ", ending="")
5151
num_deleted = cache.cull()
5252
if verbosity >= 1:
5353
self.stdout.write(f"{num_deleted} entries deleted.")

src/django_mysql/management/commands/dbparams.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ def handle(
5757
try:
5858
connection = connections[alias]
5959
except ConnectionDoesNotExist:
60-
raise CommandError(f"Connection '{alias}' does not exist")
60+
raise CommandError(f"Connection {alias!r} does not exist")
6161
if connection.vendor != "mysql":
62-
raise CommandError(f"{alias} is not a MySQL database connection")
62+
raise CommandError(f"{alias!r} is not a MySQL database connection")
6363

6464
if show_mysql and show_dsn:
6565
raise CommandError("Pass only one of --mysql and --dsn")

src/django_mysql/management/commands/mysql_cache_migration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def handle(self, *args: Any, aliases: list[str], **options: Any) -> None:
3939
try:
4040
cache = caches[alias]
4141
except InvalidCacheBackendError:
42-
raise CommandError(f"Cache '{alias}' does not exist")
42+
raise CommandError(f"Cache {alias!r} does not exist")
4343

4444
if not isinstance(cache, MySQLCache): # pragma: no cover
4545
continue

src/django_mysql/models/aggregates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def as_sql(
7878
sql.append(self.ordering.upper())
7979

8080
if self.separator is not None:
81-
sql.append(f" SEPARATOR '{self.separator}'")
81+
sql.append(f" SEPARATOR '{self.separator}'") # noqa: B028
8282

8383
sql.append(")")
8484

src/django_mysql/models/fields/dynamic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def _check_spec_recursively(
170170
if not isinstance(key, str):
171171
errors.append(
172172
checks.Error(
173-
f"The key '{key}' in 'spec{path}' is not a string",
173+
f"The key {str(key)!r} in 'spec{path}' is not a string",
174174
hint="'spec' keys must be of type str, "
175175
"'{}' is of type {}".format(key, type(key).__name__),
176176
obj=self,

src/django_mysql/models/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def __init__(self, expression: ExpressionArgument, data_type: str) -> None:
383383
expression = Value(expression)
384384

385385
if data_type not in KeyTransform.TYPE_MAP and data_type != "BINARY":
386-
raise ValueError(f"Invalid data_type '{data_type}'")
386+
raise ValueError(f"Invalid data_type {data_type!r}")
387387

388388
super().__init__(expression, data_type=data_type)
389389

src/django_mysql/status.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def get(self, name: str) -> int | float | bool | str:
3535
with self.get_cursor() as cursor:
3636
num_rows = cursor.execute(self.query + " LIKE %s", (name,))
3737
if num_rows == 0:
38-
raise KeyError(f"No such status variable '{name}'")
38+
raise KeyError(f"No such status variable {name!r}")
3939
return self._cast(cursor.fetchone()[1])
4040

4141
def get_many(self, names: Iterable[str]) -> dict[str, int | float | bool | str]:

src/django_mysql/test/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __call__(self, test_func: Any) -> Any:
4343

4444
if isinstance(test_func, type):
4545
if not issubclass(test_func, TestCase):
46-
raise Exception(
46+
raise TypeError(
4747
"{} only works with TestCase classes.".format(
4848
self.__class__.__name__
4949
)

0 commit comments

Comments
 (0)