Skip to content

Make zstd import optional on Python 3.14#1000

Merged
Kludex merged 2 commits into
mainfrom
make-zstd-import-optional-on-3.14
Jun 1, 2026
Merged

Make zstd import optional on Python 3.14#1000
Kludex merged 2 commits into
mainfrom
make-zstd-import-optional-on-3.14

Conversation

@Kludex

@Kludex Kludex commented Jun 1, 2026

Copy link
Copy Markdown
Member

On Python 3.14, compression.zstd requires the _zstd C extension, which is not present in every CPython build. We imported it unconditionally, so import httpx2 crashed with ModuleNotFoundError: No module named '_zstd' on those builds.

This wraps the 3.14 import in try/except ImportError (mirroring the existing < 3.14 branch), so a missing _zstd sets _zstandard_installed = False and drops zstd from SUPPORTED_DECODERS instead of crashing.

Fixes the report in #999 (comment).

AI Disclaimer

This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.

On Python 3.14, `compression.zstd` requires the `_zstd` C extension,
which is not present in every CPython build. Importing it unconditionally
crashed `import httpx2` with `ModuleNotFoundError: No module named '_zstd'`.
Wrap the import in try/except so zstd support degrades gracefully.
@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown

@codspeed-hq

codspeed-hq Bot commented Jun 1, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 15 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing make-zstd-import-optional-on-3.14 (c184e9d) with main (999da32)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Kludex Kludex merged commit 0ba70ab into main Jun 1, 2026
14 checks passed
@Kludex Kludex deleted the make-zstd-import-optional-on-3.14 branch June 1, 2026 07:05
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