1
1
import contextlib
2
- from typing import TYPE_CHECKING , Any , Dict , Generator , List , Set , Union , cast
2
+ from collections .abc import Generator
3
+ from typing import TYPE_CHECKING , Any , Union , cast
3
4
4
5
import attr
5
6
from fluent .syntax import ast as FTL
@@ -42,7 +43,7 @@ class CurrentEnvironment:
42
43
# For Messages, VariableReference nodes are interpreted as external args,
43
44
# but for Terms they are the values explicitly passed using CallExpression
44
45
# syntax. So we have to be able to change 'args' for this purpose.
45
- args : Dict [str , Any ] = attr .ib (factory = dict )
46
+ args : dict [str , Any ] = attr .ib (factory = dict )
46
47
# This controls whether we need to report an error if a VariableReference
47
48
# refers to an arg that is not present in the args dict.
48
49
error_for_missing_arg : bool = attr .ib (default = True )
@@ -51,9 +52,9 @@ class CurrentEnvironment:
51
52
@attr .s
52
53
class ResolverEnvironment :
53
54
context : "FluentBundle" = attr .ib ()
54
- errors : List [Exception ] = attr .ib ()
55
+ errors : list [Exception ] = attr .ib ()
55
56
part_count : int = attr .ib (default = 0 , init = False )
56
- active_patterns : Set [FTL .Pattern ] = attr .ib (factory = set , init = False )
57
+ active_patterns : set [FTL .Pattern ] = attr .ib (factory = set , init = False )
57
58
current : CurrentEnvironment = attr .ib (factory = CurrentEnvironment )
58
59
59
60
@contextlib .contextmanager
@@ -72,7 +73,7 @@ def modified(
72
73
self .current = old_current
73
74
74
75
def modified_for_term_reference (
75
- self , args : Union [Dict [str , Any ], None ] = None
76
+ self , args : Union [dict [str , Any ], None ] = None
76
77
) -> Any :
77
78
return self .modified (
78
79
args = args if args is not None else {}, error_for_missing_arg = False
@@ -100,13 +101,13 @@ class Literal(BaseResolver):
100
101
class Message (FTL .Entry , BaseResolver ):
101
102
id : "Identifier"
102
103
value : Union ["Pattern" , None ]
103
- attributes : Dict [str , "Pattern" ]
104
+ attributes : dict [str , "Pattern" ]
104
105
105
106
def __init__ (
106
107
self ,
107
108
id : "Identifier" ,
108
109
value : Union ["Pattern" , None ] = None ,
109
- attributes : Union [List ["Attribute" ], None ] = None ,
110
+ attributes : Union [list ["Attribute" ], None ] = None ,
110
111
comment : Any = None ,
111
112
** kwargs : Any ,
112
113
):
@@ -121,13 +122,13 @@ def __init__(
121
122
class Term (FTL .Entry , BaseResolver ):
122
123
id : "Identifier"
123
124
value : "Pattern"
124
- attributes : Dict [str , "Pattern" ]
125
+ attributes : dict [str , "Pattern" ]
125
126
126
127
def __init__ (
127
128
self ,
128
129
id : "Identifier" ,
129
130
value : "Pattern" ,
130
- attributes : Union [List ["Attribute" ], None ] = None ,
131
+ attributes : Union [list ["Attribute" ], None ] = None ,
131
132
comment : Any = None ,
132
133
** kwargs : Any ,
133
134
):
@@ -143,7 +144,7 @@ class Pattern(FTL.Pattern, BaseResolver):
143
144
# Prevent messages with too many sub parts, for CPI DOS protection
144
145
MAX_PARTS = 1000
145
146
146
- elements : List [Union ["TextElement" , "Placeable" ]] # type: ignore
147
+ elements : list [Union ["TextElement" , "Placeable" ]] # type: ignore
147
148
148
149
def __init__ (self , * args : Any , ** kwargs : Any ):
149
150
super ().__init__ (* args , ** kwargs )
@@ -294,7 +295,7 @@ def __call__(self, env: ResolverEnvironment) -> Any:
294
295
if isinstance (arg_val , (FluentType , str )):
295
296
return arg_val
296
297
env .errors .append (
297
- TypeError ("Unsupported external type: {}, {}" . format ( name , type (arg_val )) )
298
+ TypeError (f "Unsupported external type: { name } , { type (arg_val )} " )
298
299
)
299
300
return FluentNone (name )
300
301
@@ -306,7 +307,7 @@ class Attribute(FTL.Attribute, BaseResolver):
306
307
307
308
class SelectExpression (FTL .SelectExpression , BaseResolver ):
308
309
selector : "InlineExpression"
309
- variants : List ["Variant" ] # type: ignore
310
+ variants : list ["Variant" ] # type: ignore
310
311
311
312
def __call__ (self , env : ResolverEnvironment ) -> Union [str , FluentNone ]:
312
313
key = self .selector (env )
@@ -368,8 +369,8 @@ def __call__(self, env: ResolverEnvironment) -> str:
368
369
369
370
370
371
class CallArguments (FTL .CallArguments , BaseResolver ):
371
- positional : List [Union ["InlineExpression" , Placeable ]] # type: ignore
372
- named : List ["NamedArgument" ] # type: ignore
372
+ positional : list [Union ["InlineExpression" , Placeable ]] # type: ignore
373
+ named : list ["NamedArgument" ] # type: ignore
373
374
374
375
375
376
class FunctionReference (FTL .FunctionReference , BaseResolver ):
@@ -384,7 +385,7 @@ def __call__(self, env: ResolverEnvironment) -> Any:
384
385
function = env .context ._functions [function_name ]
385
386
except LookupError :
386
387
env .errors .append (
387
- FluentReferenceError ("Unknown function: {}" . format ( function_name ) )
388
+ FluentReferenceError (f "Unknown function: { function_name } " )
388
389
)
389
390
return FluentNone (function_name + "()" )
390
391
0 commit comments