python-compat: adapt to Python 3.11 BC breakage with `random.sample` stable
authorRaphaël Gomès <rgomes@octobus.net>
Wed, 23 Nov 2022 14:42:11 +0100
branchstable
changeset 49647 c217d94cdd9d
parent 49645 c4874ebe8644
child 49656 c6f0bcb7bc57
python-compat: adapt to Python 3.11 BC breakage with `random.sample` As per https://docs.python.org/3/whatsnew/3.11.html#porting-to-python-3-11: "The population parameter of `random.sample()` must be a sequence, and automatic conversion of sets to lists is no longer supported. Also, if the sample size is larger than the population size, a `ValueError` is raised"
mercurial/setdiscovery.py
--- a/mercurial/setdiscovery.py	Tue Nov 22 11:55:26 2022 -0500
+++ b/mercurial/setdiscovery.py	Wed Nov 23 14:42:11 2022 +0100
@@ -99,9 +99,9 @@
     """
     if len(sample) <= desiredlen:
         return sample
+    sample = list(sample)
     if randomize:
         return set(random.sample(sample, desiredlen))
-    sample = list(sample)
     sample.sort()
     return set(sample[:desiredlen])