11import re
2- from typing import Dict
3- from typing import List
4- from typing import Optional
5- from typing import Tuple
6- from typing import Type
2+ from typing import Any
73
84from scim2_filter_parser .lexer import SCIMLexer
95from scim2_filter_parser .parser import SCIMParser
@@ -43,7 +39,7 @@ def patch_resource(resource: Resource, operation: PatchOperation):
4339 operator (resource )
4440
4541
46- def parse_attribute_path (attribute_path : Optional [ str ] ) -> Optional [ Dict [ str , any ]] :
42+ def parse_attribute_path (attribute_path : str | None ) -> dict [ str , Any ] | None :
4743 """Parses an attribute path and returns a dictionary of attributes.
4844
4945 The attributes are the named captures in the regex
@@ -72,13 +68,13 @@ class Operator:
7268 REQUIRES_VALUE = True # Whether the operator modifies the resource or not
7369 RETURNS_VALUE = False # Whether the operator returns a result or not
7470
75- def __init__ (self , path : Optional [ str ] , value : Optional [ any ] ):
71+ def __init__ (self , path : str | None , value : Any | None ):
7672 self .path = path
7773 self .value = value
7874
7975 @classmethod
8076 def init_return (
81- cls , model : BaseModel , attribute : str , sub_attribute : Optional [ str ] , value : any
77+ cls , model : BaseModel , attribute : str , sub_attribute : str | None , value : Any
8278 ):
8379 """Initializes the return value if the operator returns something."""
8480 pass
@@ -89,7 +85,7 @@ def do_return(self):
8985
9086 @classmethod
9187 def operation (
92- cls , model : BaseModel , attribute : str , value : any , index : Optional [ int ] = None
88+ cls , model : BaseModel , attribute : str , value : Any , index : int | None = None
9389 ):
9490 """Performs the actual operation of the operator."""
9591 raise NotImplementedError
@@ -224,7 +220,7 @@ class AddOperator(Operator):
224220 """The implementation for the PATCH "add" operator."""
225221
226222 @classmethod
227- def operation (cls , model : BaseModel , attribute : str , value : any ):
223+ def operation (cls , model : BaseModel , attribute : str , value : Any ):
228224 alias = get_by_alias (model , attribute )
229225 if is_multi_valued (model , alias ) and isinstance (value , list ):
230226 for v in value :
@@ -262,7 +258,7 @@ class RemoveOperator(Operator):
262258 REQUIRES_VALUE = False
263259
264260 @classmethod
265- def operation (cls , model : BaseModel , attribute : str , value : any ):
261+ def operation (cls , model : BaseModel , attribute : str , value : Any ):
266262 alias = get_by_alias (model , attribute )
267263 existing_value = getattr (model , alias )
268264 if not existing_value :
@@ -284,7 +280,7 @@ class ReplaceOperator(Operator):
284280 """The implementation for the PATCH "replace" operator."""
285281
286282 @classmethod
287- def operation (cls , model : BaseModel , attribute : str , value : any ):
283+ def operation (cls , model : BaseModel , attribute : str , value : Any ):
288284 alias = get_by_alias (model , attribute )
289285 if is_multi_valued (model , alias ) and not isinstance (value , list ):
290286 raise SCIMException (Error .make_invalid_value_error ())
@@ -328,13 +324,13 @@ def add_result_index(self, model: BaseModel, attribute_name: str, index: int):
328324 """
329325 self .records .append ((model , attribute_name , index ))
330326
331- def _evaluate_result (self , record : Tuple [str , str ] | Tuple [str , str , int ]):
327+ def _evaluate_result (self , record : tuple [str , str ] | tuple [str , str , int ]):
332328 if len (record ) == 2 :
333329 return getattr (* record )
334330 else :
335331 return getattr (record [0 ], record [1 ])[record [2 ]]
336332
337- def get_field_annotation (self , annotation_type : Type ):
333+ def get_field_annotation (self , annotation_type : type ):
338334 if not self .model :
339335 return None
340336 return self .model .get_field_annotation (self .attribute , annotation_type )
@@ -353,7 +349,7 @@ class ResolveOperator(Operator):
353349 REQUIRES_VALUE = False
354350 RETURNS_VALUE = True
355351
356- def __init__ (self , path : Optional [ str ] ):
352+ def __init__ (self , path : str | None ):
357353 super ().__init__ (path , ResolveResult ())
358354
359355 def do_return (self ):
@@ -366,7 +362,7 @@ def init_return(
366362 cls ,
367363 model : BaseModel ,
368364 attribute : str ,
369- sub_attribute : Optional [ str ] ,
365+ sub_attribute : str | None ,
370366 value : ResolveResult ,
371367 ):
372368 alias = get_by_alias (model , attribute )
@@ -381,7 +377,7 @@ def init_return(
381377
382378 @classmethod
383379 def operation (
384- cls , model : BaseModel , attribute : str , value : any , index : Optional [ int ] = None
380+ cls , model : BaseModel , attribute : str , value : Any , index : int | None = None
385381 ):
386382 alias = get_by_alias (model , attribute )
387383 if index is None :
@@ -405,17 +401,17 @@ class ResolveSortOperator(ResolveOperator):
405401 is not set.
406402 """
407403
408- def __init__ (self , path : Optional [ str ] ):
404+ def __init__ (self , path : str | None ):
409405 super ().__init__ (path )
410406
411- def alias_forbidden (self , model : BaseModel , alias : Optional [ str ] ) -> bool :
407+ def alias_forbidden (self , model : BaseModel , alias : str | None ) -> bool :
412408 return (
413409 not alias
414410 or model .get_field_annotation (alias , Mutability ) == Mutability .write_only
415411 or model .get_field_annotation (alias , Returned ) == Returned .never
416412 )
417413
418- def set_value_case_exact (self , value : any , case_exact : CaseExact ):
414+ def set_value_case_exact (self , value : Any , case_exact : CaseExact ):
419415 if isinstance (value , str ) and case_exact == CaseExact .false :
420416 value = value .lower ()
421417 self .value = value
@@ -467,7 +463,7 @@ def __call__(self, model: BaseModel):
467463 self .set_value_case_exact (attribute_value , case_exact )
468464 return self .value
469465
470- def select_candidate (self , values : List [ any ]) -> Tuple [ Optional [ any ] , int ]:
466+ def select_candidate (self , values : list [ Any ]) -> tuple [ Any | None , int ]:
471467 """Selects a viable candidate from a list of possible values."""
472468 for value in values :
473469 primary = getattr (value , "primary" , False )
0 commit comments