11import 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
34
45import attr
56from fluent .syntax import ast as FTL
@@ -42,7 +43,7 @@ class CurrentEnvironment:
4243 # For Messages, VariableReference nodes are interpreted as external args,
4344 # but for Terms they are the values explicitly passed using CallExpression
4445 # 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 )
4647 # This controls whether we need to report an error if a VariableReference
4748 # refers to an arg that is not present in the args dict.
4849 error_for_missing_arg : bool = attr .ib (default = True )
@@ -51,9 +52,9 @@ class CurrentEnvironment:
5152@attr .s
5253class ResolverEnvironment :
5354 context : "FluentBundle" = attr .ib ()
54- errors : List [Exception ] = attr .ib ()
55+ errors : list [Exception ] = attr .ib ()
5556 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 )
5758 current : CurrentEnvironment = attr .ib (factory = CurrentEnvironment )
5859
5960 @contextlib .contextmanager
@@ -72,7 +73,7 @@ def modified(
7273 self .current = old_current
7374
7475 def modified_for_term_reference (
75- self , args : Union [Dict [str , Any ], None ] = None
76+ self , args : Union [dict [str , Any ], None ] = None
7677 ) -> Any :
7778 return self .modified (
7879 args = args if args is not None else {}, error_for_missing_arg = False
@@ -100,13 +101,13 @@ class Literal(BaseResolver):
100101class Message (FTL .Entry , BaseResolver ):
101102 id : "Identifier"
102103 value : Union ["Pattern" , None ]
103- attributes : Dict [str , "Pattern" ]
104+ attributes : dict [str , "Pattern" ]
104105
105106 def __init__ (
106107 self ,
107108 id : "Identifier" ,
108109 value : Union ["Pattern" , None ] = None ,
109- attributes : Union [List ["Attribute" ], None ] = None ,
110+ attributes : Union [list ["Attribute" ], None ] = None ,
110111 comment : Any = None ,
111112 ** kwargs : Any ,
112113 ):
@@ -121,13 +122,13 @@ def __init__(
121122class Term (FTL .Entry , BaseResolver ):
122123 id : "Identifier"
123124 value : "Pattern"
124- attributes : Dict [str , "Pattern" ]
125+ attributes : dict [str , "Pattern" ]
125126
126127 def __init__ (
127128 self ,
128129 id : "Identifier" ,
129130 value : "Pattern" ,
130- attributes : Union [List ["Attribute" ], None ] = None ,
131+ attributes : Union [list ["Attribute" ], None ] = None ,
131132 comment : Any = None ,
132133 ** kwargs : Any ,
133134 ):
@@ -143,7 +144,7 @@ class Pattern(FTL.Pattern, BaseResolver):
143144 # Prevent messages with too many sub parts, for CPI DOS protection
144145 MAX_PARTS = 1000
145146
146- elements : List [Union ["TextElement" , "Placeable" ]] # type: ignore
147+ elements : list [Union ["TextElement" , "Placeable" ]] # type: ignore
147148
148149 def __init__ (self , * args : Any , ** kwargs : Any ):
149150 super ().__init__ (* args , ** kwargs )
@@ -294,7 +295,7 @@ def __call__(self, env: ResolverEnvironment) -> Any:
294295 if isinstance (arg_val , (FluentType , str )):
295296 return arg_val
296297 env .errors .append (
297- TypeError ("Unsupported external type: {}, {}" . format ( name , type (arg_val )) )
298+ TypeError (f "Unsupported external type: { name } , { type (arg_val )} " )
298299 )
299300 return FluentNone (name )
300301
@@ -306,7 +307,7 @@ class Attribute(FTL.Attribute, BaseResolver):
306307
307308class SelectExpression (FTL .SelectExpression , BaseResolver ):
308309 selector : "InlineExpression"
309- variants : List ["Variant" ] # type: ignore
310+ variants : list ["Variant" ] # type: ignore
310311
311312 def __call__ (self , env : ResolverEnvironment ) -> Union [str , FluentNone ]:
312313 key = self .selector (env )
@@ -368,8 +369,8 @@ def __call__(self, env: ResolverEnvironment) -> str:
368369
369370
370371class 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
373374
374375
375376class FunctionReference (FTL .FunctionReference , BaseResolver ):
@@ -384,7 +385,7 @@ def __call__(self, env: ResolverEnvironment) -> Any:
384385 function = env .context ._functions [function_name ]
385386 except LookupError :
386387 env .errors .append (
387- FluentReferenceError ("Unknown function: {}" . format ( function_name ) )
388+ FluentReferenceError (f "Unknown function: { function_name } " )
388389 )
389390 return FluentNone (function_name + "()" )
390391
0 commit comments