Skip to content

Commit 9f49321

Browse files
committed
fix: handle null base case in allotment function
1 parent fbf9820 commit 9f49321

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/nilql/nilql.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ def allot(
702702
>>> allot(1.23)
703703
Traceback (most recent call last):
704704
...
705-
TypeError: integer, boolean, string, list, or dictionary expected
705+
TypeError: integer, boolean, string, list, dictionary, or None expected
706706
>>> allot({'id': 0, 'age': {'$allot': [1, 2, 3], 'extra': [1, 2, 3]}})
707707
Traceback (most recent call last):
708708
...
@@ -716,8 +716,8 @@ def allot(
716716
...
717717
ValueError: number of shares in subdocument is not consistent
718718
"""
719-
# Return a single share for integer and string values.
720-
if isinstance(document, (int, bool, str)):
719+
# Values and ``None`` are base cases; return a single share.
720+
if isinstance(document, (int, bool, str)) or document is None:
721721
return [document]
722722

723723
if isinstance(document, list):
@@ -791,7 +791,7 @@ def allot(
791791
return shares
792792

793793
raise TypeError(
794-
'integer, boolean, string, list, or dictionary expected'
794+
'integer, boolean, string, list, dictionary, or None expected'
795795
)
796796

797797
def unify(
@@ -830,11 +830,13 @@ def unify(
830830
>>> data = {
831831
... 'a': [1, [2, 3]],
832832
... 'b': [4, 5, 6],
833+
... 'c': None
833834
... }
834835
>>> sk = SecretKey.generate({'nodes': [{}, {}, {}]}, {'store': True})
835836
>>> encrypted = {
836837
... 'a': {'$allot': [encrypt(sk, 1), [encrypt(sk, 2), encrypt(sk, 3)]]},
837-
... 'b': {'$allot': [encrypt(sk, 4), encrypt(sk, 5), encrypt(sk, 6)]}
838+
... 'b': {'$allot': [encrypt(sk, 4), encrypt(sk, 5), encrypt(sk, 6)]},
839+
... 'c': None
838840
... }
839841
>>> shares = allot(encrypted)
840842
>>> decrypted = unify(sk, shares)

0 commit comments

Comments
 (0)