4
4
5
5
"""Weblate API client library."""
6
6
7
+ from __future__ import annotations
7
8
import json
8
9
import logging
9
10
from copy import copy
10
- from typing import Any , ClassVar , Collection , Dict , Optional , Set , Tuple , cast
11
+ from typing import Any , ClassVar , Collection , cast
11
12
from urllib .parse import urlencode , urlparse
12
13
13
14
import dateutil .parser
30
31
class WeblateException (Exception ):
31
32
"""Generic error."""
32
33
33
- def __init__ (self , message : Optional [ str ] = None ):
34
+ def __init__ (self , message : str | None = None ):
34
35
super ().__init__ (message or self .__doc__ )
35
36
36
37
@@ -67,8 +68,8 @@ def __init__(
67
68
url : str = API_URL ,
68
69
config = None ,
69
70
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 ,
72
73
backoff_factor : int = 0 ,
73
74
timeout : int = 300 ,
74
75
):
@@ -365,9 +366,9 @@ def _should_verify_ssl(path):
365
366
class LazyObject (dict ):
366
367
"""Object which supports deferred loading."""
367
368
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 ]] = {}
371
372
ID : ClassVar [str ] = "url"
372
373
373
374
def __init__ (self , weblate , url , ** kwargs ):
@@ -467,14 +468,14 @@ def to_value(self):
467
468
class Language (LazyObject ):
468
469
"""Language object."""
469
470
470
- PARAMS : ClassVar [Tuple [str , ...]] = ("url" , "web_url" , "code" , "name" , "direction" )
471
+ PARAMS : ClassVar [tuple [str , ...]] = ("url" , "web_url" , "code" , "name" , "direction" )
471
472
ID : ClassVar [str ] = "code"
472
473
473
474
474
475
class LanguageStats (LazyObject ):
475
476
"""Language object."""
476
477
477
- PARAMS : ClassVar [Tuple [str , ...]] = (
478
+ PARAMS : ClassVar [tuple [str , ...]] = (
478
479
"total" ,
479
480
"code" ,
480
481
"translated_words" ,
@@ -518,7 +519,7 @@ def cleanup(self):
518
519
class ProjectRepository (LazyObject , RepoMixin ):
519
520
"""Repository object."""
520
521
521
- PARAMS : ClassVar [Tuple [str , ...]] = (
522
+ PARAMS : ClassVar [tuple [str , ...]] = (
522
523
"url" ,
523
524
"needs_commit" ,
524
525
"needs_merge" ,
@@ -533,7 +534,7 @@ def _get_repo_url(self):
533
534
class Repository (ProjectRepository ):
534
535
"""Repository object."""
535
536
536
- PARAMS : ClassVar [Tuple [str , ...]] = (
537
+ PARAMS : ClassVar [tuple [str , ...]] = (
537
538
"url" ,
538
539
"needs_commit" ,
539
540
"needs_merge" ,
@@ -558,17 +559,17 @@ def repository(self):
558
559
class Project (LazyObject , RepoObjectMixin ):
559
560
"""Project object."""
560
561
561
- PARAMS : ClassVar [Tuple [str , ...]] = (
562
+ PARAMS : ClassVar [tuple [str , ...]] = (
562
563
"url" ,
563
564
"web_url" ,
564
565
"name" ,
565
566
"slug" ,
566
567
"web" ,
567
568
"source_language" ,
568
569
)
569
- OPTIONALS : ClassVar [Set [str ]] = {"source_language" }
570
+ OPTIONALS : ClassVar [set [str ]] = {"source_language" }
570
571
ID : ClassVar [str ] = "slug"
571
- MAPPINGS : ClassVar [Dict [str , Any ]] = {"source_language" : Language }
572
+ MAPPINGS : ClassVar [dict [str , Any ]] = {"source_language" : Language }
572
573
573
574
def list (self ):
574
575
"""List components in the project."""
@@ -607,14 +608,14 @@ def create_component(self, **kwargs):
607
608
class Category (LazyObject ):
608
609
"""Category object."""
609
610
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 }
612
613
613
614
614
615
class Component (LazyObject , RepoObjectMixin ):
615
616
"""Component object."""
616
617
617
- PARAMS : ClassVar [Tuple [str , ...]] = (
618
+ PARAMS : ClassVar [tuple [str , ...]] = (
618
619
"url" ,
619
620
"web_url" ,
620
621
"name" ,
@@ -638,14 +639,14 @@ class Component(LazyObject, RepoObjectMixin):
638
639
"category" ,
639
640
"linked_component" ,
640
641
)
641
- OPTIONALS : ClassVar [Set [str ]] = {
642
+ OPTIONALS : ClassVar [set [str ]] = {
642
643
"source_language" ,
643
644
"is_glossary" ,
644
645
"category" ,
645
646
"linked_component" ,
646
647
}
647
648
ID : ClassVar [str ] = "slug"
648
- MAPPINGS : ClassVar [Dict [str , Any ]] = {
649
+ MAPPINGS : ClassVar [dict [str , Any ]] = {
649
650
"category" : Category ,
650
651
"project" : Project ,
651
652
"source_language" : Language ,
@@ -720,7 +721,7 @@ def patch(self, **kwargs):
720
721
class Translation (LazyObject , RepoObjectMixin ):
721
722
"""Translation object."""
722
723
723
- PARAMS : ClassVar [Tuple [str , ...]] = (
724
+ PARAMS : ClassVar [tuple [str , ...]] = (
724
725
"url" ,
725
726
"web_url" ,
726
727
"language" ,
@@ -748,7 +749,7 @@ class Translation(LazyObject, RepoObjectMixin):
748
749
"last_author" ,
749
750
)
750
751
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 }
752
753
REPOSITORY_CLASS = Repository
753
754
754
755
def list (self ):
@@ -797,7 +798,7 @@ def units(self, **kwargs):
797
798
class Statistics (LazyObject ):
798
799
"""Statistics object."""
799
800
800
- PARAMS : ClassVar [Tuple [str , ...]] = (
801
+ PARAMS : ClassVar [tuple [str , ...]] = (
801
802
"failing_percent" ,
802
803
"translated_percent" ,
803
804
"total_words" ,
@@ -817,13 +818,13 @@ class Statistics(LazyObject):
817
818
class TranslationStatistics (Statistics ):
818
819
"""Translation statistics."""
819
820
820
- PARAMS : ClassVar [Tuple [str , ...]] = (* Statistics .PARAMS , "code" , "last_author" )
821
+ PARAMS : ClassVar [tuple [str , ...]] = (* Statistics .PARAMS , "code" , "last_author" )
821
822
822
823
823
824
class Change (LazyObject ):
824
825
"""Change object."""
825
826
826
- PARAMS : ClassVar [Tuple [str , ...]] = (
827
+ PARAMS : ClassVar [tuple [str , ...]] = (
827
828
"url" ,
828
829
"unit" ,
829
830
"translation" ,
@@ -833,7 +834,7 @@ class Change(LazyObject):
833
834
"target" ,
834
835
)
835
836
ID : ClassVar [str ] = "id"
836
- MAPPINGS : ClassVar [Dict [str , Any ]] = {
837
+ MAPPINGS : ClassVar [dict [str , Any ]] = {
837
838
"translation" : Translation ,
838
839
"component" : Component ,
839
840
}
@@ -842,7 +843,7 @@ class Change(LazyObject):
842
843
class Unit (LazyObject ):
843
844
"""Unit object."""
844
845
845
- PARAMS : ClassVar [Tuple [str , ...]] = (
846
+ PARAMS : ClassVar [tuple [str , ...]] = (
846
847
"approved" ,
847
848
"content_hash" ,
848
849
"context" ,
@@ -871,7 +872,7 @@ class Unit(LazyObject):
871
872
"web_url" ,
872
873
)
873
874
ID : ClassVar [str ] = "id"
874
- MAPPINGS : ClassVar [Dict [str , Any ]] = {"translation" : Translation }
875
+ MAPPINGS : ClassVar [dict [str , Any ]] = {"translation" : Translation }
875
876
876
877
def list (self ):
877
878
"""API compatibility method, returns self."""
0 commit comments