wxWidgets / Phoenix

wxPython's Project Phoenix. A new implementation of wxPython, better, stronger, faster than he was before.
http://wxpython.org/
2.21k stars 509 forks source link

Python 3.12 unit tests in test_dcDrawLists.py fail #2507

Closed bnavigator closed 4 months ago

bnavigator commented 4 months ago

Operating system: openSUSE Tumbleweed rpmbuild wxPython version & source: 4.2.1 sdist from PyPI, lightly patched Python version & source: openSUSE Tumbleweed python312 rpm

Description of the problem:

Python 3.12 does not accept floats for random.randint() anymore.

Code Example (click to expand) ```python Python 3.11.6 (main, Nov 15 2023, 09:22:27) [GCC] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import random >>> random.randint(1, 20/2) 10 >>> 20/2 10.0 ``` ```python Python 3.12.1 (main, Dec 15 2023, 10:49:50) [GCC] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import random >>> random.randint(1,20/2) Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python3.12/random.py", line 336, in randint return self.randrange(a, b+1) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib64/python3.12/random.py", line 312, in randrange istop = _index(stop) ^^^^^^^^^^^^ TypeError: 'float' object cannot be interpreted as an integer >>> 20/2 10.0 ``` ```python [ 1473s] =================================== FAILURES =================================== [ 1473s] ___________________ dcDrawLists_Tests.test_dcDrawElipseLists ___________________ [ 1473s] [gw2] linux -- Python 3.12.1 /usr/bin/python3.12 [ 1473s] self = [ 1473s] [ 1473s] def test_dcDrawElipseLists(self): [ 1473s] pnl = wx.Panel(self.frame) [ 1473s] self.frame.SetSize((w,h)) [ 1473s] dc = wx.ClientDC(pnl) [ 1473s] dc.SetPen(wx.Pen("BLACK", 1)) [ 1473s] dc.SetBrush( wx.Brush("RED") ) [ 1473s] [ 1473s] pens = makeRandomPens() [ 1473s] brushes = makeRandomBrushes() [ 1473s] [ 1473s] > dc.DrawEllipseList(makeRandomRectangles()) [ 1473s] [ 1473s] unittests/test_dcDrawLists.py:232: [ 1473s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ [ 1473s] unittests/test_dcDrawLists.py:66: in makeRandomRectangles [ 1473s] W = random.randint(10, w/2) [ 1473s] /usr/lib64/python3.12/random.py:336: in randint [ 1473s] return self.randrange(a, b+1) [ 1473s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ [ 1473s] [ 1473s] self = , start = 10, stop = 301.0 [ 1473s] step = 1 [ 1473s] [ 1473s] def randrange(self, start, stop=None, step=_ONE): [ 1473s] """Choose a random item from range(stop) or range(start, stop[, step]). [ 1473s] [ 1473s] Roughly equivalent to ``choice(range(start, stop, step))`` but [ 1473s] supports arbitrarily large ranges and is optimized for common cases. [ 1473s] [ 1473s] """ [ 1473s] [ 1473s] # This code is a bit messy to make it fast for the [ 1473s] # common case while still doing adequate error checking. [ 1473s] istart = _index(start) [ 1473s] if stop is None: [ 1473s] # We don't check for "step != 1" because it hasn't been [ 1473s] # type checked and converted to an integer yet. [ 1473s] if step is not _ONE: [ 1473s] raise TypeError("Missing a non-None stop argument") [ 1473s] if istart > 0: [ 1473s] return self._randbelow(istart) [ 1473s] raise ValueError("empty range for randrange()") [ 1473s] [ 1473s] # Stop argument supplied. [ 1473s] > istop = _index(stop) [ 1473s] E TypeError: 'float' object cannot be interpreted as an integer [ 1473s] [ 1473s] /usr/lib64/python3.12/random.py:312: TypeError [ 1473s] _________________ dcDrawLists_Tests.test_dcDrawRectangleArray __________________ [ 1473s] [gw2] linux -- Python 3.12.1 /usr/bin/python3.12 [ 1473s] self = [ 1473s] [ 1473s] @unittest.skipIf(not haveNumpy, "Numpy required for this test") [ 1473s] def test_dcDrawRectangleArray(self): [ 1473s] pnl = wx.Panel(self.frame) [ 1473s] self.frame.SetSize((w,h)) [ 1473s] dc = wx.ClientDC(pnl) [ 1473s] dc.SetPen(wx.Pen("BLACK", 1)) [ 1473s] dc.SetBrush( wx.Brush("RED") ) [ 1473s] [ 1473s] pens = makeRandomPens() [ 1473s] brushes = makeRandomBrushes() [ 1473s] [ 1473s] > dc.DrawRectangleList(np.array(makeRandomRectangles())) [ 1473s] [ 1473s] unittests/test_dcDrawLists.py:214: [ 1473s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ [ 1473s] unittests/test_dcDrawLists.py:66: in makeRandomRectangles [ 1473s] W = random.randint(10, w/2) [ 1473s] /usr/lib64/python3.12/random.py:336: in randint [ 1473s] return self.randrange(a, b+1) [ 1473s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ [ 1473s] [ 1473s] self = , start = 10, stop = 301.0 [ 1473s] step = 1 [ 1473s] [ 1473s] def randrange(self, start, stop=None, step=_ONE): [ 1473s] """Choose a random item from range(stop) or range(start, stop[, step]). [ 1473s] [ 1473s] Roughly equivalent to ``choice(range(start, stop, step))`` but [ 1473s] supports arbitrarily large ranges and is optimized for common cases. [ 1473s] [ 1473s] """ [ 1473s] [ 1473s] # This code is a bit messy to make it fast for the [ 1473s] # common case while still doing adequate error checking. [ 1473s] istart = _index(start) [ 1473s] if stop is None: [ 1473s] # We don't check for "step != 1" because it hasn't been [ 1473s] # type checked and converted to an integer yet. [ 1473s] if step is not _ONE: [ 1473s] raise TypeError("Missing a non-None stop argument") [ 1473s] if istart > 0: [ 1473s] return self._randbelow(istart) [ 1473s] raise ValueError("empty range for randrange()") [ 1473s] [ 1473s] # Stop argument supplied. [ 1473s] > istop = _index(stop) [ 1473s] E TypeError: 'float' object cannot be interpreted as an integer [ 1473s] [ 1473s] /usr/lib64/python3.12/random.py:312: TypeError [ 1473s] _________________ dcDrawLists_Tests.test_dcDrawRectangleLists __________________ [ 1473s] [gw2] linux -- Python 3.12.1 /usr/bin/python3.12 [ 1473s] self = [ 1473s] [ 1473s] def test_dcDrawRectangleLists(self): [ 1473s] pnl = wx.Panel(self.frame) [ 1473s] self.frame.SetSize((w,h)) [ 1473s] dc = wx.ClientDC(pnl) [ 1473s] dc.SetPen(wx.Pen("BLACK", 1)) [ 1473s] dc.SetBrush( wx.Brush("RED") ) [ 1473s] [ 1473s] pens = makeRandomPens() [ 1473s] brushes = makeRandomBrushes() [ 1473s] [ 1473s] > dc.DrawRectangleList(makeRandomRectangles()) [ 1473s] [ 1473s] unittests/test_dcDrawLists.py:195: [ 1473s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ [ 1473s] unittests/test_dcDrawLists.py:66: in makeRandomRectangles [ 1473s] W = random.randint(10, w/2) [ 1473s] /usr/lib64/python3.12/random.py:336: in randint [ 1473s] return self.randrange(a, b+1) [ 1473s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ [ 1473s] [ 1473s] self = , start = 10, stop = 301.0 [ 1473s] step = 1 [ 1473s] [ 1473s] def randrange(self, start, stop=None, step=_ONE): [ 1473s] """Choose a random item from range(stop) or range(start, stop[, step]). [ 1473s] [ 1473s] Roughly equivalent to ``choice(range(start, stop, step))`` but [ 1473s] supports arbitrarily large ranges and is optimized for common cases. [ 1473s] [ 1473s] """ [ 1473s] [ 1473s] # This code is a bit messy to make it fast for the [ 1473s] # common case while still doing adequate error checking. [ 1473s] istart = _index(start) [ 1473s] if stop is None: [ 1473s] # We don't check for "step != 1" because it hasn't been [ 1473s] # type checked and converted to an integer yet. [ 1473s] if step is not _ONE: [ 1473s] raise TypeError("Missing a non-None stop argument") [ 1473s] if istart > 0: [ 1473s] return self._randbelow(istart) [ 1473s] raise ValueError("empty range for randrange()") [ 1473s] [ 1473s] # Stop argument supplied. [ 1473s] > istop = _index(stop) [ 1473s] E TypeError: 'float' object cannot be interpreted as an integer [ 1473s] [ 1473s] /usr/lib64/python3.12/random.py:312: TypeError [ 1473s] =============================== warnings summary =============================== ```
bnavigator commented 4 months ago

https://docs.python.org/3.12/library/random.html#random.randrange:

Changed in version 3.12: Automatic conversion of non-integer types is no longer supported. Calls such as randrange(10.0) and randrange(Fraction(10, 1)) now raise a TypeError.