Mercurial > evolve
changeset 4754:75307f276a79
py3: make random topic name generation consistent across py2/py3
random.choice() (and others based on random.randint()) changed between
py2 and py3 without a way to get the py2 behavior. However,
random.random() did not change, so we can re-implement random.choice()
based on that.
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 17 Jul 2019 11:45:37 -0700 |
parents | 87d3955467b4 |
children | 8664231b47ac |
files | hgext3rd/topic/randomname.py |
diffstat | 1 files changed, 4 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext3rd/topic/randomname.py Fri Jul 12 17:02:35 2019 -0700 +++ b/hgext3rd/topic/randomname.py Wed Jul 17 11:45:37 2019 -0700 @@ -1005,6 +1005,9 @@ ] def randomtopicname(ui): + # Re-implement random.choice() in the way it was written in Python 2. + def choice(things): + return things[int(len(things) * random.random())] if ui.configint("devel", "randomseed"): random.seed(ui.configint("devel", "randomseed")) - return random.choice(adjectives) + "-" + random.choice(animals) + return choice(adjectives) + "-" + choice(animals)