Skip to content

bpo-33228: Use Random.choices in tempfile #6383

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Lib/tempfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def _sanitize_params(prefix, suffix, dir):
class _RandomNameSequence:
"""An instance of _RandomNameSequence generates an endless
sequence of unpredictable strings which can safely be incorporated
into file names. Each string is six characters long. Multiple
into file names. Each string is eight characters long. Multiple
threads can safely use the same instance at the same time.

_RandomNameSequence is an iterator."""
Expand All @@ -151,9 +151,7 @@ def __iter__(self):
return self

def __next__(self):
c = self.characters
choose = self.rng.choice
letters = [choose(c) for dummy in range(8)]
letters = self.rng.choices(self.characters, k=8)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these kinds of trivial changes should be done. There should be a preference for code stability.

return ''.join(letters)

def _candidate_tempdir_list():
Expand Down