This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients mark.dickinson, rhettinger, serhiy.storchaka
Date 2019-06-17.19:52:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1560801155.55.0.20318571261.issue37319@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-06-17 19:52:35serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, mark.dickinson
2019-06-17 19:52:35serhiy.storchakasetmessageid: <1560801155.55.0.20318571261.issue37319@roundup.psfhosted.org>
2019-06-17 19:52:35serhiy.storchakalinkissue37319 messages
2019-06-17 19:52:35serhiy.storchakacreate