Repository navigation
Conversation
…ent compile collisions with other libraries
…tigate a little bit more deeply...
Closed
5 of 6 tasks
Member
Author
|
Superseded by #1480 |
asvetlov
added a commit
that referenced
this pull request
Sep 23, 2026
<!-- Thank you for your contribution! --> ## What do these changes do? Adds a public C API capsule (`multidict._multidict.CAPI`, reached through `multidict_capi.h` / `multidict_capi_struct.h`) so other C extensions can create and manipulate `MultiDict`, `CIMultiDict`, their proxies, and `istr` directly, without going through the Python-level API. Covers type checks and constructors for all four mapping types plus `istr`, `getversion()` and `len()`, and `add()`, `clear()`, `setdefault()`, and single-item access (`in`, `[]`, `del`, `pop()`) for the mutable types. `GetItem`, `Pop`, and `SetDefault` follow the `PyDict_GetItemRef` / `PyDict_SetDefaultRef` design, reporting a missing key through the return code rather than an exception. `MultiDict_ForEach` visits every item, or just the items for one key, through a callback, without allocating a list. The same capsule is also reachable from Cython: `multidict/__init__.pxd` lets third-party Cython code `cimport multidict`, mirrored by a `multidict/_testcyapi.pyx` test harness. Cython is optional and never a real dependency of `multidict` itself; an ordinary or release build never sees it, and a dedicated CI job exercises the opt-in path. ## Are there changes in behavior for the user? No behavior change for existing Python-level usage. This adds a new, opt-in C API surface for other C extensions and Cython code to use. ## Is it a substantial burden for the maintainers to support this? The struct only ever grows at the end, so older clients keep working against newer `multidict` builds. The Cython binding is test-only and opt-in, so it adds no ongoing dependency burden. ## Related issue number Supersedes and closes #1183, #1190, #1191 (earlier C API drafts). ## Checklist - [x] I think the code is well written - [x] Unit tests for the changes exist - [x] Documentation reflects the changes - [ ] If you provide code modification, please add yourself to `CONTRIBUTORS.txt` - [x] Add a new news fragment into the `CHANGES/` folder - [x] `make doc-spelling` passes and any new technical words are added to `docs/spelling_wordlist.txt` <details> <summary>Agent run details (optional, for reviewers)</summary> Tests: `pytest -q` on both the accelerated build (with and without the Cython opt-in) and the pure-Python build (`MULTIDICT_NO_EXTENSIONS=1`); `tests/test_capi.py`'s `api` fixture runs every case against both the C and Cython bindings when Cython is opted in. Lint: `pre-commit run --all-files` (ruff, mypy for 3.13/3.11, yamllint, clang-format, GitHub Actions validators) clean. Docs: strict Sphinx HTML build and `doc-spelling` clean. Drafted with Claude Code (Sonnet 5); reviewed by asvetlov. </details> --------- Co-authored-by: Claude Sonnet 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resurrected version of @Vizonex work
I saved it locally just in case, and I'll delete it when the CAPI work will land on the master