Skip to content

Commit 7eb6f56

Browse files
committed
fix: handle float base case in allotment function
1 parent e64cb18 commit 7eb6f56

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "nilql"
3-
version = "0.0.0a11"
3+
version = "0.0.0a12"
44
description = "Library for working with encrypted data within nilDB queries and replies."
55
license = {text = "MIT"}
66
readme = "README.rst"

src/nilql/nilql.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -789,10 +789,10 @@ def allot(
789789
Any attempt to convert a document that has an incorrect structure raises
790790
an exception.
791791
792-
>>> allot(1.23)
792+
>>> allot({1, 2, 3})
793793
Traceback (most recent call last):
794794
...
795-
TypeError: integer, boolean, string, list, dictionary, or None expected
795+
TypeError: boolean, integer, float, string, list, dictionary, or None expected
796796
>>> allot({'id': 0, 'age': {'%allot': [1, 2, 3], 'extra': [1, 2, 3]}})
797797
Traceback (most recent call last):
798798
...
@@ -807,7 +807,7 @@ def allot(
807807
ValueError: number of shares in subdocument is not consistent
808808
"""
809809
# Values and ``None`` are base cases; return a single share.
810-
if isinstance(document, (int, bool, str)) or document is None:
810+
if isinstance(document, (bool, int, float, str)) or document is None:
811811
return [document]
812812

813813
if isinstance(document, list):
@@ -881,7 +881,7 @@ def allot(
881881
return shares
882882

883883
raise TypeError(
884-
'integer, boolean, string, list, dictionary, or None expected'
884+
'boolean, integer, float, string, list, dictionary, or None expected'
885885
)
886886

887887
def unify(
@@ -920,13 +920,15 @@ def unify(
920920
>>> data = {
921921
... 'a': [1, [2, 3]],
922922
... 'b': [4, 5, 6],
923-
... 'c': None
923+
... 'c': None,
924+
... 'd': 1.23
924925
... }
925926
>>> sk = SecretKey.generate({'nodes': [{}, {}, {}]}, {'store': True})
926927
>>> encrypted = {
927928
... 'a': {'%allot': [encrypt(sk, 1), [encrypt(sk, 2), encrypt(sk, 3)]]},
928929
... 'b': {'%allot': [encrypt(sk, 4), encrypt(sk, 5), encrypt(sk, 6)]},
929-
... 'c': None
930+
... 'c': None,
931+
... 'd': 1.23
930932
... }
931933
>>> shares = allot(encrypted)
932934
>>> decrypted = unify(sk, shares)

0 commit comments

Comments
 (0)