Skip to content

Commit

Permalink
remove unnecessary translation hooks #18
Browse files Browse the repository at this point in the history
  • Loading branch information
bckohan committed Feb 4, 2025
1 parent 4daaa2c commit 94beebd
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 41 deletions.
3 changes: 1 addition & 2 deletions django_typer/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from django.conf import settings
from django.core.checks import CheckMessage, register
from django.core.checks import Warning as CheckWarning
from django.utils.translation import gettext as _

from .config import traceback_config

Expand Down Expand Up @@ -86,7 +85,7 @@ def check_traceback_config(app_configs, **kwargs) -> t.List[CheckMessage]:
warnings.append(
CheckWarning(
"DT_RICH_TRACEBACK_CONFIG",
hint=_("Unexpected parameters encountered: {keys}.").format(
hint="Unexpected parameters encountered: {keys}.".format(
keys=", ".join(unexpected)
),
obj=settings.SETTINGS_MODULE,
Expand Down
17 changes: 5 additions & 12 deletions django_typer/completers/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from django.conf import settings
from django.db import models
from django.db.models.query import QuerySet
from django.utils.translation import gettext as _


class ModelObjectCompleter:
Expand Down Expand Up @@ -274,11 +273,7 @@ def uuid_query(
self._offset += 1

if len(uuid) > 32:
raise ValueError(
_("Too many UUID characters: {incomplete}").format(
incomplete=incomplete
)
)
raise ValueError(f"Too many UUID characters: {incomplete}")
min_uuid = UUID(uuid + "0" * (32 - len(uuid)))
max_uuid = UUID(uuid + "f" * (32 - len(uuid)))
return models.Q(**{f"{self.lookup_field}__gte": min_uuid}) & models.Q(
Expand All @@ -302,11 +297,11 @@ def _get_date_bounds(self, incomplete: str) -> t.Tuple[date, date]:
day_low = 1
day_high = None
if len(parts) > 1:
assert len(parts[0]) > 3, _("Year must be 4 digits")
assert len(parts[0]) > 3, "Year must be 4 digits"
month_high = min(int(parts[1] + "9" * (2 - len(parts[1]))), 12)
month_low = max(int(parts[1] + "0" * (2 - len(parts[1]))), 1)
if len(parts) > 2:
assert len(parts[1]) > 1, _("Month must be 2 digits")
assert len(parts[1]) > 1, "Month must be 2 digits"
day_low = max(int(parts[2] + "0" * (2 - len(parts[2]))), 1)
day_high = min(
int(parts[2] + "9" * (2 - len(parts[2]))),
Expand Down Expand Up @@ -658,7 +653,7 @@ def __init__(
self._queryset = model_or_qry
else:
raise ValueError(
_("ModelObjectCompleter requires a Django model class or queryset.")
"ModelObjectCompleter requires a Django model class or queryset."
)
self.lookup_field = str(
lookup_field or getattr(self.model_cls._meta.pk, "name", "id")
Expand Down Expand Up @@ -701,9 +696,7 @@ def __init__(
self.query = self.duration_query
else:
raise ValueError(
_("Unsupported lookup field class: {cls}").format(
cls=self._field.__class__.__name__
)
f"Unsupported lookup field class: {self._field.__class__.__name__}"
)

def __call__(
Expand Down
15 changes: 5 additions & 10 deletions django_typer/management/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from django.db.models import Model
from django.db.models.query import QuerySet
from django.utils.functional import Promise, classproperty
from django.utils.translation import gettext as _

from django_typer import patch

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


class OutputWrapper(BaseOutputWrapper):
Expand Down Expand Up @@ -3073,7 +3072,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
sys.exit(exc_val.exit_code)
if isinstance(exc_val, click.exceptions.UsageError):
err_msg = (
_(self.missing_args_message).format(
self.missing_args_message.format(
parameter=getattr(getattr(exc_val, "param", None), "name", "")
)
if isinstance(exc_val, click.exceptions.MissingParameter)
Expand Down Expand Up @@ -3132,9 +3131,7 @@ def __init__(
assert get_typer_command(self.typer_app)
except RuntimeError as rerr:
raise NotImplementedError(
_(
"No commands or command groups were registered on {command}"
).format(command=self._name)
f"No commands or command groups were registered on {self._name}"
) from rerr

def get_subcommand(self, *command_path: str) -> CommandNode:
Expand Down Expand Up @@ -3248,10 +3245,8 @@ def handle(self, option1: bool, option2: bool):
if callable(handle):
return handle(*args, **kwargs)
raise NotImplementedError(
_(
"{cls} does not implement handle(), you must call the other command "
"functions directly."
).format(cls=self.__class__)
f"{self.__class__} does not implement handle(), you must call the other command "
"functions directly."
)

@t.no_type_check
Expand Down
5 changes: 1 addition & 4 deletions django_typer/parsers/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from django.apps import AppConfig, apps
from django.core.management import CommandError
from django.utils.translation import gettext as _


def app_config(label: t.Union[str, AppConfig]):
Expand Down Expand Up @@ -44,9 +43,7 @@ def handle(
if cfg.name == label:
return cfg

raise CommandError(
_("{label} does not match any installed app label.").format(label=label)
) from err
raise CommandError(f"{label} does not match any installed app label.") from err


app_config.__name__ = "APP_LABEL"
13 changes: 3 additions & 10 deletions django_typer/parsers/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from click import Context, Parameter, ParamType
from django.core.management import CommandError
from django.db import models
from django.utils.translation import gettext as _

from django_typer.completers.model import ModelObjectCompleter

Expand Down Expand Up @@ -118,7 +117,7 @@ def __init__(
self.return_type = return_type
self.case_insensitive = case_insensitive
field = self.model_cls._meta.get_field(self.lookup_field)
assert not isinstance(field, (models.ForeignObjectRel, GenericForeignKey)), _(
assert not isinstance(field, (models.ForeignObjectRel, GenericForeignKey)), (
"{cls} is not a supported lookup field."
).format(cls=self._field.__class__.__name__)
self._field = field
Expand Down Expand Up @@ -178,17 +177,11 @@ def convert(
if self.on_error:
return self.on_error(self.model_cls, original, err)
raise CommandError(
_("{value} is not a valid {field}").format(
value=original, field=self._field.__class__.__name__
)
f"{original} is not a valid {self._field.__class__.__name__}"
) from err
except self.model_cls.DoesNotExist as err:
if self.on_error:
return self.on_error(self.model_cls, original, err)
raise CommandError(
_('{model}.{lookup_field}="{value}" does not exist!').format(
model=self.model_cls.__name__,
lookup_field=self.lookup_field,
value=original,
)
f'{self.model_cls.__name__}.{self.lookup_field}="{original}" does not exist!'
) from err
3 changes: 1 addition & 2 deletions django_typer/shells/powershell.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from pathlib import Path

from click.shell_completion import CompletionItem
from django.utils.translation import gettext as _

from . import DjangoTyperShellCompleter

Expand Down Expand Up @@ -76,7 +75,7 @@ def get_user_profile(self) -> Path:
except UnicodeDecodeError: # pragma: no cover
pass
raise RuntimeError(
_("Unable to find the PowerShell user profile.")
"Unable to find the PowerShell user profile."
) # pragma: no cover

def install(self) -> Path:
Expand Down
2 changes: 1 addition & 1 deletion django_typer/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def set_no_color(context, param, value):
context.django_command.no_color = value
if context.params.get("force_color", False):
raise CommandError(
_("The --no-color and --force-color options can't be used together.")
"The --no-color and --force-color options can't be used together."
)
return value

Expand Down

0 comments on commit 94beebd

Please sign in to comment.