[issue37708] Harmonize random.choice(s) behavior with random.sample on iterators

Raymond Hettinger report at bugs.python.org
Wed Jul 31 19:59:17 EDT 2019


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

The sample() function accepts d.keys() because a keys view is registered as being an instance of collections.abc.Set.  We have to do that because sample() is specifically documented as accepting sets.  If we had it do over again, that functionality would likely not be supported (it implicitly the population into a tuple).

For a fine-grained function like choice() that implicit population conversion would make no sense at all.  For choices(), we can choose not to make that API mistake again.

Thanks for the suggestion, but I am going to decline.  It isn't something that we need in practice and it would add complication for near zero gain.  (Also, there is no rule that all of these functions have to accept the same kinds of inputs -- different algorithms and different use cases allow for some flexibility).

----------
resolution:  -> rejected
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37708>
_______________________________________


More information about the Python-bugs-list mailing list