GeezerVison is showing github.com — random.shuffle's random= argument got deprecated · Issue #1479 · pre-commit/pre-commit
random.shuffle's random= argument got deprecated #1479
Description
Related issue: bpo-40465.
black..................................................................../home/isidentical/.venv/lib/python3.10/site-packages/pre_commit/languages/helpers.py:95: DeprecationWarning: The *random* parameter to shuffle() has been deprecated
since Python 3.9 and will be removed in a subsequent version.
random.shuffle(seq, random=fixed_random.random)
Passed
Activity
asottile commented on May 31, 2020
serhiy-storchaka commented on May 31, 2020
Why not to use just
fixed_random.shuffle(seq)
?
asottile commented on May 31, 2020
serhiy-storchaka commented on May 31, 2020
asottile commented on May 31, 2020
yeah that's what the current code is using?
isidentical commented on May 31, 2020
yeah that's what the current code is using?
I think what @serhiy-storchaka is suggesting that, since you set a custom seed you can use directly fixed_random's shuffle method.
def _shuffled(seq: Sequence[str]) -> List[str]:
"""Deterministically shuffle"""
fixed_random = random.Random()
fixed_random.seed(FIXED_RANDOM_SEED, version=1)
seq = list(seq)
fixed_random.shuffle(seq)
return seqasottile commented on May 31, 2020
I get that, but where in the documentation does it say that Random has a shuffle method -- the link above is to the module's function
serhiy-storchaka commented on May 31, 2020
The functions supplied by this module are actually bound methods of a hidden instance of the random.Random class. You can instantiate your own instances of Random to get generators that don’t share state.
asottile commented on May 31, 2020
Metadata
Metadata
Development
No branches or pull requestsIssue actions