Skip to content

q can't write big strings in Python 3.12: "TypeError: 'float' object cannot be interpreted as an integer" #71

@alexwlchan

Description

@alexwlchan

File to reproduce:

# example.py
import q
x = 'a' * 81
q.q(x)

Steps to reproduce:

$ python3.12 -m venv .venv
$ source .venv/bin/activate
$ pip install q
Collecting q
  Using cached q-2.7-py2.py3-none-any.whl.metadata (811 bytes)
Using cached q-2.7-py2.py3-none-any.whl (10 kB)
Installing collected packages: q
Successfully installed q-2.7

$ python3.12 example.py
Traceback (most recent call last):
  File "/private/var/folders/lp/1yl_g9ls2_g3l2tkmb6fpg0h0000gn/T/tmp.Jf4R2cEjpE/example.py", line 3, in <module>
    q.q(x)
  File "/private/var/folders/lp/1yl_g9ls2_g3l2tkmb6fpg0h0000gn/T/tmp.Jf4R2cEjpE/.venv/lib/python3.12/site-packages/q.py", line 357, in __call__
    self.show(info.function, args, labels)
  File "/private/var/folders/lp/1yl_g9ls2_g3l2tkmb6fpg0h0000gn/T/tmp.Jf4R2cEjpE/.venv/lib/python3.12/site-packages/q.py", line 272, in show
    for label, repr in zip(labels, reprs):
  File "/private/var/folders/lp/1yl_g9ls2_g3l2tkmb6fpg0h0000gn/T/tmp.Jf4R2cEjpE/.venv/lib/python3.12/site-packages/q.py", line 229, in safe_repr
    path = self.OUTPUT_PATH + '%08d.txt' % self.random.randrange(1e8)
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/random.py", line 301, in randrange
    istart = _index(start)
             ^^^^^^^^^^^^^
TypeError: 'float' object cannot be interpreted as an integer

This is because randrange changed in Python 3.12, and it no longer converts non-integers to integers automatically.

This was fixed in q over a year ago (b8b7a7e) but the fix was never released to PyPI.

Could we get a release with the fix please?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions