This rule raises an issue when code imports from legacy compression modules (lzma, bz2, gzip, zlib) instead of using the new compression namespace imports in Python 3.14+.

Why is this an issue?

Starting with Python 3.14, PEP 784 introduces a new compression namespace that provides canonical import names for compression modules. The new imports like compression.lzma, compression.bz2, compression.gzip, and compression.zlib are now the preferred way to import these modules.

Using the legacy top-level module names is still supported for backwards compatibility, but the new namespace imports offer several advantages:

While the legacy imports continue to work, adopting the new canonical names helps keep your code aligned with Python’s current best practices and prepares it for future developments in the standard library.

What is the potential impact?

Using legacy compression imports does not cause functional issues, but it means your code is not following the current Python standards. This can make the codebase appear outdated and may require updates in the future if the legacy imports are eventually deprecated.

How to fix?

Replace legacy compression module imports with the new compression namespace imports. Update all import statements to use the canonical names introduced in Python 3.14.

Non-compliant code example

from lzma import LZMAFile
from bz2 import BZ2File
from gzip import GzipFile
from zlib import compress

Compliant code example

from compression.lzma import LZMAFile
from compression.bz2 import BZ2File
from compression.gzip import GzipFile
from compression.zlib import compress

Documentation