Skip to content

Commit 8320ea4

Browse files
committed
drop python 3.9 support
1 parent 5119dea commit 8320ea4

13 files changed

Lines changed: 127 additions & 136 deletions

File tree

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
14+
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
1515

1616
steps:
1717
- uses: actions/checkout@v6

probables/blooms/bloom.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
def _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

3535
class 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
"""

probables/blooms/countingbloom.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from collections.abc import ByteString
99
from pathlib import Path
1010
from struct import Struct
11-
from typing import Union
1211

1312
from probables.blooms.bloom import BloomFilter
1413
from probables.constants import UINT32_T_MAX, UINT64_T_MAX
@@ -48,11 +47,11 @@ class CountingBloomFilter(BloomFilter):
4847

4948
def __init__(
5049
self,
51-
est_elements: Union[int, None] = None,
52-
false_positive_rate: Union[float, None] = None,
53-
filepath: Union[str, Path, None] = None,
54-
hex_string: Union[str, None] = None,
55-
hash_function: Union[HashFuncT, None] = None,
50+
est_elements: int | None = None,
51+
false_positive_rate: float | None = None,
52+
filepath: str | Path | None = None,
53+
hex_string: str | None = None,
54+
hash_function: HashFuncT | None = None,
5655
) -> None:
5756
"""setup the basic values needed"""
5857
self._filepath = None
@@ -81,7 +80,7 @@ def _load_init(self, filepath, hash_function, hex_string, est_elements, false_po
8180
_IMPT_STRUCT = Struct("I")
8281

8382
@classmethod
84-
def frombytes(cls, b: ByteString, hash_function: Union[HashFuncT, None] = None) -> "CountingBloomFilter":
83+
def frombytes(cls, b: ByteString, hash_function: HashFuncT | None = None) -> "CountingBloomFilter":
8584
"""
8685
Args:
8786
b (ByteString): the bytes to load as a Counting Bloom Filter

probables/blooms/expandingbloom.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from mmap import mmap
1111
from pathlib import Path
1212
from struct import Struct
13-
from typing import Union
1413

1514
from probables.blooms.bloom import BloomFilter
1615
from probables.exceptions import RotatingBloomFilterError
@@ -46,10 +45,10 @@ class ExpandingBloomFilter:
4645

4746
def __init__(
4847
self,
49-
est_elements: Union[int, None] = None,
50-
false_positive_rate: Union[float, None] = None,
51-
filepath: Union[str, Path, None] = None,
52-
hash_function: Union[HashFuncT, None] = None,
48+
est_elements: int | None = None,
49+
false_positive_rate: float | None = None,
50+
filepath: str | Path | None = None,
51+
hash_function: HashFuncT | None = None,
5352
):
5453
"""initialize"""
5554
self._blooms = [] # type: ignore
@@ -74,7 +73,7 @@ def __init__(
7473
_BLOOM_ELEMENT_SIZE = Struct("B").size
7574

7675
@classmethod
77-
def frombytes(cls, b: ByteString, hash_function: Union[HashFuncT, None] = None) -> "ExpandingBloomFilter":
76+
def frombytes(cls, b: ByteString, hash_function: HashFuncT | None = None) -> "ExpandingBloomFilter":
7877
"""
7978
Args:
8079
b (ByteString): The bytes to load as a Expanding Bloom Filter
@@ -183,12 +182,12 @@ def __check_for_growth(self):
183182
if self._blooms[-1].elements_added >= self.__est_elements:
184183
self.__add_bloom_filter()
185184

186-
def export(self, file: Union[Path, str, IOBase, mmap]) -> None:
185+
def export(self, file: Path | str | IOBase | mmap) -> None:
187186
"""Export an expanding Bloom Filter, or subclass, to disk
188187
189188
Args:
190189
filepath (str): The path to the file to import"""
191-
if not isinstance(file, (IOBase, mmap)):
190+
if not isinstance(file, IOBase | mmap):
192191
file = resolve_path(file)
193192
with open(file, "wb") as filepointer:
194193
self.export(filepointer) # type:ignore
@@ -207,9 +206,9 @@ def export(self, file: Union[Path, str, IOBase, mmap]) -> None:
207206
)
208207
)
209208

210-
def __load(self, file: Union[Path, str, IOBase, mmap]):
209+
def __load(self, file: Path | str | IOBase | mmap):
211210
"""load a file"""
212-
if not isinstance(file, (IOBase, mmap)):
211+
if not isinstance(file, IOBase | mmap):
213212
file = resolve_path(file)
214213
with MMap(file) as filepointer:
215214
self.__load(filepointer)
@@ -272,11 +271,11 @@ class RotatingBloomFilter(ExpandingBloomFilter):
272271

273272
def __init__(
274273
self,
275-
est_elements: Union[int, None] = None,
276-
false_positive_rate: Union[float, None] = None,
274+
est_elements: int | None = None,
275+
false_positive_rate: float | None = None,
277276
max_queue_size: int = 10,
278-
filepath: Union[str, Path, None] = None,
279-
hash_function: Union[HashFuncT, None] = None,
277+
filepath: str | Path | None = None,
278+
hash_function: HashFuncT | None = None,
280279
) -> None:
281280
"""initialize"""
282281
super().__init__(
@@ -289,7 +288,7 @@ def __init__(
289288

290289
@classmethod
291290
def frombytes( # type:ignore
292-
cls, b: ByteString, max_queue_size: int, hash_function: Union[HashFuncT, None] = None
291+
cls, b: ByteString, max_queue_size: int, hash_function: HashFuncT | None = None
293292
) -> "RotatingBloomFilter":
294293
"""
295294
Args:

0 commit comments

Comments
 (0)