[issue42222] Modernize integer test/conversion in randrange()

2022-02-03 Thread Petr Viktorin


Petr Viktorin  added the comment:

Since this is a user-visible change in 3.11, could you add a What's New entry?

--
nosy: +petr.viktorin

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42222] Modernize integer test/conversion in randrange()

2021-10-19 Thread Łukasz Langa

Change by Łukasz Langa :


--
versions: +Python 3.11 -Python 3.10

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42222] Modernize integer test/conversion in randrange()

2021-10-19 Thread Łukasz Langa

Łukasz Langa  added the comment:


New changeset 574241632bd19e56ed488ee4d8999aefc6a8d7cd by Serhiy Storchaka in 
branch 'main':
bpo-4: Improve tests for invalid argument types in randrange() (GH-29021)
https://github.com/python/cpython/commit/574241632bd19e56ed488ee4d8999aefc6a8d7cd


--
nosy: +lukasz.langa

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42222] Modernize integer test/conversion in randrange()

2021-10-18 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
pull_requests: +27294
pull_request: https://github.com/python/cpython/pull/29021

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42222] Modernize integer test/conversion in randrange()

2021-10-16 Thread Raymond Hettinger


Raymond Hettinger  added the comment:


New changeset 5afa0a411243210a30526c7459a0ccff5cb88494 by Raymond Hettinger in 
branch 'main':
bpo-4: Remove deprecated support for non-integer values (GH-28983)
https://github.com/python/cpython/commit/5afa0a411243210a30526c7459a0ccff5cb88494


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42222] Modernize integer test/conversion in randrange()

2021-10-15 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
pull_requests: +27270
pull_request: https://github.com/python/cpython/pull/28983

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42222] Modernize integer test/conversion in randrange()

2020-12-28 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42222] Modernize integer test/conversion in randrange()

2020-12-28 Thread Raymond Hettinger


Raymond Hettinger  added the comment:


New changeset a9621bb301dba44494e81edc00e3a3b62c96af26 by Raymond Hettinger in 
branch 'master':
bpo-4: Modernize integer test/conversion in randrange() (#23064)
https://github.com/python/cpython/commit/a9621bb301dba44494e81edc00e3a3b62c96af26


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42222] Modernize integer test/conversion in randrange()

2020-12-25 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

There is another randrange() oddity.  If stop is None, the step argument is 
ignored:

>>> randrange(100, stop=None, step=10)
4

If we want to fully harmonize with range(), then randrange() should only accept 
positional arguments and should not allow None for the stop argument.  That 
would leave the unoptimized implementation equivalent to:

def randrange(self, /, *args):
return self.choice(range(*args))

The actual implementation can retain its fast paths and have a nicer looking 
signature perhaps using __text_signature__.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42222] Modernize integer test/conversion in randrange()

2020-12-24 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
assignee:  -> rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42222] Modernize integer test/conversion in randrange()

2020-11-07 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

To put what I said another way: both items are mental paper cuts and I see 
benefit to both coredevs and users in getting rid of them.  That is not to say 
'no cost', but that there is a real benefit to be balanced against the real 
cost.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42222] Modernize integer test/conversion in randrange()

2020-11-07 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

To me, ValueError("non-integer arg 1 for randrange()") (ValueError('bad type') 
is a bit painful to read.  We do sometime fix such bugs, when not documented, 
in future releases.

Current the doc, "Return a randomly selected element from range(start, stop, 
step). This is equivalent to choice(range(start, stop, step))", implies that 
both accept the same values, which most would expect anyway from the names.  
Being selectively 'generous' in what is accepted is confusing.

For the future: both range and math.factorial raise
TypeError: 'float' object cannot be interpreted as an integer
The consistency is nice.  randrange should say the same after deprecation.

--
nosy: +terry.reedy

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42222] Modernize integer test/conversion in randrange()

2020-10-31 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

10**9 isn't much harder than 10E9 ;-)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42222] Modernize integer test/conversion in randrange()

2020-10-31 Thread Vedran Čačić

Vedran Čačić  added the comment:

Yes, the ability to write randrange(1e9) is sometimes nice. And the fact that 
it might give the number outside the intended range with probability 1e-17 is 
not really an important argument (people have bad intuitions about very small 
probabilities). But if we intend to be consistent with range, then of course 
this must go.

--
nosy: +veky

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42222] Modernize integer test/conversion in randrange()

2020-10-31 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

User feedback concur with making the change:  
https://twitter.com/raymondh/status/1322607969754775552

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42222] Modernize integer test/conversion in randrange()

2020-10-31 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

I think and always thought that integer domain functions should not accept 
non-integer arguments even with integer value. This is why I submitted numerous 
patches for deprecating and finally removing support of non-integer arguments 
in most of integer domain functions. C implemented functions which use 
PyArg_Parse("i") or PyLong_AsLong() for parsing arguments use now index() 
instead of int(). They emit a deprecation warning for non-integers in 3.8 and 
3.9 and raise type error since 3.10. math.factorial() emits a warning only in 
3.9.

Issue37319 (sorry, I wrote incorrect issue number in msg380085) was initially 
opened for 3.9, so we could convert warnings into errors in 3.10 or 3.11.

Currently randrange(1e25) can return value larger than 10**25, because 
int(1e25) == 1905969664 > 10**25.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42222] Modernize integer test/conversion in randrange()

2020-10-31 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

> These propositions were rejected by you. 
> Have you reconsidered your decision?

I was reluctant to break any existing code.
Now, I'm unsure and am inclined to harmonize it with range().

What do you think?
Should we have ever supported float arguments
for an integer domain function?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42222] Modernize integer test/conversion in randrange()

2020-10-31 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

It changes the behavior. Currently randrange(10.0) works, but with PR 23064 it 
would fail.

See issue40046 with a ready PR for increasing coverage for the random module. 
If it would accepted, some tests would fail with PR 23064.

If you want to deprecate accepting float arguments, there was issue40046 with a 
ready PR.

These propositions were rejected by you. Have you reconsidered your decision?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42222] Modernize integer test/conversion in randrange()

2020-10-31 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

I had forgotten. It looks like float arguments were allowed:

>>> randrange(10.0, 20.0, 2.0)
16

Is this worth going through a deprecation cycle to get the code cleaned-up or 
should we live with it as is?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42222] Modernize integer test/conversion in randrange()

2020-10-31 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

And, if we were willing to correct the exception type from ValueError to 
TypeError, the code could be made simpler, faster, and more in line with user 
expectations.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42222] Modernize integer test/conversion in randrange()

2020-10-31 Thread Raymond Hettinger


New submission from Raymond Hettinger :

Move the int(x)==x test and conversion into the C code for operator.index().

--
components: Library (Lib)
messages: 380082
nosy: rhettinger, serhiy.storchaka, tim.peters
priority: normal
severity: normal
status: open
title: Modernize integer test/conversion in randrange()
versions: Python 3.10

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42222] Modernize integer test/conversion in randrange()

2020-10-31 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
keywords: +patch
pull_requests: +21983
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/23064

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com