Skip to content

Commit

Permalink
chore: fix type annotations ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Nov 15, 2024
1 parent dd74145 commit 90fc25f
Show file tree
Hide file tree
Showing 34 changed files with 84 additions and 84 deletions.
20 changes: 10 additions & 10 deletions weblate/accounts/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def __init__(
) -> None:
self.outgoing: list[OutgoingEmail] = outgoing
self.subscription_cache: dict[
tuple[str | None | int, ...], QuerySet[Subscription]
tuple[str | int | None, ...], QuerySet[Subscription]
] = {}
self.child_notify: list[Notification] | None = None
if perm_cache is not None:
Expand All @@ -115,7 +115,7 @@ def __init__(

def get_language_filter(
self, change: Change, translation: Translation
) -> None | Language:
) -> Language | None:
if self.filter_languages:
return translation.language
return None
Expand All @@ -134,11 +134,11 @@ def get_name(cls):

def filter_subscriptions(
self,
project: None | Project,
component: None | Component,
translation: None | Translation,
project: Project | None,
component: Component | None,
translation: Translation | None,
users: list[int] | None,
lang_filter: None | Language,
lang_filter: Language | None,
) -> QuerySet[Subscription]:
from weblate.accounts.models import Subscription

Expand Down Expand Up @@ -648,10 +648,10 @@ class LastAuthorCommentNotificaton(Notification):
def get_users(
self,
frequency: int,
change: None | Change = None,
project: None | Project = None,
component: None | Component = None,
translation: None | Translation = None,
change: Change | None = None,
project: Project | None = None,
component: Component | None = None,
translation: Translation | None = None,
users: list[int] | None = None,
):
last_author = change.unit.get_last_content_change()[0]
Expand Down
2 changes: 1 addition & 1 deletion weblate/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ def fake_email_sent(request: AuthenticatedHttpRequest, reset: bool = False):
def register(request: AuthenticatedHttpRequest):
"""Registration form."""
# Fetch invitation
invitation: None | Invitation = None
invitation: Invitation | None = None
initial = {}
if invitation_pk := request.session.get("invitation_link"):
try:
Expand Down
4 changes: 2 additions & 2 deletions weblate/addons/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class BaseAddon:
"""Base class for Weblate add-ons."""

events: tuple[AddonEvent, ...] = ()
settings_form: None | type[BaseAddonForm] = None
settings_form: type[BaseAddonForm] | None = None
name = ""
compat: CompatDict = {}
multiple = False
Expand Down Expand Up @@ -292,7 +292,7 @@ def component_update(self, component: Component) -> None:
# To be implemented in a subclass

def execute_process(
self, component: Component, cmd: list[str], env: None | dict[str, str] = None
self, component: Component, cmd: list[str], env: dict[str, str] | None = None
) -> None:
component.log_debug("%s add-on exec: %s", self.name, " ".join(cmd))
try:
Expand Down
2 changes: 1 addition & 1 deletion weblate/addons/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BaseScriptAddon(BaseAddon):

icon = "script.svg"
script: str
add_file: None | str = None
add_file: str | None = None
alert = "AddonScriptError"

def run_script(self, component=None, translation=None, env=None) -> None:
Expand Down
2 changes: 1 addition & 1 deletion weblate/addons/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AddonList(PathViewMixin, ListView):
paginate_by = None
model = Addon
supported_path_types = (None, Component, Project)
path_object: None | Component | Project
path_object: Component | Project | None
request: AuthenticatedHttpRequest

def get_queryset(self):
Expand Down
2 changes: 1 addition & 1 deletion weblate/checks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class BaseCheck:
def get_identifier(self) -> str:
return self.check_id

def get_propagated_value(self, unit: Unit) -> None | str:
def get_propagated_value(self, unit: Unit) -> str | None:
return None

def get_propagated_units(
Expand Down
2 changes: 1 addition & 1 deletion weblate/checks/consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ConsistencyCheck(TargetCheck, BatchCheckMixin):
batch_project_wide = True
skip_suggestions = True

def get_propagated_value(self, unit: Unit) -> None | str:
def get_propagated_value(self, unit: Unit) -> str | None:
return unit.target

def get_propagated_units(
Expand Down
6 changes: 3 additions & 3 deletions weblate/checks/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def __init__(self, *args) -> None:
self.merge(flags)

def get_items(
self, flags: None | str | etree._Element | Flags | tuple[str | tuple[Any, ...]]
self, flags: str | etree._Element | Flags | tuple[str | tuple[Any, ...]] | None
) -> tuple[str | tuple[Any, ...], ...]:
if flags is None:
return ()
Expand All @@ -199,7 +199,7 @@ def get_items(
return flags

def merge(
self, flags: None | str | etree._Element | Flags | tuple[str | tuple[Any, ...]]
self, flags: str | etree._Element | Flags | tuple[str | tuple[Any, ...]] | None
) -> None:
for flag in self.get_items(flags):
if isinstance(flag, tuple):
Expand All @@ -209,7 +209,7 @@ def merge(
self._items[flag] = flag

def remove(
self, flags: None | str | etree._Element | Flags | tuple[str | tuple[Any, ...]]
self, flags: str | etree._Element | Flags | tuple[str | tuple[Any, ...]] | None
) -> None:
for flag in self.get_items(flags):
if isinstance(flag, tuple):
Expand Down
2 changes: 1 addition & 1 deletion weblate/checks/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class MaxSizeCheck(TargetCheckParametrized):
def param_type(self):
return multi_value_flag(int, 1, 2)

def get_params(self, unit: Unit) -> tuple[str, None | int, int, int]:
def get_params(self, unit: Unit) -> tuple[str, int | None, int, int]:
all_flags = unit.all_flags
return (
all_flags.get_value_fallback("font-family", "sans"),
Expand Down
14 changes: 7 additions & 7 deletions weblate/checks/tests/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,24 +147,24 @@ def source_string(self):
class CheckTestCase(SimpleTestCase):
"""Generic test, also serves for testing base class."""

check: None | BaseCheck = None
check: BaseCheck | None = None
default_lang = "cs"

def setUp(self) -> None:
self.test_empty: tuple[str, str, str] = ("", "", "")
self.test_good_matching: tuple[str, str, str] = ("string", "string", "")
self.test_good_none: tuple[str, str, str] = ("string", "string", "")
self.test_good_ignore: None | tuple[str, str, str] = None
self.test_good_flag: None | tuple[str, str, str] = None
self.test_failure_1: None | tuple[str, str, str] = None
self.test_failure_2: None | tuple[str, str, str] = None
self.test_failure_3: None | tuple[str, str, str] = None
self.test_good_ignore: tuple[str, str, str] | None = None
self.test_good_flag: tuple[str, str, str] | None = None
self.test_failure_1: tuple[str, str, str] | None = None
self.test_failure_2: tuple[str, str, str] | None = None
self.test_failure_3: tuple[str, str, str] | None = None
self.test_ignore_check: tuple[str, str, str] = (
"x",
"x",
self.check.ignore_string if self.check else "",
)
self.test_highlight: None | tuple[str, str, list[tuple[int, int, str]]] = None
self.test_highlight: tuple[str, str, list[tuple[int, int, str]]] | None = None

def do_test(self, expected, data, lang=None) -> None:
"""Perform single check if we have data to test."""
Expand Down
2 changes: 1 addition & 1 deletion weblate/checks/tests/test_icu_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ICUMessageFormatCheckTest(CheckTestCase):

id_hash: str = "icu_message_format"
flag: str = "icu-message-format"
flags: None | str = None
flags: str | None = None

def get_mock(
self, source: str | list[str] | None = None, flags: str | None = None
Expand Down
6 changes: 3 additions & 3 deletions weblate/formats/ttkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class TTKitFormat(TranslationFormat):
set_context_bilingual = True
# Use settarget/setsource to set language as well
use_settarget = False
force_encoding: None | str = None
force_encoding: str | None = None
plural_preference: tuple[int, ...] | None = (
Plural.SOURCE_CLDR,
Plural.SOURCE_DEFAULT,
Expand Down Expand Up @@ -1629,7 +1629,7 @@ def get_content_and_filename(storefile):
content = handle.read()
return content, filename

def parse_store(self, storefile, *, dialect: None | str = None):
def parse_store(self, storefile, *, dialect: str | None = None):
"""Parse the store."""
content, filename = self.get_content_and_filename(storefile)

Expand Down Expand Up @@ -1660,7 +1660,7 @@ def parse_store(self, storefile, *, dialect: None | str = None):

return self.parse_simple_csv(content, filename, header=header)

def parse_simple_csv(self, content, filename, header: None | list[str] = None):
def parse_simple_csv(self, content, filename, header: list[str] | None = None):
fieldnames = ["source", "target"]
if header and all(
field in {"source", "target", "context", "id"} for field in header
Expand Down
16 changes: 8 additions & 8 deletions weblate/machinery/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class TranslationResultDict(TypedDict):
class UnitMemoryResultDict(TypedDict, total=False):
quality: list[int]
translation: list[str]
origin: list[None | BatchMachineTranslation]
origin: list[BatchMachineTranslation] | None


DownloadTranslations = Iterable[TranslationResultDict]
Expand All @@ -116,7 +116,7 @@ class BatchMachineTranslation:
accounting_key = "external"
force_uncleanup = False
hightlight_syntax = False
settings_form: None | type[BaseMachineryForm] = None
settings_form: type[BaseMachineryForm] | None = None
request_timeout = 5
is_available = True
replacement_start = "[X"
Expand All @@ -132,7 +132,7 @@ def __init__(self, settings: SettingsDict) -> None:
self.rate_limit_cache = f"{self.mtid}-rate-limit"
self.languages_cache = f"{self.mtid}-languages"
self.comparer = Comparer()
self.supported_languages_error: None | Exception = None
self.supported_languages_error: Exception | None = None
self.supported_languages_error_age: float = 0
self.settings = settings

Expand Down Expand Up @@ -185,7 +185,7 @@ def get_headers(self) -> dict[str, str]:
"""Add authentication headers to request."""
return {}

def get_auth(self) -> None | tuple[str, str] | AuthBase:
def get_auth(self) -> tuple[str, str] | AuthBase | None:
return None

def check_failure(self, response) -> None:
Expand Down Expand Up @@ -292,7 +292,7 @@ def is_rate_limit_error(self, exc) -> bool:
return exc.response.status_code in {456, 429, 401, 403, 503}

def get_cache_key(
self, scope: str, *, parts: Iterable[str | int] = (), text: None | str = None
self, scope: str, *, parts: Iterable[str | int] = (), text: str | None = None
) -> str:
"""
Cache key for caching translations.
Expand Down Expand Up @@ -328,14 +328,14 @@ def make_re_placeholder(self, text: str):
return re.escape(text[:-1]) + " *" + re.escape(text[-1:])

def format_replacement(
self, h_start: int, h_end: int, h_text: str, h_kind: None | Unit
self, h_start: int, h_end: int, h_text: str, h_kind: Unit | None
) -> str:
"""Generate a single replacement."""
return f"{self.replacement_start}{h_start}{self.replacement_end}"

def get_highlights(
self, text: str, unit
) -> Iterable[tuple[int, int, str, None | Unit]]:
) -> Iterable[tuple[int, int, str, Unit | None]]:
for h_start, h_end, h_text in highlight_string(
text, unit, hightlight_syntax=self.hightlight_syntax
):
Expand Down Expand Up @@ -812,7 +812,7 @@ def escape_text(self, text: str) -> str:
return escape(text)

def format_replacement(
self, h_start: int, h_end: int, h_text: str, h_kind: None | Unit
self, h_start: int, h_end: int, h_text: str, h_kind: Unit | None
) -> str:
"""Generate a single replacement."""
raise NotImplementedError
Expand Down
2 changes: 1 addition & 1 deletion weblate/machinery/deepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def download_multiple_translations(
return result

def format_replacement(
self, h_start: int, h_end: int, h_text: str, h_kind: None | Unit
self, h_start: int, h_end: int, h_text: str, h_kind: Unit | None
) -> str:
"""Generate a single replacement."""
return f'<x id="{h_start}"></x>'
Expand Down
2 changes: 1 addition & 1 deletion weblate/machinery/googlev3.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def download_translations(
}

def format_replacement(
self, h_start: int, h_end: int, h_text: str, h_kind: None | Unit
self, h_start: int, h_end: int, h_text: str, h_kind: Unit | None
) -> str:
"""Generate a single replacement."""
return f'<span translate="no" id="{h_start}">{self.escape_text(h_text)}</span>'
Expand Down
2 changes: 1 addition & 1 deletion weblate/machinery/ibm.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_identifier(cls) -> str:
def get_headers(self) -> dict[str, str]:
return {"Content-Type": "application/json"}

def get_auth(self) -> None | tuple[str, str] | AuthBase:
def get_auth(self) -> tuple[str, str] | AuthBase | None:
return ("apikey", self.settings["key"])

def download_languages(self):
Expand Down
6 changes: 3 additions & 3 deletions weblate/machinery/microsoft.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def get_identifier(cls) -> str:
def __init__(self, settings: SettingsDict) -> None:
"""Check configuration."""
super().__init__(settings)
self._access_token: None | str = None
self._token_expiry: None | datetime = None
self._access_token: str | None = None
self._token_expiry: datetime | None = None

# check settings for Microsoft region prefix
region = "" if not self.settings["region"] else f"{self.settings['region']}."
Expand Down Expand Up @@ -153,7 +153,7 @@ def download_translations(
}

def format_replacement(
self, h_start: int, h_end: int, h_text: str, h_kind: None | Unit
self, h_start: int, h_end: int, h_text: str, h_kind: Unit | None
):
"""Generate a single replacement."""
if h_kind is None:
Expand Down
2 changes: 1 addition & 1 deletion weblate/machinery/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def __init__(self, settings=None) -> None:
timeout=self.request_timeout,
base_url=self.settings.get("base_url") or None,
)
self._models: None | set[str] = None
self._models: set[str] | None = None

def get_model(self) -> str:
if self._models is None:
Expand Down
2 changes: 1 addition & 1 deletion weblate/machinery/saptranslationhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_headers(self):

return result

def get_auth(self) -> None | tuple[str, str] | AuthBase:
def get_auth(self) -> tuple[str, str] | AuthBase | None:
# to access the productive API
if self.settings["username"] and self.settings["password"]:
return (self.settings["username"], self.settings["password"])
Expand Down
2 changes: 1 addition & 1 deletion weblate/machinery/tmserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TMServerTranslation(MachineTranslation):
"""tmserver machine translation support."""

name = "tmserver"
settings_form: None | type[BaseMachineryForm] = URLMachineryForm
settings_form: type[BaseMachineryForm] | None = URLMachineryForm

def map_language_code(self, code):
"""Convert language to service specific code."""
Expand Down
2 changes: 1 addition & 1 deletion weblate/machinery/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def get_context_data(self, **kwargs):


def format_string_helper(
source: str, translation: Translation, diff: None | str = None
source: str, translation: Translation, diff: str | None = None
):
return format_language_string(source, translation, diff=diff)["items"][0]["content"]

Expand Down
2 changes: 1 addition & 1 deletion weblate/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def apply_csp_settings(self) -> None:
if value:
self.directives[rule].update(value)

def add_csp_host(self, url: str, *directives: CSP_KIND) -> None | str:
def add_csp_host(self, url: str, *directives: CSP_KIND) -> str | None:
domain = urlparse(url).hostname
# Handle domain only URLs (OpenInfraOpenId uses that)
if not domain and ":" not in url and "/" not in url:
Expand Down
4 changes: 2 additions & 2 deletions weblate/trans/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def __init__(self, unit_set, *args, **kwargs) -> None:
self.unit_set = unit_set
super().__init__(*args, **kwargs)

def clean_checksum(self) -> None | str:
def clean_checksum(self) -> str | None:
"""Validate whether checksum is valid and fetches unit for it."""
if "checksum" not in self.cleaned_data:
return None
Expand Down Expand Up @@ -2993,7 +2993,7 @@ def __init__(
),
)

def clean_translation_review(self) -> None | bool:
def clean_translation_review(self) -> bool | None:
if "translation_review" not in self.cleaned_data:
return None
translation_review = self.cleaned_data["translation_review"]
Expand Down
Loading

0 comments on commit 90fc25f

Please sign in to comment.