Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

random.shuffle's random= argument got deprecated #1479

Closed
isidentical opened this issue May 31, 2020 · 9 comments · Fixed by #1480
Closed

random.shuffle's random= argument got deprecated #1479

isidentical opened this issue May 31, 2020 · 9 comments · Fixed by #1480

Comments

@isidentical
Copy link

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
@asottile
Copy link
Member

well that's annoying.

@serhiy-storchaka
Copy link

Why not to use just

fixed_random.shuffle(seq)

?

@asottile
Copy link
Member

is that documented? I don't see it on https://docs.python.org/3/library/random.html

@serhiy-storchaka
Copy link

@asottile
Copy link
Member

yeah that's what the current code is using?

@isidentical
Copy link
Author

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 seq

@asottile
Copy link
Member

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
Copy link

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
Copy link
Member

🤦 and here I was expecting it to be documented under https://docs.python.org/3/library/random.html#random.Random

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants