Skip to content

Commit ec4d71d

Browse files
committed
chore: use future type annotations
1 parent 66cadfc commit ec4d71d

7 files changed

+41
-34
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ select = [
127127
"N"
128128
]
129129

130-
[tool.ruff.mccabe]
130+
[tool.ruff.lint.mccabe]
131131
max-complexity = 16
132132

133133
[tool.setuptools]

wlc/__init__.py

+28-27
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
"""Weblate API client library."""
66

7+
from __future__ import annotations
78
import json
89
import logging
910
from copy import copy
10-
from typing import Any, ClassVar, Collection, Dict, Optional, Set, Tuple, cast
11+
from typing import Any, ClassVar, Collection, cast
1112
from urllib.parse import urlencode, urlparse
1213

1314
import dateutil.parser
@@ -30,7 +31,7 @@
3031
class WeblateException(Exception):
3132
"""Generic error."""
3233

33-
def __init__(self, message: Optional[str] = None):
34+
def __init__(self, message: str | None = None):
3435
super().__init__(message or self.__doc__)
3536

3637

@@ -67,8 +68,8 @@ def __init__(
6768
url: str = API_URL,
6869
config=None,
6970
retries: int = 0,
70-
status_forcelist: Optional[Collection[int]] = None,
71-
method_whitelist: Optional[Collection[str]] = None,
71+
status_forcelist: Collection[int] | None = None,
72+
method_whitelist: Collection[str] | None = None,
7273
backoff_factor: int = 0,
7374
timeout: int = 300,
7475
):
@@ -365,9 +366,9 @@ def _should_verify_ssl(path):
365366
class LazyObject(dict):
366367
"""Object which supports deferred loading."""
367368

368-
PARAMS: ClassVar[Tuple[str, ...]] = ()
369-
OPTIONALS: ClassVar[Set[str]] = set()
370-
MAPPINGS: ClassVar[Dict[str, Any]] = {}
369+
PARAMS: ClassVar[tuple[str, ...]] = ()
370+
OPTIONALS: ClassVar[set[str]] = set()
371+
MAPPINGS: ClassVar[dict[str, Any]] = {}
371372
ID: ClassVar[str] = "url"
372373

373374
def __init__(self, weblate, url, **kwargs):
@@ -467,14 +468,14 @@ def to_value(self):
467468
class Language(LazyObject):
468469
"""Language object."""
469470

470-
PARAMS: ClassVar[Tuple[str, ...]] = ("url", "web_url", "code", "name", "direction")
471+
PARAMS: ClassVar[tuple[str, ...]] = ("url", "web_url", "code", "name", "direction")
471472
ID: ClassVar[str] = "code"
472473

473474

474475
class LanguageStats(LazyObject):
475476
"""Language object."""
476477

477-
PARAMS: ClassVar[Tuple[str, ...]] = (
478+
PARAMS: ClassVar[tuple[str, ...]] = (
478479
"total",
479480
"code",
480481
"translated_words",
@@ -518,7 +519,7 @@ def cleanup(self):
518519
class ProjectRepository(LazyObject, RepoMixin):
519520
"""Repository object."""
520521

521-
PARAMS: ClassVar[Tuple[str, ...]] = (
522+
PARAMS: ClassVar[tuple[str, ...]] = (
522523
"url",
523524
"needs_commit",
524525
"needs_merge",
@@ -533,7 +534,7 @@ def _get_repo_url(self):
533534
class Repository(ProjectRepository):
534535
"""Repository object."""
535536

536-
PARAMS: ClassVar[Tuple[str, ...]] = (
537+
PARAMS: ClassVar[tuple[str, ...]] = (
537538
"url",
538539
"needs_commit",
539540
"needs_merge",
@@ -558,17 +559,17 @@ def repository(self):
558559
class Project(LazyObject, RepoObjectMixin):
559560
"""Project object."""
560561

561-
PARAMS: ClassVar[Tuple[str, ...]] = (
562+
PARAMS: ClassVar[tuple[str, ...]] = (
562563
"url",
563564
"web_url",
564565
"name",
565566
"slug",
566567
"web",
567568
"source_language",
568569
)
569-
OPTIONALS: ClassVar[Set[str]] = {"source_language"}
570+
OPTIONALS: ClassVar[set[str]] = {"source_language"}
570571
ID: ClassVar[str] = "slug"
571-
MAPPINGS: ClassVar[Dict[str, Any]] = {"source_language": Language}
572+
MAPPINGS: ClassVar[dict[str, Any]] = {"source_language": Language}
572573

573574
def list(self):
574575
"""List components in the project."""
@@ -607,14 +608,14 @@ def create_component(self, **kwargs):
607608
class Category(LazyObject):
608609
"""Category object."""
609610

610-
PARAMS: ClassVar[Tuple[str, ...]] = ("category", "name", "project", "slug", "url")
611-
MAPPINGS: ClassVar[Dict[str, Any]] = {"project": Project}
611+
PARAMS: ClassVar[tuple[str, ...]] = ("category", "name", "project", "slug", "url")
612+
MAPPINGS: ClassVar[dict[str, Any]] = {"project": Project}
612613

613614

614615
class Component(LazyObject, RepoObjectMixin):
615616
"""Component object."""
616617

617-
PARAMS: ClassVar[Tuple[str, ...]] = (
618+
PARAMS: ClassVar[tuple[str, ...]] = (
618619
"url",
619620
"web_url",
620621
"name",
@@ -638,14 +639,14 @@ class Component(LazyObject, RepoObjectMixin):
638639
"category",
639640
"linked_component",
640641
)
641-
OPTIONALS: ClassVar[Set[str]] = {
642+
OPTIONALS: ClassVar[set[str]] = {
642643
"source_language",
643644
"is_glossary",
644645
"category",
645646
"linked_component",
646647
}
647648
ID: ClassVar[str] = "slug"
648-
MAPPINGS: ClassVar[Dict[str, Any]] = {
649+
MAPPINGS: ClassVar[dict[str, Any]] = {
649650
"category": Category,
650651
"project": Project,
651652
"source_language": Language,
@@ -720,7 +721,7 @@ def patch(self, **kwargs):
720721
class Translation(LazyObject, RepoObjectMixin):
721722
"""Translation object."""
722723

723-
PARAMS: ClassVar[Tuple[str, ...]] = (
724+
PARAMS: ClassVar[tuple[str, ...]] = (
724725
"url",
725726
"web_url",
726727
"language",
@@ -748,7 +749,7 @@ class Translation(LazyObject, RepoObjectMixin):
748749
"last_author",
749750
)
750751
ID: ClassVar[str] = "language_code"
751-
MAPPINGS: ClassVar[Dict[str, Any]] = {"language": Language, "component": Component}
752+
MAPPINGS: ClassVar[dict[str, Any]] = {"language": Language, "component": Component}
752753
REPOSITORY_CLASS = Repository
753754

754755
def list(self):
@@ -797,7 +798,7 @@ def units(self, **kwargs):
797798
class Statistics(LazyObject):
798799
"""Statistics object."""
799800

800-
PARAMS: ClassVar[Tuple[str, ...]] = (
801+
PARAMS: ClassVar[tuple[str, ...]] = (
801802
"failing_percent",
802803
"translated_percent",
803804
"total_words",
@@ -817,13 +818,13 @@ class Statistics(LazyObject):
817818
class TranslationStatistics(Statistics):
818819
"""Translation statistics."""
819820

820-
PARAMS: ClassVar[Tuple[str, ...]] = (*Statistics.PARAMS, "code", "last_author")
821+
PARAMS: ClassVar[tuple[str, ...]] = (*Statistics.PARAMS, "code", "last_author")
821822

822823

823824
class Change(LazyObject):
824825
"""Change object."""
825826

826-
PARAMS: ClassVar[Tuple[str, ...]] = (
827+
PARAMS: ClassVar[tuple[str, ...]] = (
827828
"url",
828829
"unit",
829830
"translation",
@@ -833,7 +834,7 @@ class Change(LazyObject):
833834
"target",
834835
)
835836
ID: ClassVar[str] = "id"
836-
MAPPINGS: ClassVar[Dict[str, Any]] = {
837+
MAPPINGS: ClassVar[dict[str, Any]] = {
837838
"translation": Translation,
838839
"component": Component,
839840
}
@@ -842,7 +843,7 @@ class Change(LazyObject):
842843
class Unit(LazyObject):
843844
"""Unit object."""
844845

845-
PARAMS: ClassVar[Tuple[str, ...]] = (
846+
PARAMS: ClassVar[tuple[str, ...]] = (
846847
"approved",
847848
"content_hash",
848849
"context",
@@ -871,7 +872,7 @@ class Unit(LazyObject):
871872
"web_url",
872873
)
873874
ID: ClassVar[str] = "id"
874-
MAPPINGS: ClassVar[Dict[str, Any]] = {"translation": Translation}
875+
MAPPINGS: ClassVar[dict[str, Any]] = {"translation": Translation}
875876

876877
def list(self):
877878
"""API compatibility method, returns self."""

wlc/config.py

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
"""Weblate API library, configuration."""
66

7+
from __future__ import annotations
8+
79
import os.path
810
from configparser import NoOptionError, RawConfigParser
911

wlc/main.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-License-Identifier: GPL-3.0-or-later
44

55
"""Command-line interface for Weblate."""
6+
from __future__ import annotations
67
import csv
78
import http.client
89
import json
@@ -11,17 +12,17 @@
1112
from argparse import ArgumentParser
1213
from datetime import datetime
1314
from pathlib import Path
14-
from typing import Callable, Dict, List
15+
from typing import Callable
1516

1617
import argcomplete
1718
from requests.exceptions import RequestException
1819

1920
import wlc
2021
from wlc.config import NoOptionError, WeblateConfig
2122

22-
COMMANDS: Dict[str, Callable] = {}
23+
COMMANDS: dict[str, Callable] = {}
2324

24-
SORT_ORDER: List[str] = []
25+
SORT_ORDER: list[str] = []
2526

2627

2728
def register_command(command):

wlc/test_base.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-License-Identifier: GPL-3.0-or-later
44

55
"""Test helpers."""
6+
from __future__ import annotations
67
import os
78
from email import message_from_string
89
from hashlib import blake2b

wlc/test_main.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-License-Identifier: GPL-3.0-or-later
44

55
"""Test command-line interface."""
6+
from __future__ import annotations
67

78
import json
89
import os

wlc/test_wlc.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
# SPDX-License-Identifier: GPL-3.0-or-later
44

55
"""Test the module."""
6+
from __future__ import annotations
67
import io
78
import os
8-
from typing import Any, ClassVar, Dict, Optional
9+
from typing import Any, ClassVar
910

1011
from requests.exceptions import RequestException
1112

@@ -289,7 +290,7 @@ def test_create_component_local_files(self):
289290
class ObjectTestBaseClass(APITest):
290291
"""Base class for objects testing."""
291292

292-
_name: Optional[str] = None
293+
_name: str | None = None
293294
_cls: Any = None
294295

295296
def check_object(self, obj):
@@ -641,7 +642,7 @@ def test_units_search(self):
641642
class UnitTest(ObjectTestBaseClass):
642643
_name = "123"
643644
_cls = Unit
644-
patch_data: ClassVar[Dict[str, Any]] = {
645+
patch_data: ClassVar[dict[str, Any]] = {
645646
"target": ["foo"],
646647
"state": 30,
647648
}

0 commit comments

Comments
 (0)