diff options
author | Raymond Hettinger <python@rcn.com> | 2009-02-24 11:27:15 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2009-02-24 11:27:15 (GMT) |
commit | 886687dcda94bfb4b1c5bd1c5152ef91011a9c1c (patch) | |
tree | 135c7f18f3e389bc75c9342ffd9d2880581848c1 /Lib/random.py | |
parent | 9aa53c2f0151032c5592d0c8b112fc35d7f77078 (diff) | |
download | cpython-886687dcda94bfb4b1c5bd1c5152ef91011a9c1c.zip cpython-886687dcda94bfb4b1c5bd1c5152ef91011a9c1c.tar.gz cpython-886687dcda94bfb4b1c5bd1c5152ef91011a9c1c.tar.bz2 |
Use ABCs to validate documented restriction to Sets or Sequences.
Diffstat (limited to 'Lib/random.py')
-rw-r--r-- | Lib/random.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/random.py b/Lib/random.py index 95f4411..afec8a0 100644 --- a/Lib/random.py +++ b/Lib/random.py @@ -43,6 +43,7 @@ from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin from os import urandom as _urandom from binascii import hexlify as _hexlify +import collections as _collections __all__ = ["Random","seed","random","uniform","randint","choice","sample", "randrange","shuffle","normalvariate","lognormvariate", @@ -296,10 +297,10 @@ class Random(_random.Random): # preferred since the list takes less space than the # set and it doesn't suffer from frequent reselections. - if isinstance(population, (set, frozenset)): + if isinstance(population, _collections.Set): population = tuple(population) - if not hasattr(population, '__getitem__') or hasattr(population, 'keys'): - raise TypeError("Population must be a sequence or set. For dicts, use dict.keys().") + if not isinstance(population, _collections.Sequence): + raise TypeError("Population must be a sequence or Set. For dicts, use list(d).") random = self.random n = len(population) if not 0 <= k <= n: |