Skip to content

Commit 56c58c7

Browse files
committed
chore: improve type annotations
Fix some issues discovered by ty type checker.
1 parent 0ec2d79 commit 56c58c7

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

weblate/screenshots/views.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
from weblate.utils.views import PathViewMixin
3232

3333
if TYPE_CHECKING:
34+
from collections.abc import Generator
35+
3436
from tesserocr import PyTessBaseAPI
3537

3638
from weblate.auth.models import AuthenticatedHttpRequest
@@ -416,7 +418,7 @@ def ocr_extract(api, image: str, strings, resolution: int):
416418

417419

418420
@contextmanager
419-
def get_tesseract(language: Language) -> PyTessBaseAPI:
421+
def get_tesseract(language: Language) -> Generator[PyTessBaseAPI]:
420422
from tesserocr import OEM, PSM, PyTessBaseAPI
421423

422424
# Get matching language

weblate/trans/models/unit.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ class OldUnit(TypedDict):
387387
context: str
388388
extra_flags: str
389389
explanation: str
390+
automatically_translated: bool
390391

391392

392393
class UnitAttributesDict(TypedDict):
@@ -615,11 +616,11 @@ def invalidate_checks_cache(self) -> None:
615616
if key in self.__dict__:
616617
del self.__dict__[key]
617618

618-
def save_labels(self, new_labels: list[Label], user: User) -> None:
619+
def save_labels(self, labels: list[Label], user: User) -> None:
619620
"""Save new labels for the unit."""
620621
old_labels = set(self.labels.all())
621622

622-
self.labels.set(new_labels)
623+
self.labels.set(labels)
623624

624625
new_labels = set(self.labels.all())
625626

weblate/utils/environment.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,43 @@
77
import ast
88
import os
99
from pathlib import Path
10-
from typing import Any
10+
from typing import Any, Literal, overload
1111
from urllib.parse import quote
1212

1313
from django.core.exceptions import ImproperlyConfigured
1414

1515

16+
@overload
1617
def get_env_str(
1718
name: str,
18-
default: str | None = None,
19+
default: str,
20+
*,
1921
required: bool = False,
2022
fallback_name: str | None = None,
21-
) -> str:
23+
) -> str: ...
24+
@overload
25+
def get_env_str(
26+
name: str,
27+
default: None = None,
28+
*,
29+
required: Literal[True],
30+
fallback_name: str | None = None,
31+
) -> str: ...
32+
@overload
33+
def get_env_str(
34+
name: str,
35+
default: None = None,
36+
*,
37+
required: bool = False,
38+
fallback_name: str | None = None,
39+
) -> str | None: ...
40+
def get_env_str(
41+
name,
42+
default=None,
43+
*,
44+
required=False,
45+
fallback_name=None,
46+
):
2247
file_env = f"{name}_FILE"
2348
if filename := os.environ.get(file_env):
2449
try:

0 commit comments

Comments
 (0)