[Python-checkins] tempfile: Use random.choises() instead of choise() (GH-23068)
methane
webhook-mailer at python.org
Sun Nov 1 06:02:08 EST 2020
https://github.com/python/cpython/commit/d2810054c7ee1b4ce925fc520224b595b53bf4b4
commit: d2810054c7ee1b4ce925fc520224b595b53bf4b4
branch: master
author: Inada Naoki <songofacandy at gmail.com>
committer: methane <songofacandy at gmail.com>
date: 2020-11-01T20:02:03+09:00
summary:
tempfile: Use random.choises() instead of choise() (GH-23068)
files:
M Lib/tempfile.py
M Lib/test/test_tempfile.py
diff --git a/Lib/tempfile.py b/Lib/tempfile.py
index 770f72c25295c..c3fe61aa0af4f 100644
--- a/Lib/tempfile.py
+++ b/Lib/tempfile.py
@@ -143,10 +143,7 @@ def __iter__(self):
return self
def __next__(self):
- c = self.characters
- choose = self.rng.choice
- letters = [choose(c) for dummy in range(8)]
- return ''.join(letters)
+ return ''.join(self.rng.choices(self.characters, k=8))
def _candidate_tempdir_list():
"""Generate a list of candidate temporary directories which
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py
index 8ace883d74bb2..77d710efaf107 100644
--- a/Lib/test/test_tempfile.py
+++ b/Lib/test/test_tempfile.py
@@ -153,8 +153,8 @@ def setUp(self):
self.r = tempfile._RandomNameSequence()
super().setUp()
- def test_get_six_char_str(self):
- # _RandomNameSequence returns a six-character string
+ def test_get_eight_char_str(self):
+ # _RandomNameSequence returns a eight-character string
s = next(self.r)
self.nameCheck(s, '', '', '')
More information about the Python-checkins
mailing list