Skip to content

Use stdlib compression.zstd for Zstd decompression on Python 3.14+#932

Merged
Kludex merged 4 commits into
mainfrom
std-zstd
May 13, 2026
Merged

Use stdlib compression.zstd for Zstd decompression on Python 3.14+#932
Kludex merged 4 commits into
mainfrom
std-zstd

Conversation

@Kludex

@Kludex Kludex commented May 13, 2026

Copy link
Copy Markdown
Member

Work done with bad internet, and without any coding agent. It's very rewarding to just code.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d3ec059b89

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +49 to +50
except ImportError:
_zstandard_installed = False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Define zstandard in ImportError branch

When import zstandard fails on Python 3.13 and below, this branch only sets _zstandard_installed = False and leaves zstandard undefined. Later in the same module, the if zstandard is None: check runs unconditionally, so importing _decoders.py raises a NameError in environments that do not install the optional zstd extra. That turns an optional dependency into an import-time crash for all decoding paths, not just zstd.

Useful? React with 👍 / 👎.

Comment on lines +31 to +55
# Zstandard support is optional on Python <= 3.13.
# On Python 3.14, the stdlib includes a built-in zstd implementation, so we can support
# it without an extra dependency.
if typing.TYPE_CHECKING:
if sys.version_info >= (3, 14):
from compression.zstd import ZstdDecompressor, ZstdError
else:
from zstandard import ZstdDecompressor as _ZstdDecompressor, ZstdError

ZstdDecompressor = functools.partial(_ZstdDecompressor().decompressobj)

_zstandard_installed: bool = True
else: # pragma: no cover
if sys.version_info >= (3, 14):
from compression.zstd import ZstdDecompressor, ZstdError

_zstandard_installed = True
else:
try:
from zstandard import ZstdDecompressor as _ZstdDecompressor, ZstdError

ZstdDecompressor = functools.partial(_ZstdDecompressor().decompressobj)
_zstandard_installed = True
except ImportError:
_zstandard_installed = False

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's crazy that I need to do this.

@Kludex Kludex merged commit 6c19d2a into main May 13, 2026
11 checks passed
@Kludex Kludex deleted the std-zstd branch May 13, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant