2929
3030def _verify_not_type_mismatch (second : SimpleBloomT ) -> bool :
3131 """verify that there is not a type mismatch"""
32- return isinstance (second , ( BloomFilter , BloomFilterOnDisk ) )
32+ return isinstance (second , BloomFilter | BloomFilterOnDisk )
3333
3434
3535class BloomFilter :
@@ -68,11 +68,11 @@ class BloomFilter:
6868
6969 def __init__ (
7070 self ,
71- est_elements : Union [ int , None ] = None ,
72- false_positive_rate : Union [ float , None ] = None ,
73- filepath : Union [ str , Path , None ] = None ,
74- hex_string : Union [ str , None ] = None ,
75- hash_function : Union [ HashFuncT , None ] = None ,
71+ est_elements : int | None = None ,
72+ false_positive_rate : float | None = None ,
73+ filepath : str | Path | None = None ,
74+ hex_string : str | None = None ,
75+ hash_function : HashFuncT | None = None ,
7676 ):
7777 # set some things up
7878 self ._on_disk = False
@@ -110,7 +110,7 @@ def _load_init(self, filepath, hash_function, hex_string, est_elements, false_po
110110 _FPR_STRUCT = Struct ("f" )
111111 _IMPT_STRUCT = Struct ("B" )
112112
113- def __contains__ (self , key : KeyT ) -> Union [ int , bool ] :
113+ def __contains__ (self , key : KeyT ) -> int | bool :
114114 """setup the `in` keyword"""
115115 return self .check (key )
116116
@@ -220,7 +220,7 @@ def clear(self) -> None:
220220 for idx in range (self ._bloom_length ):
221221 self ._bloom [idx ] = 0
222222
223- def hashes (self , key : KeyT , depth : Union [ int , None ] = None ) -> HashResultsT :
223+ def hashes (self , key : KeyT , depth : int | None = None ) -> HashResultsT :
224224 """Return the hashes based on the provided key
225225
226226 Args:
@@ -284,12 +284,12 @@ def export_hex(self) -> str:
284284 bytes_string = hexlify (bytearray (self ._bloom [: self .bloom_length ])) + hexlify (footer_bytes )
285285 return str (bytes_string , "utf-8" )
286286
287- def export (self , file : Union [ Path , str , IOBase , mmap ] ) -> None :
287+ def export (self , file : Path | str | IOBase | mmap ) -> None :
288288 """Export the Bloom Filter to disk
289289
290290 Args:
291291 file (str): The file or filepath to which the Bloom Filter will be written."""
292- if not isinstance (file , ( IOBase , mmap ) ):
292+ if not isinstance (file , IOBase | mmap ):
293293 file = resolve_path (file )
294294 with open (file , "wb" ) as filepointer :
295295 self .export (filepointer )
@@ -303,7 +303,7 @@ def export(self, file: Union[Path, str, IOBase, mmap]) -> None:
303303 )
304304 )
305305
306- def export_c_header (self , filename : Union [ str , Path ] ) -> None :
306+ def export_c_header (self , filename : str | Path ) -> None :
307307 """Export the Bloom Filter to disk as a C header file.
308308
309309 Args:
@@ -322,7 +322,7 @@ def export_c_header(self, filename: Union[str, Path]) -> None:
322322 print ("const unsigned char bloom[] = {" , * data , "};" , sep = "\n " , file = file )
323323
324324 @classmethod
325- def frombytes (cls , b : ByteString , hash_function : Union [ HashFuncT , None ] = None ) -> "BloomFilter" :
325+ def frombytes (cls , b : ByteString , hash_function : HashFuncT | None = None ) -> "BloomFilter" :
326326 """
327327 Args:
328328 b (ByteString): The bytes to load as a Bloom Filter
@@ -488,7 +488,7 @@ def _set_values(
488488 fpr : float ,
489489 n_hashes : int ,
490490 n_bits : int ,
491- hash_func : Union [ HashFuncT , None ] ,
491+ hash_func : HashFuncT | None ,
492492 ) -> None :
493493 self ._est_elements = est_els
494494 self ._fpr = fpr
@@ -501,7 +501,7 @@ def _set_values(
501501 self ._number_hashes = n_hashes
502502 self ._num_bits = n_bits
503503
504- def _load_hex (self , hex_string : str , hash_function : Union [ HashFuncT , None ] = None ) -> None :
504+ def _load_hex (self , hex_string : str , hash_function : HashFuncT | None = None ) -> None :
505505 """placeholder for loading from hex string"""
506506 offset = self ._FOOTER_STRUCT_BE .size * 2
507507 est_els , els_added , fpr , n_hashes , n_bits = self ._parse_footer (
@@ -513,11 +513,11 @@ def _load_hex(self, hex_string: str, hash_function: Union[HashFuncT, None] = Non
513513
514514 def _load (
515515 self ,
516- file : Union [ Path , str , IOBase , mmap , ByteString ] ,
517- hash_function : Union [ HashFuncT , None ] = None ,
516+ file : Path | str | IOBase | mmap | ByteString ,
517+ hash_function : HashFuncT | None = None ,
518518 ) -> None :
519519 """load the Bloom Filter from file or bytes"""
520- if not isinstance (file , ( IOBase , mmap , bytes , bytearray , memoryview ) ):
520+ if not isinstance (file , IOBase | mmap | bytes | bytearray | memoryview ):
521521 file = resolve_path (file )
522522 with MMap (file ) as filepointer :
523523 self ._load (filepointer , hash_function )
@@ -594,15 +594,15 @@ class BloomFilterOnDisk(BloomFilter):
594594
595595 def __init__ (
596596 self ,
597- filepath : Union [ str , Path ] ,
598- est_elements : Union [ int , None ] = None ,
599- false_positive_rate : Union [ float , None ] = None ,
600- hex_string : Union [ str , None ] = None ,
601- hash_function : Union [ HashFuncT , None ] = None ,
597+ filepath : str | Path ,
598+ est_elements : int | None = None ,
599+ false_positive_rate : float | None = None ,
600+ hex_string : str | None = None ,
601+ hash_function : HashFuncT | None = None ,
602602 ) -> None :
603603 # set some things up
604604 self ._filepath = resolve_path (filepath )
605- self .__file_pointer : Union [ BufferedRandom , None ] = None
605+ self .__file_pointer : BufferedRandom | None = None
606606 super ().__init__ (est_elements , false_positive_rate , filepath , hex_string , hash_function )
607607
608608 def _load_init (self , filepath , hash_function , hex_string , est_elements , false_positive_rate ):
@@ -641,7 +641,7 @@ def close(self) -> None:
641641 self .__file_pointer .close ()
642642 self .__file_pointer = None
643643
644- def export (self , file : Union [ str , Path ] ) -> None : # type: ignore
644+ def export (self , file : str | Path ) -> None : # type: ignore
645645 """Export to disk if a different location
646646
647647 Args:
@@ -653,7 +653,7 @@ def export(self, file: Union[str, Path]) -> None: # type: ignore
653653 copyfile (self ._filepath , str (file ))
654654 # otherwise, nothing to do!
655655
656- def _load (self , file : Union [ str , Path ] , hash_function : Union [ HashFuncT , None ] = None ): # type: ignore
656+ def _load (self , file : str | Path , hash_function : HashFuncT | None = None ): # type: ignore
657657 """load the Bloom Filter on disk"""
658658 # read the file, set the optimal params
659659 # mmap everything
@@ -675,7 +675,7 @@ def add_alt(self, hashes: HashResultsT) -> None:
675675 self .__update ()
676676
677677 @classmethod
678- def frombytes (cls , b : ByteString , hash_function : Union [ HashFuncT , None ] = None ) -> "BloomFilterOnDisk" :
678+ def frombytes (cls , b : ByteString , hash_function : HashFuncT | None = None ) -> "BloomFilterOnDisk" :
679679 """
680680 Raises: NotSupportedError
681681 """
0 commit comments