Message345892
Unlike other range()-like functions random.randrange() accepts not only integers and integer-like objects (implementing __index__), but any numbers with integral values, like 3.0 or Decimal(3). In 3.8 using __int__ for implicit converting to C integers were deprecated, and likely will be forbidden in 3.9. __index__ is now preferable.
I propose to deprecate accepting non-integer arguments in random.randrange() and use __index__ instead of __int__ for converting values. At end it will lead to simpler and faster code. Instead of
istart = _int(start)
if istart != start:
raise ValueError("non-integer arg 1 for randrange()")
we could use just
start = _index(start)
It will help also in converting the randrange() implementation to C.
See also issue37315. |
|
Date |
User |
Action |
Args |
2019-06-17 19:52:35 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, rhettinger, mark.dickinson |
2019-06-17 19:52:35 | serhiy.storchaka | set | messageid: <1560801155.55.0.20318571261.issue37319@roundup.psfhosted.org> |
2019-06-17 19:52:35 | serhiy.storchaka | link | issue37319 messages |
2019-06-17 19:52:35 | serhiy.storchaka | create | |
|