fix: Provide a sequence to random.sample

The sample function used to automatically convert sets to sequences but
that is no longer supported starting in 3.11 so we have to do it
manually.

Reference: https://docs.python.org/3/library/random.html#random.sample
This commit is contained in:
Feanil Patel
2024-03-15 15:30:01 -04:00
parent b20ac9c515
commit 87b9c759f0

View File

@@ -221,7 +221,7 @@ class LibraryContentBlock(
overlimit_block_keys = set()
if len(selected_keys) > max_count:
num_to_remove = len(selected_keys) - max_count
overlimit_block_keys = set(rand.sample(selected_keys, num_to_remove))
overlimit_block_keys = set(rand.sample(list(selected_keys), num_to_remove))
selected_keys -= overlimit_block_keys
# Do we have enough blocks now?
@@ -233,7 +233,7 @@ class LibraryContentBlock(
pool = valid_block_keys - selected_keys
if mode == "random":
num_to_add = min(len(pool), num_to_add)
added_block_keys = set(rand.sample(pool, num_to_add))
added_block_keys = set(rand.sample(list(pool), num_to_add))
# We now have the correct n random children to show for this user.
else:
raise NotImplementedError("Unsupported mode.")