Remove remaining bare _ translation references (#3485)

This helps simplify the linter configs and improves compatibility
with type checkers.
This commit is contained in:
correctmost 2025-05-20 04:44:25 -04:00 committed by GitHub
parent a945606834
commit 3e5f879d52
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 10 deletions

View File

@ -5,5 +5,4 @@ max-complexity = 40
max-line-length = 160 max-line-length = 160
show-source = True show-source = True
statistics = True statistics = True
builtins = _
exclude = .git,__pycache__,build,docs,actions-runner exclude = .git,__pycache__,build,docs,actions-runner

View File

@ -6,10 +6,7 @@ import json
import os import os
from dataclasses import dataclass from dataclasses import dataclass
from pathlib import Path from pathlib import Path
from typing import TYPE_CHECKING, Any, override from typing import override
if TYPE_CHECKING:
_: Any
@dataclass @dataclass
@ -136,6 +133,7 @@ class TranslationHandler:
""" """
Set the provided language as the current translation Set the provided language as the current translation
""" """
# The install() call has the side effect of assigning GNUTranslations.gettext to builtins._
language.translation.install() language.translation.install()
def _get_locales_dir(self) -> Path: def _get_locales_dir(self) -> Path:
@ -170,10 +168,12 @@ class _DeferredTranslation:
@override @override
def __str__(self) -> str: def __str__(self) -> str:
translate = _ if builtins._ is _DeferredTranslation: # type: ignore[attr-defined]
if translate is _DeferredTranslation:
return self.message return self.message
return translate(self.message)
# builtins._ is changed from _DeferredTranslation to GNUTranslations.gettext after
# Language.activate() is called
return builtins._(self.message) # type: ignore[attr-defined]
def __lt__(self, other) -> bool: def __lt__(self, other) -> bool:
return self.message < other return self.message < other

View File

@ -171,12 +171,10 @@ disable = [
score = false score = false
[tool.pylint.variables] [tool.pylint.variables]
additional-builtins = ["_"]
init-import = true init-import = true
[tool.ruff] [tool.ruff]
target-version = "py312" target-version = "py312"
builtins = ["_"]
line-length = 160 line-length = 160
[tool.ruff.format] [tool.ruff.format]