New submission from Serhiy Storchaka <storchaka+cpyt...@gmail.com>:

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.

----------
components: Library (Lib)
messages: 345892
nosy: mark.dickinson, rhettinger, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Deprecate using random.randrange() with non-integers
type: enhancement
versions: Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue37319>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to