Skip to content

Commit 94beebd

Browse files
committed
remove unnecessary translation hooks #18
1 parent 4daaa2c commit 94beebd

File tree

7 files changed

+17
-41
lines changed

7 files changed

+17
-41
lines changed

django_typer/apps.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from django.conf import settings
1313
from django.core.checks import CheckMessage, register
1414
from django.core.checks import Warning as CheckWarning
15-
from django.utils.translation import gettext as _
1615

1716
from .config import traceback_config
1817

@@ -86,7 +85,7 @@ def check_traceback_config(app_configs, **kwargs) -> t.List[CheckMessage]:
8685
warnings.append(
8786
CheckWarning(
8887
"DT_RICH_TRACEBACK_CONFIG",
89-
hint=_("Unexpected parameters encountered: {keys}.").format(
88+
hint="Unexpected parameters encountered: {keys}.".format(
9089
keys=", ".join(unexpected)
9190
),
9291
obj=settings.SETTINGS_MODULE,

django_typer/completers/model.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from django.conf import settings
99
from django.db import models
1010
from django.db.models.query import QuerySet
11-
from django.utils.translation import gettext as _
1211

1312

1413
class ModelObjectCompleter:
@@ -274,11 +273,7 @@ def uuid_query(
274273
self._offset += 1
275274

276275
if len(uuid) > 32:
277-
raise ValueError(
278-
_("Too many UUID characters: {incomplete}").format(
279-
incomplete=incomplete
280-
)
281-
)
276+
raise ValueError(f"Too many UUID characters: {incomplete}")
282277
min_uuid = UUID(uuid + "0" * (32 - len(uuid)))
283278
max_uuid = UUID(uuid + "f" * (32 - len(uuid)))
284279
return models.Q(**{f"{self.lookup_field}__gte": min_uuid}) & models.Q(
@@ -302,11 +297,11 @@ def _get_date_bounds(self, incomplete: str) -> t.Tuple[date, date]:
302297
day_low = 1
303298
day_high = None
304299
if len(parts) > 1:
305-
assert len(parts[0]) > 3, _("Year must be 4 digits")
300+
assert len(parts[0]) > 3, "Year must be 4 digits"
306301
month_high = min(int(parts[1] + "9" * (2 - len(parts[1]))), 12)
307302
month_low = max(int(parts[1] + "0" * (2 - len(parts[1]))), 1)
308303
if len(parts) > 2:
309-
assert len(parts[1]) > 1, _("Month must be 2 digits")
304+
assert len(parts[1]) > 1, "Month must be 2 digits"
310305
day_low = max(int(parts[2] + "0" * (2 - len(parts[2]))), 1)
311306
day_high = min(
312307
int(parts[2] + "9" * (2 - len(parts[2]))),
@@ -658,7 +653,7 @@ def __init__(
658653
self._queryset = model_or_qry
659654
else:
660655
raise ValueError(
661-
_("ModelObjectCompleter requires a Django model class or queryset.")
656+
"ModelObjectCompleter requires a Django model class or queryset."
662657
)
663658
self.lookup_field = str(
664659
lookup_field or getattr(self.model_cls._meta.pk, "name", "id")
@@ -701,9 +696,7 @@ def __init__(
701696
self.query = self.duration_query
702697
else:
703698
raise ValueError(
704-
_("Unsupported lookup field class: {cls}").format(
705-
cls=self._field.__class__.__name__
706-
)
699+
f"Unsupported lookup field class: {self._field.__class__.__name__}"
707700
)
708701

709702
def __call__(

django_typer/management/__init__.py

+5-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from django.db.models import Model
1818
from django.db.models.query import QuerySet
1919
from django.utils.functional import Promise, classproperty
20-
from django.utils.translation import gettext as _
2120

2221
from django_typer import patch
2322

@@ -2512,7 +2511,7 @@ def add_argument(self, *args, **kwargs):
25122511
add_argument() is disabled for TyperCommands because all arguments
25132512
and parameters are specified as args and kwargs on the function calls.
25142513
"""
2515-
raise NotImplementedError(_("add_argument() is not supported"))
2514+
raise NotImplementedError("add_argument() is not supported")
25162515

25172516

25182517
class OutputWrapper(BaseOutputWrapper):
@@ -3073,7 +3072,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
30733072
sys.exit(exc_val.exit_code)
30743073
if isinstance(exc_val, click.exceptions.UsageError):
30753074
err_msg = (
3076-
_(self.missing_args_message).format(
3075+
self.missing_args_message.format(
30773076
parameter=getattr(getattr(exc_val, "param", None), "name", "")
30783077
)
30793078
if isinstance(exc_val, click.exceptions.MissingParameter)
@@ -3132,9 +3131,7 @@ def __init__(
31323131
assert get_typer_command(self.typer_app)
31333132
except RuntimeError as rerr:
31343133
raise NotImplementedError(
3135-
_(
3136-
"No commands or command groups were registered on {command}"
3137-
).format(command=self._name)
3134+
f"No commands or command groups were registered on {self._name}"
31383135
) from rerr
31393136

31403137
def get_subcommand(self, *command_path: str) -> CommandNode:
@@ -3248,10 +3245,8 @@ def handle(self, option1: bool, option2: bool):
32483245
if callable(handle):
32493246
return handle(*args, **kwargs)
32503247
raise NotImplementedError(
3251-
_(
3252-
"{cls} does not implement handle(), you must call the other command "
3253-
"functions directly."
3254-
).format(cls=self.__class__)
3248+
f"{self.__class__} does not implement handle(), you must call the other command "
3249+
"functions directly."
32553250
)
32563251

32573252
@t.no_type_check

django_typer/parsers/apps.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from django.apps import AppConfig, apps
44
from django.core.management import CommandError
5-
from django.utils.translation import gettext as _
65

76

87
def app_config(label: t.Union[str, AppConfig]):
@@ -44,9 +43,7 @@ def handle(
4443
if cfg.name == label:
4544
return cfg
4645

47-
raise CommandError(
48-
_("{label} does not match any installed app label.").format(label=label)
49-
) from err
46+
raise CommandError(f"{label} does not match any installed app label.") from err
5047

5148

5249
app_config.__name__ = "APP_LABEL"

django_typer/parsers/model.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from click import Context, Parameter, ParamType
77
from django.core.management import CommandError
88
from django.db import models
9-
from django.utils.translation import gettext as _
109

1110
from django_typer.completers.model import ModelObjectCompleter
1211

@@ -118,7 +117,7 @@ def __init__(
118117
self.return_type = return_type
119118
self.case_insensitive = case_insensitive
120119
field = self.model_cls._meta.get_field(self.lookup_field)
121-
assert not isinstance(field, (models.ForeignObjectRel, GenericForeignKey)), _(
120+
assert not isinstance(field, (models.ForeignObjectRel, GenericForeignKey)), (
122121
"{cls} is not a supported lookup field."
123122
).format(cls=self._field.__class__.__name__)
124123
self._field = field
@@ -178,17 +177,11 @@ def convert(
178177
if self.on_error:
179178
return self.on_error(self.model_cls, original, err)
180179
raise CommandError(
181-
_("{value} is not a valid {field}").format(
182-
value=original, field=self._field.__class__.__name__
183-
)
180+
f"{original} is not a valid {self._field.__class__.__name__}"
184181
) from err
185182
except self.model_cls.DoesNotExist as err:
186183
if self.on_error:
187184
return self.on_error(self.model_cls, original, err)
188185
raise CommandError(
189-
_('{model}.{lookup_field}="{value}" does not exist!').format(
190-
model=self.model_cls.__name__,
191-
lookup_field=self.lookup_field,
192-
value=original,
193-
)
186+
f'{self.model_cls.__name__}.{self.lookup_field}="{original}" does not exist!'
194187
) from err

django_typer/shells/powershell.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from pathlib import Path
33

44
from click.shell_completion import CompletionItem
5-
from django.utils.translation import gettext as _
65

76
from . import DjangoTyperShellCompleter
87

@@ -76,7 +75,7 @@ def get_user_profile(self) -> Path:
7675
except UnicodeDecodeError: # pragma: no cover
7776
pass
7877
raise RuntimeError(
79-
_("Unable to find the PowerShell user profile.")
78+
"Unable to find the PowerShell user profile."
8079
) # pragma: no cover
8180

8281
def install(self) -> Path:

django_typer/types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def set_no_color(context, param, value):
3333
context.django_command.no_color = value
3434
if context.params.get("force_color", False):
3535
raise CommandError(
36-
_("The --no-color and --force-color options can't be used together.")
36+
"The --no-color and --force-color options can't be used together."
3737
)
3838
return value
3939

0 commit comments

Comments
 (0)