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, tim.peters
Date 2019-06-20.07:43:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Why this code uses int() at all? My guess is that it was added for earlier detection of user errors, otherwise the user could get a TypeError or AttributeError with unrelated message, or even a wrong result. int() is used just for type checking. But it is not good tool for this. int() does several different actions:

1. Parses string representation of integer.

2. Converts a real number to an integer with some truncation.

3. Losslessly converts an int-like number into an instance of int.

The first two options are not applicable here, so we need an additional check

        if istart != start:
            raise ValueError("non-integer arg 1 for randrange()")

And this is not perfect: for randrange('5') we get a ValueError instead of expected TypeError.

operator.index() is better tool for this.
Date User Action Args
2019-06-20 07:43:34serhiy.storchakasetrecipients: + serhiy.storchaka, tim.peters, rhettinger, mark.dickinson
2019-06-20 07:43:34serhiy.storchakasetmessageid: <>
2019-06-20 07:43:34serhiy.storchakalinkissue37319 messages
2019-06-20 07:43:34serhiy.storchakacreate