1212from dataclasses import dataclass , field
1313from datetime import datetime , timedelta
1414from enum import Enum
15- from typing import Any , Dict , Iterator , List , Optional , Set , Tuple , Union
15+ import typing as t
1616
1717from viur .core import db , utils
1818from viur .core .config import conf
@@ -76,9 +76,9 @@ class ReadFromClientError:
7676 """A ReadFromClientErrorSeverity enumeration value representing the severity of the error."""
7777 errorMessage : str
7878 """A string containing a human-readable error message describing the issue."""
79- fieldPath : List [str ] = field (default_factory = list )
79+ fieldPath : list [str ] = field (default_factory = list )
8080 """A list of strings representing the path to the field where the error occurred."""
81- invalidatedFields : List [str ] = None
81+ invalidatedFields : list [str ] = None
8282 """A list of strings containing the names of invalidated fields, if any."""
8383
8484
@@ -192,18 +192,18 @@ def __init__(
192192 self ,
193193 * ,
194194 compute : Compute = None ,
195- defaultValue : Any = None ,
195+ defaultValue : t . Any = None ,
196196 descr : str = "" ,
197197 getEmptyValueFunc : callable = None ,
198198 indexed : bool = True ,
199199 isEmptyFunc : callable = None , # fixme: Rename this, see below.
200- languages : Union [ None , List [str ] ] = None ,
201- multiple : Union [ bool , MultipleConstraints ] = False ,
202- params : Dict = None ,
200+ languages : None | list [str ] = None ,
201+ multiple : bool | MultipleConstraints = False ,
202+ params : dict = None ,
203203 readOnly : bool = None , # fixme: Rename into readonly (all lowercase!) soon.
204- required : Union [ bool , List [str ], Tuple [str ] ] = False ,
204+ required : bool | list [str ] | tuple [str ] = False ,
205205 searchable : bool = False ,
206- unique : Union [ None , UniqueValue ] = None ,
206+ unique : None | UniqueValue = None ,
207207 vfunc : callable = None , # fixme: Rename this, see below.
208208 visible : bool = True ,
209209 ):
@@ -306,7 +306,7 @@ def isInvalid(self, value):
306306 """
307307 return False
308308
309- def isEmpty (self , value : Any ) -> bool :
309+ def isEmpty (self , value : t . Any ) -> bool :
310310 """
311311 Check if the given single value represents the "empty" value.
312312 This usually is the empty string, 0 or False.
@@ -339,7 +339,7 @@ def getDefaultValue(self, skeletonInstance):
339339 else :
340340 return self .defaultValue
341341
342- def getEmptyValue (self ) -> Any :
342+ def getEmptyValue (self ) -> t . Any :
343343 """
344344 Returns the value representing an empty field for this bone.
345345 This might be the empty string for str/text Bones, Zero for numeric bones etc.
@@ -482,9 +482,9 @@ def parseSubfieldsFromClient(self) -> bool:
482482 """
483483 return False
484484
485- def singleValueFromClient (self , value : Any , skel : 'SkeletonInstance' ,
485+ def singleValueFromClient (self , value : t . Any , skel : 'SkeletonInstance' ,
486486 bone_name : str , client_data : dict
487- ) -> tuple [Any , list [ReadFromClientError ] | None ]:
487+ ) -> tuple [t . Any , list [ReadFromClientError ] | None ]:
488488 """Load a single value from a client
489489
490490 :param value: The single value which should be loaded.
@@ -501,7 +501,7 @@ def singleValueFromClient(self, value: Any, skel: 'SkeletonInstance',
501501 return self .getEmptyValue (), [
502502 ReadFromClientError (ReadFromClientErrorSeverity .Invalid , "Will not read a BaseBone fromClient!" )]
503503
504- def fromClient (self , skel : 'SkeletonInstance' , name : str , data : dict ) -> Union [ None , List [ReadFromClientError ] ]:
504+ def fromClient (self , skel : 'SkeletonInstance' , name : str , data : dict ) -> None | list [ReadFromClientError ]:
505505 """
506506 Reads a value from the client and stores it in the skeleton instance if it is valid for the bone.
507507
@@ -586,7 +586,7 @@ def fromClient(self, skel: 'SkeletonInstance', name: str, data: dict) -> Union[N
586586 errors .extend (self .validateMultipleConstraints (skel , name ))
587587 return errors or None
588588
589- def validateMultipleConstraints (self , skel : 'SkeletonInstance' , name : str ) -> List [ReadFromClientError ]:
589+ def validateMultipleConstraints (self , skel : 'SkeletonInstance' , name : str ) -> list [ReadFromClientError ]:
590590 """
591591 Validates the value of a bone against its multiple constraints and returns a list of ReadFromClientError
592592 objects for each violation, such as too many items or duplicates.
@@ -844,8 +844,8 @@ def buildDBFilter(self,
844844 name : str ,
845845 skel : 'viur.core.skeleton.SkeletonInstance' ,
846846 dbFilter : db .Query ,
847- rawFilter : Dict ,
848- prefix : Optional [str ] = None ) -> db .Query :
847+ rawFilter : dict ,
848+ prefix : t . Optional [str ] = None ) -> db .Query :
849849 """
850850 Parses the searchfilter a client specified in his Request into
851851 something understood by the datastore.
@@ -896,7 +896,7 @@ def buildDBSort(self,
896896 name : str ,
897897 skel : 'viur.core.skeleton.SkeletonInstance' ,
898898 dbFilter : db .Query ,
899- rawFilter : Dict ) -> Optional [db .Query ]:
899+ rawFilter : dict ) -> t . Optional [db .Query ]:
900900 """
901901 Same as buildDBFilter, but this time its not about filtering
902902 the results, but by sorting them.
@@ -945,7 +945,7 @@ def buildDBSort(self,
945945 dbFilter .order (order )
946946 return dbFilter
947947
948- def _hashValueForUniquePropertyIndex (self , value : Union [ str , int ] ) -> List [str ]:
948+ def _hashValueForUniquePropertyIndex (self , value : str | int ) -> list [str ]:
949949 """
950950 Generates a hash of the given value for creating unique property indexes.
951951
@@ -958,7 +958,7 @@ def _hashValueForUniquePropertyIndex(self, value: Union[str, int]) -> List[str]:
958958 :return: A list containing a string representation of the hashed value. If the bone is multiple,
959959 the list may contain more than one hashed value.
960960 """
961- def hashValue (value : Union [ str , int ] ) -> str :
961+ def hashValue (value : str | int ) -> str :
962962 h = hashlib .sha256 ()
963963 h .update (str (value ).encode ("UTF-8" ))
964964 res = h .hexdigest ()
@@ -994,7 +994,7 @@ def keyHash(key):
994994 # Lock the value for that specific list
995995 return [hashValue (", " .join (tmpList ))]
996996
997- def getUniquePropertyIndexValues (self , skel : 'viur.core.skeleton.SkeletonInstance' , name : str ) -> List [str ]:
997+ def getUniquePropertyIndexValues (self , skel : 'viur.core.skeleton.SkeletonInstance' , name : str ) -> list [str ]:
998998 """
999999 Returns a list of hashes for the current value(s) of a bone in the skeleton, used for storing in the
10001000 unique property value index.
@@ -1011,13 +1011,13 @@ def getUniquePropertyIndexValues(self, skel: 'viur.core.skeleton.SkeletonInstanc
10111011 return []
10121012 return self ._hashValueForUniquePropertyIndex (val )
10131013
1014- def getReferencedBlobs (self , skel : 'viur.core.skeleton.SkeletonInstance' , name : str ) -> Set [str ]:
1014+ def getReferencedBlobs (self , skel : 'viur.core.skeleton.SkeletonInstance' , name : str ) -> set [str ]:
10151015 """
10161016 Returns a set of blob keys referenced from this bone
10171017 """
10181018 return set ()
10191019
1020- def performMagic (self , valuesCache : Dict , name : str , isAdd : bool ):
1020+ def performMagic (self , valuesCache : dict , name : str , isAdd : bool ):
10211021 """
10221022 This function applies "magically" functionality which f.e. inserts the current Date
10231023 or the current user.
@@ -1051,7 +1051,7 @@ def refresh(self, skel: 'viur.core.skeleton.SkeletonInstance', boneName: str) ->
10511051 """
10521052 pass
10531053
1054- def mergeFrom (self , valuesCache : Dict , boneName : str , otherSkel : 'viur.core.skeleton.SkeletonInstance' ):
1054+ def mergeFrom (self , valuesCache : dict , boneName : str , otherSkel : 'viur.core.skeleton.SkeletonInstance' ):
10551055 """
10561056 Merges the values from another skeleton instance into the current instance, given that the bone types match.
10571057
@@ -1076,9 +1076,9 @@ def mergeFrom(self, valuesCache: Dict, boneName: str, otherSkel: 'viur.core.skel
10761076 def setBoneValue (self ,
10771077 skel : 'SkeletonInstance' ,
10781078 boneName : str ,
1079- value : Any ,
1079+ value : t . Any ,
10801080 append : bool ,
1081- language : Union [ None , str ] = None ) -> bool :
1081+ language : None | str = None ) -> bool :
10821082 """
10831083 Sets the value of a bone in a skeleton instance, with optional support for appending and language-specific
10841084 values. Sanity checks are being performed.
@@ -1132,7 +1132,7 @@ def setBoneValue(self,
11321132 skel [boneName ][language ] = val
11331133 return True
11341134
1135- def getSearchTags (self , skel : 'viur.core.skeleton.SkeletonInstance' , name : str ) -> Set [str ]:
1135+ def getSearchTags (self , skel : 'viur.core.skeleton.SkeletonInstance' , name : str ) -> set [str ]:
11361136 """
11371137 Returns a set of strings as search index for this bone.
11381138
@@ -1150,7 +1150,7 @@ def getSearchTags(self, skel: 'viur.core.skeleton.SkeletonInstance', name: str)
11501150
11511151 def iter_bone_value (
11521152 self , skel : 'viur.core.skeleton.SkeletonInstance' , name : str
1153- ) -> Iterator [Tuple [ Optional [int ], Optional [str ], Any ]]:
1153+ ) -> t . Iterator [tuple [ t . Optional [int ], t . Optional [str ], t . Any ]]:
11541154 """
11551155 Yield all values from the Skeleton related to this bone instance.
11561156
0 commit comments