Skip to content

vizonex capi -- draft - #1191

Closed
asvetlov wants to merge 45 commits into
aio-libs:masterfrom
asvetlov:vizonex-capi
Closed

asvetlov wants to merge 45 commits into
aio-libs:masterfrom
asvetlov:vizonex-capi

Conversation

@asvetlov

@asvetlov asvetlov commented Jun 22, 2025 •

Copy link
Copy Markdown
Member

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

asvetlov and others added 30 commits June 19, 2025 23:56
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Jun 22, 2025
@asvetlov asvetlov mentioned this pull request Jun 22, 2025
@asvetlov

Copy link
Copy Markdown
Member Author

Superseded by #1480

@asvetlov asvetlov closed this Sep 22, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants