1414
1515import ast
1616import re
17+ from collections .abc import Callable
1718from enum import Enum , Flag , IntFlag
18- from typing import Any , Callable , Dict , List , Optional , Tuple , TypeVar , Union , cast
19+ from typing import Any , TypeVar , cast
1920
2021from robot .libraries .BuiltIn import BuiltIn
2122
107108 AssertionOperator ["then" ],
108109]
109110
110- handlers : Dict [AssertionOperator , Tuple [Callable , str ]] = {
111+ handlers : dict [AssertionOperator , tuple [Callable , str ]] = {
111112 AssertionOperator ["==" ]: (lambda a , b : a == b , "should be" ),
112113 AssertionOperator ["!=" ]: (lambda a , b : a != b , "should not be" ),
113114 AssertionOperator ["<" ]: (lambda a , b : a < b , "should be less than" ),
132133}
133134
134135
135- set_handlers : Dict [AssertionOperator , Tuple [Callable , str ]] = {
136+ set_handlers : dict [AssertionOperator , tuple [Callable , str ]] = {
136137 AssertionOperator ["==" ]: (lambda a , b : a == b , "should be" ),
137138 AssertionOperator ["!=" ]: (lambda a , b : a != b , "should not be" ),
138139 AssertionOperator ["*=" ]: (lambda a , b : b .issubset (a ), "should contain" ),
145146T = TypeVar ("T" )
146147
147148
148- def apply_formatters (value : T , formatters : Optional [ List [ Any ]] ) -> Any :
149+ def apply_formatters (value : T , formatters : list [ Any ] | None ) -> Any :
149150 if not formatters :
150151 return value
151152 for formatter in formatters :
152153 value = formatter (value )
153154 return value
154155
155156
156- def apply_to_expected (expected : Any , formatters : Optional [ List [ Any ]] ) -> Any :
157+ def apply_to_expected (expected : Any , formatters : list [ Any ] | None ) -> Any :
157158 if not formatters :
158159 return expected
159160 for formatter in formatters :
@@ -164,11 +165,11 @@ def apply_to_expected(expected: Any, formatters: Optional[List[Any]]) -> Any:
164165
165166def verify_assertion (
166167 value : T ,
167- operator : Optional [ AssertionOperator ] ,
168+ operator : AssertionOperator | None ,
168169 expected : Any ,
169170 message : str = "" ,
170- custom_message : Optional [ str ] = None ,
171- formatters : Optional [ list ] = None ,
171+ custom_message : str | None = None ,
172+ formatters : list | None = None ,
172173) -> Any :
173174 if operator is None and expected :
174175 raise ValueError (
@@ -193,11 +194,11 @@ def verify_assertion(
193194
194195
195196def flag_verify_assertion (
196- value : Union [ IntFlag , Flag ] ,
197- operator : Optional [ AssertionOperator ] ,
197+ value : IntFlag | Flag ,
198+ operator : AssertionOperator | None ,
198199 expected : Any ,
199200 message : str = "" ,
200- custom_message : Optional [ str ] = None ,
201+ custom_message : str | None = None ,
201202) -> Any :
202203 if not isinstance (value , Flag ):
203204 raise TypeError (f"Verified value was not of type Flag. It was { type (value )} " )
@@ -273,7 +274,7 @@ def raise_error(custom_message, expected, filler, message, text, value):
273274
274275def float_str_verify_assertion (
275276 value : T ,
276- operator : Optional [ AssertionOperator ] ,
277+ operator : AssertionOperator | None ,
277278 expected : Any ,
278279 message = "" ,
279280 custom_message = "" ,
@@ -294,7 +295,7 @@ def float_str_verify_assertion(
294295
295296def int_str_verify_assertion (
296297 value : T ,
297- operator : Optional [ AssertionOperator ] ,
298+ operator : AssertionOperator | None ,
298299 expected : Any ,
299300 message = "" ,
300301 custom_message = "" ,
@@ -315,7 +316,7 @@ def int_str_verify_assertion(
315316
316317def bool_verify_assertion (
317318 value : T ,
318- operator : Optional [ AssertionOperator ] ,
319+ operator : AssertionOperator | None ,
319320 expected : Any ,
320321 message = "" ,
321322 custom_message = "" ,
@@ -330,7 +331,7 @@ def bool_verify_assertion(
330331 return verify_assertion (value , operator , expected_bool , message , custom_message )
331332
332333
333- def map_list (selected : List ):
334+ def map_list (selected : list ):
334335 if not selected or len (selected ) == 0 :
335336 return None
336337 if len (selected ) == 1 :
@@ -339,9 +340,9 @@ def map_list(selected: List):
339340
340341
341342def list_verify_assertion (
342- value : List ,
343- operator : Optional [ AssertionOperator ] ,
344- expected : List ,
343+ value : list ,
344+ operator : AssertionOperator | None ,
345+ expected : list ,
345346 message = "" ,
346347 custom_message = "" ,
347348):
@@ -382,9 +383,9 @@ def list_verify_assertion(
382383
383384
384385def dict_verify_assertion (
385- value : Dict ,
386- operator : Optional [ AssertionOperator ] ,
387- expected : Optional [ Dict ] ,
386+ value : dict ,
387+ operator : AssertionOperator | None ,
388+ expected : dict | None ,
388389 message = "" ,
389390 custom_message = "" ,
390391):
@@ -397,9 +398,9 @@ def dict_verify_assertion(
397398
398399
399400def int_dict_verify_assertion (
400- value : Dict [str , int ],
401- operator : Optional [ AssertionOperator ] ,
402- expected : Optional [ Dict [ str , int ]] ,
401+ value : dict [str , int ],
402+ operator : AssertionOperator | None ,
403+ expected : dict [ str , int ] | None ,
403404 message = "" ,
404405 custom_message = "" ,
405406):
0 commit comments