Skip to content

Commit d93aea9

Browse files
committed
chore: Apply pyupgrade for 3.10+ syntax
pyupgrade --py310-plus modeltranslation/**/*.py
1 parent a03477c commit d93aea9

File tree

13 files changed

+27
-33
lines changed

13 files changed

+27
-33
lines changed

modeltranslation/_compat.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING, Any, Callable
3+
from typing import TYPE_CHECKING, Any
4+
from collections.abc import Callable
45

56
import django
6-
from typing import Iterable
7-
from typing import Optional
7+
from collections.abc import Iterable
88

99
if TYPE_CHECKING:
1010
from django.db.models import QuerySet
@@ -32,7 +32,7 @@ def clear_ForeignObjectRel_caches(field: ForeignObjectRel):
3232

3333
def build_refresh_from_db(
3434
old_refresh_from_db: Callable[
35-
[Any, Optional[str], Optional[Iterable[str]], QuerySet[Any] | None], None
35+
[Any, str | None, Iterable[str] | None, QuerySet[Any] | None], None
3636
],
3737
):
3838
from modeltranslation.manager import append_translated
@@ -57,7 +57,7 @@ def is_hidden(field: ForeignObjectRel) -> bool:
5757

5858
# Django versions below 5.1 do not have `from_queryset` argument.
5959
def build_refresh_from_db( # type: ignore[misc]
60-
old_refresh_from_db: Callable[[Any, Optional[str], Optional[Iterable[str]]], None],
60+
old_refresh_from_db: Callable[[Any, str | None, Iterable[str] | None], None],
6161
):
6262
from modeltranslation.manager import append_translated
6363

modeltranslation/_typing.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
from __future__ import annotations
22

3-
import sys
43
from typing import Literal, TypeVar, Union
54

65
from django.contrib import admin
76
from django.contrib.admin.options import BaseModelAdmin
87

9-
if sys.version_info >= (3, 11):
10-
from typing import Self, TypeAlias # noqa: F401
11-
else:
12-
from typing_extensions import Self, TypeAlias # noqa: F401
8+
from typing_extensions import Self # noqa: F401
9+
from typing import TypeAlias
1310

1411
AutoPopulate: TypeAlias = "bool | Literal['all', 'default', 'required']"
1512

modeltranslation/admin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def patch_translation_field(
8181
if field.required:
8282
field.required = False
8383
field.blank = True
84-
self._orig_was_required["%s.%s" % (db_field.model._meta, db_field.name)] = True
84+
self._orig_was_required["{}.{}".format(db_field.model._meta, db_field.name)] = True
8585

8686
# For every localized field copy the widget from the original field
8787
# and add a css class to identify a modeltranslation widget.
@@ -131,7 +131,7 @@ def patch_translation_field(
131131
# Add another css class to identify a default modeltranslation widget
132132
css_classes.append("mt-default")
133133
if orig_formfield.required or self._orig_was_required.get(
134-
"%s.%s" % (orig_field.model._meta, orig_field.name)
134+
"{}.{}".format(orig_field.model._meta, orig_field.name)
135135
):
136136
# In case the original form field was required, make the
137137
# default translation field required instead.

modeltranslation/decorators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING, Any, Callable, TypeVar
3+
from typing import TYPE_CHECKING, Any, TypeVar
4+
from collections.abc import Callable
45
from collections.abc import Iterable
56

67
from django.db.models import Model

modeltranslation/fields.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def __init__(
198198
self.remote_field.related_name = "%s_rel_+" % self.name
199199
elif is_hidden(self.remote_field):
200200
# Even if the backwards relation is disabled, django internally uses it, need to use a language scoped related_name
201-
self.remote_field.related_name = "_%s_%s_+" % (
201+
self.remote_field.related_name = "_{}_{}_+".format(
202202
self.model.__name__.lower(),
203203
self.name,
204204
)
@@ -210,7 +210,7 @@ def __init__(
210210
self.related_query_name(), self.language
211211
)
212212
self.related_query_name = lambda: loc_related_query_name
213-
self.remote_field.related_name = "%s_set" % (
213+
self.remote_field.related_name = "{}_set".format(
214214
build_localized_fieldname(self.model.__name__.lower(), language),
215215
)
216216
else:

modeltranslation/management/commands/loaddata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def check_mode(
2727
if value == "0" or value.lower() == "false":
2828
value = False # type: ignore[assignment]
2929
if value not in ALLOWED:
30-
raise ValueError("%s option can be only one of: %s" % (opt_str, ALLOWED_FOR_PRINT))
30+
raise ValueError("{} option can be only one of: {}".format(opt_str, ALLOWED_FOR_PRINT))
3131
setattr(namespace or parser.values, option.dest, value) # type: ignore[attr-defined]
3232

3333

modeltranslation/management/commands/sync_translation_fields.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def handle(self, *args: Any, **options: Any) -> None:
8282
for model in models:
8383
db_table = model._meta.db_table
8484
model_name = model._meta.model_name
85-
model_full_name = "%s.%s" % (model._meta.app_label, model_name)
85+
model_full_name = "{}.{}".format(model._meta.app_label, model_name)
8686
opts = translator.get_options_for_model(model)
8787
for field_name, fields in opts.local_fields.items():
8888
# Take `db_column` attribute into account
@@ -144,7 +144,7 @@ def get_sync_sql(
144144
col_type = f.db_type(connection=connection)
145145
field_sql = [style.SQL_FIELD(qn(f.column)), style.SQL_COLTYPE(col_type)] # type: ignore[arg-type]
146146
# column creation
147-
stmt = "ALTER TABLE %s ADD COLUMN %s" % (qn(db_table), " ".join(field_sql))
147+
stmt = "ALTER TABLE {} ADD COLUMN {}".format(qn(db_table), " ".join(field_sql))
148148
if not f.null:
149149
stmt += " " + style.SQL_KEYWORD("NOT NULL")
150150
sql_output.append(stmt + ";")

modeltranslation/manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def append_lookup_key(model: type[Model], lookup_key: str) -> set[str]:
117117
rest = append_lookup_key(transmodel, pieces[1])
118118
fields = {"__".join(pr) for pr in itertools.product(fields, rest)}
119119
else:
120-
fields = {"%s__%s" % (f, pieces[1]) for f in fields}
120+
fields = {"{}__{}".format(f, pieces[1]) for f in fields}
121121
return fields
122122

123123

modeltranslation/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import annotations
2-
from typing import Callable
2+
from collections.abc import Callable
33

44
from django.conf import settings
55
from django.core.exceptions import ImproperlyConfigured

modeltranslation/tests/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class CustomThroughModel(models.Model):
160160

161161
@property
162162
def test_property(self):
163-
return "%s_%s" % (self.__class__.__name__, self.rel_1_id)
163+
return "{}_{}".format(self.__class__.__name__, self.rel_1_id)
164164

165165
def test_method(self):
166166
return self.rel_1_id + 1

0 commit comments

Comments
 (0)