pyfusefilter 1.3.2__tar.gz → 1.3.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. pyfusefilter-1.3.4/MANIFEST.in +4 -0
  2. {pyfusefilter-1.3.2 → pyfusefilter-1.3.4}/PKG-INFO +2 -1
  3. pyfusefilter-1.3.4/pyfusefilter/_xorfilter.pyi +6 -0
  4. {pyfusefilter-1.3.2 → pyfusefilter-1.3.4}/pyfusefilter/ffibuild.py +6 -0
  5. {pyfusefilter-1.3.2 → pyfusefilter-1.3.4}/pyfusefilter/pyfusefilter.py +68 -51
  6. {pyfusefilter-1.3.2 → pyfusefilter-1.3.4}/pyfusefilter.egg-info/PKG-INFO +2 -1
  7. {pyfusefilter-1.3.2 → pyfusefilter-1.3.4}/pyfusefilter.egg-info/SOURCES.txt +5 -1
  8. {pyfusefilter-1.3.2 → pyfusefilter-1.3.4}/pyproject.toml +13 -2
  9. {pyfusefilter-1.3.2 → pyfusefilter-1.3.4}/setup.py +2 -1
  10. pyfusefilter-1.3.4/tests/__init__.py +0 -0
  11. pyfusefilter-1.3.4/tests/test_annotations.py +37 -0
  12. {pyfusefilter-1.3.2 → pyfusefilter-1.3.4}/tests/test_fuse16.py +5 -2
  13. {pyfusefilter-1.3.2 → pyfusefilter-1.3.4}/tests/test_fuse8.py +5 -2
  14. pyfusefilter-1.3.4/tests/typecheck_api.py +18 -0
  15. pyfusefilter-1.3.2/MANIFEST.in +0 -2
  16. {pyfusefilter-1.3.2 → pyfusefilter-1.3.4}/LICENSE +0 -0
  17. {pyfusefilter-1.3.2 → pyfusefilter-1.3.4}/README.md +0 -0
  18. {pyfusefilter-1.3.2 → pyfusefilter-1.3.4}/lib/xor_singleheader/include/binaryfusefilter.h +0 -0
  19. {pyfusefilter-1.3.2 → pyfusefilter-1.3.4}/lib/xor_singleheader/include/xorfilter.h +0 -0
  20. {pyfusefilter-1.3.2 → pyfusefilter-1.3.4}/pyfusefilter/__init__.py +0 -0
  21. /pyfusefilter-1.3.2/tests/__init__.py → /pyfusefilter-1.3.4/pyfusefilter/py.typed +0 -0
  22. {pyfusefilter-1.3.2 → pyfusefilter-1.3.4}/pyfusefilter.egg-info/dependency_links.txt +0 -0
  23. {pyfusefilter-1.3.2 → pyfusefilter-1.3.4}/pyfusefilter.egg-info/requires.txt +0 -0
  24. {pyfusefilter-1.3.2 → pyfusefilter-1.3.4}/pyfusefilter.egg-info/top_level.txt +0 -0
  25. {pyfusefilter-1.3.2 → pyfusefilter-1.3.4}/setup.cfg +0 -0
  26. {pyfusefilter-1.3.2 → pyfusefilter-1.3.4}/tests/test_xor16.py +0 -0
  27. {pyfusefilter-1.3.2 → pyfusefilter-1.3.4}/tests/test_xor8.py +0 -0
@@ -0,0 +1,4 @@
1
+ include lib/xor_singleheader/include/binaryfusefilter.h
2
+ include lib/xor_singleheader/include/xorfilter.h
3
+ include pyfusefilter/py.typed
4
+ include pyfusefilter/*.pyi
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyfusefilter
3
- Version: 1.3.2
3
+ Version: 1.3.4
4
4
  Summary: Python bindings for C implementation of xor and fuse filters
5
5
  Home-page: https://github.com/FastFilter/pyfusefilter
6
6
  Author: Amey Narkhede & Daniel Lemire
@@ -208,6 +208,7 @@ License: Apache License
208
208
  limitations under the License.
209
209
 
210
210
  Project-URL: Homepage, https://github.com/FastFilter/pyfusefilter
211
+ Classifier: Typing :: Typed
211
212
  Requires-Python: >=3.0
212
213
  Description-Content-Type: text/markdown
213
214
  License-File: LICENSE
@@ -0,0 +1,6 @@
1
+ from typing import Any
2
+
3
+ # The cffi extension is generated at build time. The Python code only calls
4
+ # into it; callers of the package never need these names.
5
+ lib: Any
6
+ ffi: Any
@@ -14,8 +14,14 @@ with open("lib/xor_singleheader/include/binaryfusefilter.h", "r", encoding='utf-
14
14
  all_src += src.read()
15
15
 
16
16
 
17
+ # Under Pyodide (WebAssembly), a wheel is tied to one Pyodide version anyway,
18
+ # so the limited API (abi3) gains nothing; and Pyodide 315 names abi3
19
+ # extensions with quotes (_xorfilter.abi3-"wasm32-emscripten".so), which
20
+ # Python then cannot import.
21
+ import sysconfig
17
22
  ffi.set_source(
18
23
  "_xorfilter", all_src,
24
+ py_limited_api=not sysconfig.get_platform().startswith("emscripten"),
19
25
  )
20
26
 
21
27
  ffi.cdef(
@@ -1,9 +1,26 @@
1
- from ._xorfilter import lib, ffi
1
+ from __future__ import annotations
2
+
3
+ import struct
4
+ import sys
5
+ from collections.abc import Iterable
2
6
  from ctypes import c_ulonglong
7
+
3
8
  import xxhash
4
- import struct
5
9
 
6
- def hash(item):
10
+ from ._xorfilter import lib, ffi
11
+
12
+ # serialize() returns a cffi buffer. It supports the buffer protocol, so
13
+ # file.write() and deserialize() accept it, but it is not a bytes instance.
14
+ # collections.abc.Buffer is that protocol; it exists at runtime on 3.12+.
15
+ if sys.version_info >= (3, 12):
16
+ from collections.abc import Buffer
17
+ else:
18
+ from typing import Any, Union
19
+
20
+ Buffer = Union[bytes, bytearray, memoryview, Any]
21
+
22
+
23
+ def hash(item: object) -> int:
7
24
  # xxhash 4 no longer accepts str; encoding as UTF-8 gives exactly the
8
25
  # same hash values that earlier xxhash versions computed for str input.
9
26
  return xxhash.xxh64_intdigest(str(item).encode("utf-8"))
@@ -15,7 +32,7 @@ class Xor8:
15
32
  a byte of memory per key. Its false positive rate is roughly 0.39%.
16
33
  For large sets, a Fuse8 filter is more efficient than a Xor8 filter.
17
34
  """
18
- def __init__(self, size_or_data):
35
+ def __init__(self, size_or_data: int | Iterable[object]) -> None:
19
36
  """
20
37
  Initialize the Xor8 filter.
21
38
  If an integer is provided, allocate a filter of that size. You must then use 'populate' to add data.
@@ -36,10 +53,10 @@ class Xor8:
36
53
  if not lib.xor8_buffered_populate(data, len(data), self.__filter):
37
54
  raise ValueError("Unable to populate the filter")
38
55
 
39
- def __repr__(self):
56
+ def __repr__(self) -> str:
40
57
  return "Xor8 object with size(in bytes):{}".format(self.size_in_bytes())
41
58
 
42
- def __getitem__(self, item):
59
+ def __getitem__(self, item: object) -> bool:
43
60
  """
44
61
  Check if the item is in the filter. With a small probability, the filter
45
62
  may return true for an item not in the set (false positive). There is
@@ -47,7 +64,7 @@ class Xor8:
47
64
  """
48
65
  return self.contains(item)
49
66
 
50
- def __contains__(self, item):
67
+ def __contains__(self, item: object) -> bool:
51
68
  """
52
69
  Check if the item is in the filter. With a small probability, the filter
53
70
  may return true for an item not in the set (false positive). There is
@@ -55,10 +72,10 @@ class Xor8:
55
72
  """
56
73
  return self.contains(item)
57
74
 
58
- def __del__(self):
75
+ def __del__(self) -> None:
59
76
  lib.xor8_free(self.__filter)
60
77
 
61
- def populate(self, data: list):
78
+ def populate(self, data: Iterable[object]) -> bool:
62
79
  """
63
80
  Set the data of the filter. You may use this method to add data after
64
81
  allocating the filter with an integer size. The sizes should match.
@@ -68,7 +85,7 @@ class Xor8:
68
85
  data = list(map(lambda x: c_ulonglong((hash(x))).value, data))
69
86
  return lib.xor8_buffered_populate(data, len(data), self.__filter)
70
87
 
71
- def contains(self, item):
88
+ def contains(self, item: object) -> bool:
72
89
  """
73
90
  Check if the item is in the filter. With a small probability, the filter
74
91
  may return true for an item not in the set (false positive). There is
@@ -77,25 +94,25 @@ class Xor8:
77
94
  item = c_ulonglong((hash(item))).value
78
95
  return lib.xor8_contain(item, self.__filter)
79
96
 
80
- def size_in_bytes(self):
97
+ def size_in_bytes(self) -> int:
81
98
  """
82
99
  Return the size of the filter in bytes, not counting Python overhead.
83
100
  This value might be slightly larger than the serialized size.
84
101
  """
85
102
  return lib.xor8_size_in_bytes(self.__filter)
86
103
 
87
- def serialize(self):
104
+ def serialize(self) -> Buffer:
88
105
  """
89
- Serialize the filter to a bytes object.
106
+ Serialize the filter to a bytes-like buffer.
90
107
  """
91
108
  buffer = ffi.new("char[]", lib.xor8_serialization_bytes(self.__filter))
92
109
  lib.xor8_serialize(self.__filter, buffer)
93
110
  return ffi.buffer(buffer)
94
111
 
95
112
  @staticmethod
96
- def deserialize(buffer):
113
+ def deserialize(buffer: Buffer) -> Xor8:
97
114
  """
98
- Deserialize a bytes object to a Xor8 filter.
115
+ Deserialize a bytes-like buffer to a Xor8 filter.
99
116
  """
100
117
  self = object.__new__(Xor8)
101
118
  self.__filter = ffi.new("xor8_t *")
@@ -110,7 +127,7 @@ class Xor16:
110
127
  Its false positive rate is roughly 0.0015%.
111
128
  For large sets, a Fuse16 filter is more efficient than a Xor16 filter.
112
129
  """
113
- def __init__(self, size_or_data):
130
+ def __init__(self, size_or_data: int | Iterable[object]) -> None:
114
131
  """
115
132
  Initialize the Xor16 filter.
116
133
  If an integer is provided, allocate a filter of that size. You must then use 'populate' to add data.
@@ -131,13 +148,13 @@ class Xor16:
131
148
  if not lib.xor16_buffered_populate(data, len(data), self.__filter):
132
149
  raise ValueError("Unable to populate the filter")
133
150
 
134
- def __repr__(self):
151
+ def __repr__(self) -> str:
135
152
  """
136
153
  Return a string representation of the Xor16 filter, including its size in bytes.
137
154
  """
138
155
  return "Xor16 object with size(in bytes):{}".format(self.size_in_bytes())
139
156
 
140
- def __getitem__(self, item):
157
+ def __getitem__(self, item: object) -> bool:
141
158
  """
142
159
  Check if the item is in the filter. With a small probability, the filter
143
160
  may return true for an item not in the set (false positive). There is
@@ -145,7 +162,7 @@ class Xor16:
145
162
  """
146
163
  return self.contains(item)
147
164
 
148
- def __contains__(self, item):
165
+ def __contains__(self, item: object) -> bool:
149
166
  """
150
167
  Check if the item is in the filter. With a small probability, the filter
151
168
  may return true for an item not in the set (false positive). There is
@@ -153,13 +170,13 @@ class Xor16:
153
170
  """
154
171
  return self.contains(item)
155
172
 
156
- def __del__(self):
173
+ def __del__(self) -> None:
157
174
  """
158
175
  Free the memory allocated for the Xor16 filter.
159
176
  """
160
177
  lib.xor16_free(self.__filter)
161
178
 
162
- def populate(self, data):
179
+ def populate(self, data: Iterable[object]) -> bool:
163
180
  """
164
181
  Set the data of the filter. You may use this method to add data after
165
182
  allocating the filter with an integer size. The sizes should match.
@@ -169,7 +186,7 @@ class Xor16:
169
186
  data = list(map(lambda x: c_ulonglong((hash(x))).value, data))
170
187
  return lib.xor16_buffered_populate(data, len(data), self.__filter)
171
188
 
172
- def contains(self, item):
189
+ def contains(self, item: object) -> bool:
173
190
  """
174
191
  Check if the item is in the filter. With a small probability, the filter
175
192
  may return true for an item not in the set (false positive). There is
@@ -178,25 +195,25 @@ class Xor16:
178
195
  item = c_ulonglong((hash(item))).value
179
196
  return lib.xor16_contain(item, self.__filter)
180
197
 
181
- def size_in_bytes(self):
198
+ def size_in_bytes(self) -> int:
182
199
  """
183
200
  Return the size of the filter in bytes, not counting Python overhead.
184
201
  This value might be slightly larger than the serialized size.
185
202
  """
186
203
  return lib.xor16_size_in_bytes(self.__filter)
187
204
 
188
- def serialize(self):
205
+ def serialize(self) -> Buffer:
189
206
  """
190
- Serialize the filter to a bytes object.
207
+ Serialize the filter to a bytes-like buffer.
191
208
  """
192
209
  buffer = ffi.new("char[]", lib.xor16_serialization_bytes(self.__filter))
193
210
  lib.xor16_serialize(self.__filter, buffer)
194
211
  return ffi.buffer(buffer)
195
212
 
196
213
  @staticmethod
197
- def deserialize(buffer):
214
+ def deserialize(buffer: Buffer) -> Xor16:
198
215
  """
199
- Deserialize a bytes object to a Xor16 filter.
216
+ Deserialize a bytes-like buffer to a Xor16 filter.
200
217
  """
201
218
  self = object.__new__(Xor16)
202
219
  self.__filter = ffi.new("xor16_t *")
@@ -210,7 +227,7 @@ class Fuse8:
210
227
  It uses about one byte of memory per key.
211
228
  For large sets, a Fuse8 filter is more efficient than a Xor8 filter.
212
229
  """
213
- def __init__(self, size_or_data):
230
+ def __init__(self, size_or_data: int | Iterable[object]) -> None:
214
231
  """
215
232
  Initialize the Fuse8 filter.
216
233
  If an integer is provided, allocate a filter of that size. You must then use 'populate' to add data.
@@ -231,13 +248,13 @@ class Fuse8:
231
248
  if not lib.binary_fuse8_populate(data, len(data), self.__filter):
232
249
  raise ValueError("Unable to populate the filter")
233
250
 
234
- def __repr__(self):
251
+ def __repr__(self) -> str:
235
252
  """
236
253
  Return a string representation of the Fuse8 filter, including its size in bytes.
237
254
  """
238
255
  return "Fuse8 object with size(in bytes):{}".format(self.size_in_bytes())
239
256
 
240
- def __getitem__(self, item):
257
+ def __getitem__(self, item: object) -> bool:
241
258
  """
242
259
  Check if the item is in the filter. With a small probability, the filter
243
260
  may return true for an item not in the set (false positive). There is
@@ -245,7 +262,7 @@ class Fuse8:
245
262
  """
246
263
  return self.contains(item)
247
264
 
248
- def __contains__(self, item):
265
+ def __contains__(self, item: object) -> bool:
249
266
  """
250
267
  Check if the item is in the filter. With a small probability, the filter
251
268
  may return true for an item not in the set (false positive). There is
@@ -253,13 +270,13 @@ class Fuse8:
253
270
  """
254
271
  return self.contains(item)
255
272
 
256
- def __del__(self):
273
+ def __del__(self) -> None:
257
274
  """
258
275
  Free the memory allocated for the Fuse8 filter.
259
276
  """
260
277
  lib.binary_fuse8_free(self.__filter)
261
278
 
262
- def populate(self, data: list):
279
+ def populate(self, data: Iterable[object]) -> bool:
263
280
  """
264
281
  Set the data of the filter. You may use this method to add data after
265
282
  allocating the filter with an integer size. If the number of items
@@ -273,7 +290,7 @@ class Fuse8:
273
290
  raise MemoryError("Unable to allocate memory for filter")
274
291
  return lib.binary_fuse8_populate(data, len(data), self.__filter)
275
292
 
276
- def contains(self, item):
293
+ def contains(self, item: object) -> bool:
277
294
  """
278
295
  Check if the item is in the filter. With a small probability, the filter
279
296
  may return true for an item not in the set (false positive). There is
@@ -282,25 +299,25 @@ class Fuse8:
282
299
  item = c_ulonglong((hash(item))).value
283
300
  return lib.binary_fuse8_contain(item, self.__filter)
284
301
 
285
- def size_in_bytes(self):
302
+ def size_in_bytes(self) -> int:
286
303
  """
287
304
  Return the size of the filter in bytes, not counting Python overhead.
288
305
  This value might be slightly larger than the serialized size.
289
306
  """
290
307
  return lib.binary_fuse8_size_in_bytes(self.__filter)
291
308
 
292
- def serialize(self):
309
+ def serialize(self) -> Buffer:
293
310
  """
294
- Serialize the filter to a bytes object.
311
+ Serialize the filter to a bytes-like buffer.
295
312
  """
296
313
  buffer = ffi.new("char[]", lib.binary_fuse8_serialization_bytes(self.__filter))
297
314
  lib.binary_fuse8_serialize(self.__filter, buffer)
298
315
  return ffi.buffer(buffer)
299
316
 
300
317
  @staticmethod
301
- def deserialize(buffer):
318
+ def deserialize(buffer: Buffer) -> Fuse8:
302
319
  """
303
- Deserialize a bytes object to a Fuse8 filter.
320
+ Deserialize a bytes-like buffer to a Fuse8 filter.
304
321
  """
305
322
  self = object.__new__(Fuse8)
306
323
  self.__filter = ffi.new("binary_fuse8_t *")
@@ -314,7 +331,7 @@ class Fuse16:
314
331
  Its false positive rate is roughly 0.0015%.
315
332
  For large sets, a Fuse16 filter is more efficient than a Xor16 filter.
316
333
  """
317
- def __init__(self, size_or_data):
334
+ def __init__(self, size_or_data: int | Iterable[object]) -> None:
318
335
  """
319
336
  Initialize the Fuse16 filter.
320
337
  If an integer is provided, allocate a filter of that size. You must then use 'populate' to add data.
@@ -335,13 +352,13 @@ class Fuse16:
335
352
  if not lib.binary_fuse16_populate(data, len(data), self.__filter):
336
353
  raise ValueError("Unable to populate the filter")
337
354
 
338
- def __repr__(self):
355
+ def __repr__(self) -> str:
339
356
  """
340
357
  Return a string representation of the Fuse16 filter, including its size in bytes.
341
358
  """
342
359
  return "Fuse16 object with size(in bytes):{}".format(self.size_in_bytes())
343
360
 
344
- def __getitem__(self, item):
361
+ def __getitem__(self, item: object) -> bool:
345
362
  """
346
363
  Check if the item is in the filter. With a small probability, the filter
347
364
  may return true for an item not in the set (false positive). There is
@@ -349,7 +366,7 @@ class Fuse16:
349
366
  """
350
367
  return self.contains(item)
351
368
 
352
- def __contains__(self, item):
369
+ def __contains__(self, item: object) -> bool:
353
370
  """
354
371
  Check if the item is in the filter. With a small probability, the filter
355
372
  may return true for an item not in the set (false positive). There is
@@ -357,13 +374,13 @@ class Fuse16:
357
374
  """
358
375
  return self.contains(item)
359
376
 
360
- def __del__(self):
377
+ def __del__(self) -> None:
361
378
  """
362
379
  Free the memory allocated for the Fuse16 filter.
363
380
  """
364
381
  lib.binary_fuse16_free(self.__filter)
365
382
 
366
- def populate(self, data: list):
383
+ def populate(self, data: Iterable[object]) -> bool:
367
384
  """
368
385
  Set the data of the filter. You may use this method to add data after
369
386
  allocating the filter with an integer size. If the number of items
@@ -377,7 +394,7 @@ class Fuse16:
377
394
  raise MemoryError("Unable to allocate memory for filter")
378
395
  return lib.binary_fuse16_populate(data, len(data), self.__filter)
379
396
 
380
- def contains(self, item):
397
+ def contains(self, item: object) -> bool:
381
398
  """
382
399
  Check if the item is in the filter. With a small probability, the filter
383
400
  may return true for an item not in the set (false positive). There is
@@ -386,25 +403,25 @@ class Fuse16:
386
403
  item = c_ulonglong((hash(item))).value
387
404
  return lib.binary_fuse16_contain(item, self.__filter)
388
405
 
389
- def size_in_bytes(self):
406
+ def size_in_bytes(self) -> int:
390
407
  """
391
408
  Return the size of the filter in bytes, not counting Python overhead.
392
409
  This value might be slightly larger than the serialized size.
393
410
  """
394
411
  return lib.binary_fuse16_size_in_bytes(self.__filter)
395
412
 
396
- def serialize(self):
413
+ def serialize(self) -> Buffer:
397
414
  """
398
- Serialize the filter to a bytes object.
415
+ Serialize the filter to a bytes-like buffer.
399
416
  """
400
417
  buffer = ffi.new("char[]", lib.binary_fuse16_serialization_bytes(self.__filter))
401
418
  lib.binary_fuse16_serialize(self.__filter, buffer)
402
419
  return ffi.buffer(buffer)
403
420
 
404
421
  @staticmethod
405
- def deserialize(buffer):
422
+ def deserialize(buffer: Buffer) -> Fuse16:
406
423
  """
407
- Deserialize a bytes object to a Fuse16 filter.
424
+ Deserialize a bytes-like buffer to a Fuse16 filter.
408
425
  """
409
426
  self = object.__new__(Fuse16)
410
427
  self.__filter = ffi.new("binary_fuse16_t *")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyfusefilter
3
- Version: 1.3.2
3
+ Version: 1.3.4
4
4
  Summary: Python bindings for C implementation of xor and fuse filters
5
5
  Home-page: https://github.com/FastFilter/pyfusefilter
6
6
  Author: Amey Narkhede & Daniel Lemire
@@ -208,6 +208,7 @@ License: Apache License
208
208
  limitations under the License.
209
209
 
210
210
  Project-URL: Homepage, https://github.com/FastFilter/pyfusefilter
211
+ Classifier: Typing :: Typed
211
212
  Requires-Python: >=3.0
212
213
  Description-Content-Type: text/markdown
213
214
  License-File: LICENSE
@@ -7,7 +7,9 @@ setup.py
7
7
  lib/xor_singleheader/include/binaryfusefilter.h
8
8
  lib/xor_singleheader/include/xorfilter.h
9
9
  pyfusefilter/__init__.py
10
+ pyfusefilter/_xorfilter.pyi
10
11
  pyfusefilter/ffibuild.py
12
+ pyfusefilter/py.typed
11
13
  pyfusefilter/pyfusefilter.py
12
14
  pyfusefilter.egg-info/PKG-INFO
13
15
  pyfusefilter.egg-info/SOURCES.txt
@@ -15,7 +17,9 @@ pyfusefilter.egg-info/dependency_links.txt
15
17
  pyfusefilter.egg-info/requires.txt
16
18
  pyfusefilter.egg-info/top_level.txt
17
19
  tests/__init__.py
20
+ tests/test_annotations.py
18
21
  tests/test_fuse16.py
19
22
  tests/test_fuse8.py
20
23
  tests/test_xor16.py
21
- tests/test_xor8.py
24
+ tests/test_xor8.py
25
+ tests/typecheck_api.py
@@ -1,9 +1,12 @@
1
1
  [tool.setuptools]
2
2
  py-modules = []
3
3
  # cffi-modules handled in setup.py
4
+
5
+ [tool.setuptools.package-data]
6
+ pyfusefilter = ["py.typed", "*.pyi"]
4
7
  [project]
5
8
  name = "pyfusefilter"
6
- version = "1.3.2"
9
+ version = "1.3.4"
7
10
  description = "Python bindings for C implementation of xor and fuse filters"
8
11
  authors = [
9
12
  {name = "Amey Narkhede", email = "ameynarkhede02@gmail.com"},
@@ -13,6 +16,9 @@ dependencies = ["cffi", "xxhash"]
13
16
  readme = "README.md"
14
17
  license = {file = "LICENSE"}
15
18
  requires-python = ">=3.0"
19
+ classifiers = [
20
+ "Typing :: Typed",
21
+ ]
16
22
 
17
23
  [project.urls]
18
24
  Homepage = "https://github.com/FastFilter/pyfusefilter"
@@ -23,11 +29,16 @@ build-backend = "setuptools.build_meta"
23
29
 
24
30
  # cibuildwheel settings live in pyproject-cibuildwheel.toml (see wheels.yml).
25
31
 
32
+ [tool.mypy]
33
+ python_version = "3.12"
34
+ # Build script. It is not part of the runtime API.
35
+ exclude = ["ffibuild\\.py"]
36
+
26
37
  [tool.pdoc]
27
38
  # pdoc configuration
28
39
  name = "pyfusefilter"
29
40
  description = "Python bindings for C implementation of xor and fuse filters"
30
- version = "1.3.2"
41
+ version = "1.3.4"
31
42
  author = "Amey Narkhede & Daniel Lemire"
32
43
  author_email = "daniel@lemire.me"
33
44
  url = "https://github.com/FastFilter/pyfusefilter"
@@ -3,7 +3,7 @@ import os
3
3
 
4
4
  setup(
5
5
  name="pyfusefilter",
6
- version="1.3.2",
6
+ version="1.3.4",
7
7
  description="Python bindings for C implementation of xorfilter",
8
8
  long_description=open("README.md", "r", encoding='utf-8').read(),
9
9
  long_description_content_type="text/markdown",
@@ -13,6 +13,7 @@ setup(
13
13
  # license handled in pyproject.toml
14
14
  python_requires=">=3.0",
15
15
  packages=find_packages(),
16
+ package_data={"pyfusefilter": ["py.typed", "*.pyi"]},
16
17
  ext_package="pyfusefilter",
17
18
  # install_requires handled in pyproject.toml
18
19
  cffi_modules=["pyfusefilter/ffibuild.py:ffi"],
File without changes
@@ -0,0 +1,37 @@
1
+ import inspect
2
+ import sys
3
+
4
+ from pyfusefilter import Fuse8, Fuse16, Xor8, Xor16
5
+ from pyfusefilter.pyfusefilter import Buffer
6
+
7
+
8
+ def test_public_signatures():
9
+ for cls in (Xor8, Xor16, Fuse8, Fuse16):
10
+ init = inspect.signature(cls.__init__)
11
+ assert init.parameters["size_or_data"].annotation == "int | Iterable[object]"
12
+ assert init.return_annotation == "None"
13
+
14
+ populate = inspect.signature(cls.populate)
15
+ assert populate.parameters["data"].annotation == "Iterable[object]"
16
+ assert populate.return_annotation == "bool"
17
+
18
+ contains = inspect.signature(cls.contains)
19
+ assert contains.parameters["item"].annotation == "object"
20
+ assert contains.return_annotation == "bool"
21
+
22
+ assert inspect.signature(cls.size_in_bytes).return_annotation == "int"
23
+ assert inspect.signature(cls.serialize).return_annotation == "Buffer"
24
+ deserialize = inspect.signature(cls.deserialize)
25
+ assert deserialize.parameters["buffer"].annotation == "Buffer"
26
+ assert deserialize.return_annotation == cls.__name__
27
+
28
+
29
+ def test_serialize_is_a_buffer():
30
+ filt = Xor8([1, 2, 3])
31
+ raw = filt.serialize()
32
+ assert not isinstance(raw, bytes)
33
+ memoryview(raw)
34
+ if sys.version_info >= (3, 12):
35
+ assert isinstance(raw, Buffer)
36
+ assert Xor8.deserialize(raw).contains(1)
37
+ assert Xor8.deserialize(bytes(raw)).contains(2)
@@ -1,5 +1,5 @@
1
1
  from pyfusefilter import Fuse16
2
- from random import sample
2
+ from random import randrange
3
3
  import tempfile, os
4
4
 
5
5
 
@@ -66,7 +66,10 @@ def test_fuse16_few_segments():
66
66
  # https://github.com/FastFilter/xor_singleheader/issues/77
67
67
  for size in (3551, 11504, 11521, 12372, 13224, 37454):
68
68
  for _ in range(5):
69
- keys = sample(range(1 << 62), size)
69
+ keys = set()
70
+ while len(keys) < size:
71
+ keys.add(randrange(1 << 62))
72
+ keys = list(keys)
70
73
  filter = Fuse16(keys)
71
74
  for key in keys:
72
75
  assert key in filter
@@ -1,5 +1,5 @@
1
1
  from pyfusefilter import Fuse8
2
- from random import sample
2
+ from random import randrange
3
3
  import tempfile, os
4
4
 
5
5
  def test_readme():
@@ -65,7 +65,10 @@ def test_fuse8_few_segments():
65
65
  # https://github.com/FastFilter/xor_singleheader/issues/77
66
66
  for size in (3551, 11504, 11521, 12372, 13224, 37454):
67
67
  for _ in range(5):
68
- keys = sample(range(1 << 62), size)
68
+ keys = set()
69
+ while len(keys) < size:
70
+ keys.add(randrange(1 << 62))
71
+ keys = list(keys)
69
72
  filter = Fuse8(keys)
70
73
  for key in keys:
71
74
  assert key in filter
@@ -0,0 +1,18 @@
1
+ """Examples mypy checks against the installed annotations."""
2
+
3
+ from pyfusefilter import Fuse8, Fuse16, Xor8, Xor16
4
+
5
+
6
+ def round_trip(keys: list[object]) -> bool:
7
+ filt = Xor8(keys)
8
+ raw = filt.serialize()
9
+ restored = Xor8.deserialize(raw)
10
+ populated = filt.populate(range(len(keys)))
11
+ return (
12
+ restored.contains(keys[0])
13
+ and isinstance(filt.size_in_bytes(), int)
14
+ and populated
15
+ and Fuse8(keys).contains(keys[0])
16
+ and Xor16(len(keys)).populate(keys)
17
+ and Fuse16(1).serialize() is not None
18
+ )
@@ -1,2 +0,0 @@
1
- include lib/xor_singleheader/include/binaryfusefilter.h
2
- include lib/xor_singleheader/include/xorfilter.h
File without changes
File without changes
File without changes