python-lz4 icon indicating copy to clipboard operation
python-lz4 copied to clipboard

ImportError when attempting to test with Python 3.14

Open befeleme opened this issue 6 months ago • 3 comments

Trying to run the tests with Python 3.14, I run into ImportError. This is new, doesn't happen with Python 3.13. I test with Python 3.14, because I prepare an update of the main Python in Fedora Linux 43 and try to rebuild all Python packages as such.

$ tox -e py314
py314: commands[0]> pytest --cov=lz4/block --cov=lz4/frame --tb=long tests/block tests/frame
ImportError while loading conftest '/home/ksurma/dev/python-lz4/tests/frame/conftest.py'.
tests/frame/conftest.py:2: in <module>
    import lz4.frame as lz4frame
lz4/frame/__init__.py:30: in <module>
    from . import _compression
E   ImportError: cannot import name '_compression' from partially initialized module 'lz4.frame' (most likely due to a circular import) (/home/ksurma/dev/python-lz4/lz4/frame/__init__.py)

Or just on an installed project in Python 3.14 venv:

$ python                      
>>> import lz4.frame as lz4frame
Traceback (most recent call last):
  File "/home/ksurma/dev/python-lz4/lz4/frame/__init__.py", line 28, in <module>
    import _compression   # Python 3.6 and later
    ^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named '_compression'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    import lz4.frame as lz4frame
  File "/home/ksurma/dev/python-lz4/lz4/frame/__init__.py", line 30, in <module>
    from . import _compression
ImportError: cannot import name '_compression' from partially initialized module 'lz4.frame' (most likely due to a circular import) (/home/ksurma/dev/python-lz4/lz4/frame/__init__.py)

befeleme avatar May 29 '25 07:05 befeleme

From https://peps.python.org/pep-0784/

The _compression module, given that it is marked private, will be immediately renamed to compression._common._streams.

Here:

https://github.com/python-lz4/python-lz4/blob/022d53815abf97e6eb49d0be3a27c74541c782ec/lz4/frame/init.py#L27-L30

It goes to the second import (which is likely broken, as it was not used since Python 3.5?).

hroncok avatar May 29 '25 09:05 hroncok

import compression._common._streams as _compression

should do on Python 3.14+

hroncok avatar May 29 '25 09:05 hroncok

Considering https://github.com/python-lz4/python-lz4/blob/022d53815abf97e6eb49d0be3a27c74541c782ec/setup.py#L174

The from . import _compression fallback is likely not needed.

hroncok avatar May 29 '25 10:05 hroncok

% uvx --with=lz4 python3.14t -c"import lz4"

<frozen importlib._bootstrap>:491: RuntimeWarning: The global interpreter lock (GIL) has been enabled
    to load module 'lz4._version', which has not declared that it can run safely without the GIL.
    To override this behavior and keep the GIL disabled (at your own risk), run with PYTHON_GIL=0
    or -Xgil=0.

Reviews please on the solution proposed in:

  • #303

cclauss avatar Sep 24 '25 11:09 cclauss

Python 3.14 (the π version) was released today. https://www.python.org/downloads/release/python-3140/ https://github.com/actions/python-versions/releases

cclauss avatar Oct 07 '25 15:10 cclauss

@corona10 This is green ✅ at the bottom of https://ft-checker.com/?search=lz4 but is not really usable on Py4.13.

cclauss avatar Oct 12 '25 13:10 cclauss