Skip to content

Commit

Permalink
fix: Provide a sequence to random.sample
Browse files Browse the repository at this point in the history
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
  • Loading branch information
feanil committed Apr 12, 2024
1 parent 3115aac commit e60ec96
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions xmodule/library_content_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def make_selection(cls, selected, children, max_count, mode):
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?
Expand All @@ -233,7 +233,7 @@ def make_selection(cls, selected, children, max_count, mode):
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.")
Expand Down

0 comments on commit e60ec96

Please sign in to comment.