[issue42772] randrange() mishandles step when stop is None

2021-01-02 Thread Raymond Hettinger
Change by Raymond Hettinger : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___ ___

[issue42772] randrange() mishandles step when stop is None

2021-01-02 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset 768fa145cfec2a0599802b74fc31d2bc2812ed96 by Raymond Hettinger in branch 'master': bpo-42772: Step argument ignored when stop is None. (GH-24018) https://github.com/python/cpython/commit/768fa145cfec2a0599802b74fc31d2bc2812ed96 -- _

[issue42772] randrange() mishandles step when stop is None

2020-12-30 Thread Raymond Hettinger
Change by Raymond Hettinger : -- assignee: -> rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: htt

[issue42772] randrange() mishandles step when stop is None

2020-12-30 Thread Raymond Hettinger
Raymond Hettinger added the comment: Upon further reflection, I think these cases should raise a TypeError because the meaning is ambiguous: randrange(1000, step=10) # Could only mean start=0 stop=1000 step=10 but that conflicts with: randrange(1000, None, 100) # Has no reasonable

[issue42772] randrange() mishandles step when stop is None

2020-12-30 Thread Raymond Hettinger
Change by Raymond Hettinger : -- keywords: +patch pull_requests: +22858 stage: -> patch review pull_request: https://github.com/python/cpython/pull/24018 ___ Python tracker __

[issue42772] randrange() mishandles step when stop is None

2020-12-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: > Should I restore that optimization in issue37319? Yes, but to fix the bug it needs to occur earlier in the code (currently line 314): if stop is None and step is _ONE: <-- Line 314 ^ <-- Add this And again lat

[issue42772] randrange() mishandles step when stop is None

2020-12-28 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: > Another solution is to use an identity test for the step argument Should I restore that optimization in issue37319? -- ___ Python tracker __

[issue42772] randrange() mishandles step when stop is None

2020-12-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: Another solution is to use an identity test for the step argument _one = 1 class Random: def randrange(start, stop=None, step=_one): ... if stop is None and step is _one: if istart > 0:

[issue42772] randrange() mishandles step when stop is None

2020-12-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: Note, we can't actually use "self.choice(range(*args))" because the underlying len() call can Overflow. If it does, the components need to be computed manually. -- ___ Python tracker

[issue42772] randrange() mishandles step when stop is None

2020-12-28 Thread Raymond Hettinger
Change by Raymond Hettinger : -- nosy: +tim.peters ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://ma

[issue42772] randrange() mishandles step when stop is None

2020-12-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: One fix is to move up the code for converting step to istep and then modify the early out test to: if stop is None and istep == 1: if istart > 0: return self._randbelow(istart) That would have the downside of slowing

[issue42772] randrange() mishandles step when stop is None

2020-12-28 Thread Raymond Hettinger
Change by Raymond Hettinger : -- assignee: rhettinger -> versions: +Python 3.9 ___ Python tracker ___ ___ Python-bugs-list mailing

[issue42772] randrange() mishandles step when stop is None

2020-12-28 Thread Raymond Hettinger
Change by Raymond Hettinger : -- assignee: -> rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: htt

[issue42772] randrange() mishandles step when stop is None

2020-12-28 Thread Raymond Hettinger
New submission from Raymond Hettinger : When stop is None, the step argument is ignored: >>> randrange(1000, None, 100) 651 >>> randrange(1000, step=100) 673 -- components: Library (Lib) messages: 383919 nosy: rhettinger, serhiy.storchaka priority: normal severity: normal status: open