Skip to content

[_cffi_backend] Improve CField, CType, _CDataBase, buffer - #15530

Open
mildsunrise wants to merge 4 commits into
python:mainfrom
mildsunrise:patch-1
Open

[_cffi_backend] Improve CField, CType, _CDataBase, buffer#15530
mildsunrise wants to merge 4 commits into
python:mainfrom
mildsunrise:patch-1

Conversation

@mildsunrise

Copy link
Copy Markdown

these were verified against implementation code. the docs are not very precise on some of these things, but I think it's clear all this is intended to be public facing API. CType in particular will be documented better as part of python-cffi/cffi#231.

draft because I still need to resolve the style issues (so far I can only see (1) replacing Optional with | None, and (2) importing Self from _typing_extensions).

I also need to see if Python/typeshed allows structural typing (because available CType fields vary depending on the value of kind)

mildsunrise and others added 4 commits March 20, 2026 06:35
the implementation really doesn't allow other objects being passed, and I see other stubs doing this, so I presume it's okay?
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau

srittau commented Mar 20, 2026

Copy link
Copy Markdown
Collaborator

LGTM, I'll merge this when you undraft.

@mildsunrise

Copy link
Copy Markdown
Author

@srittau the CType class exposes different sets of attributes depending on the kind. would it be acceptable to make it a union of protocols instead of a (nominal) class, like i'm doing here? the section on subtyping seems to say so, but this would break uses of isinstance(x, CType). however i feel like it would be more accurate / useful overall

@srittau

srittau commented Mar 30, 2026

Copy link
Copy Markdown
Collaborator

I suggest we merge this PR as is, as it's a clear improvement on the status quo. Then we can experiment with the protocol-based approach in a targeted PR. I'm especially interested in the primer output.

@mildsunrise
mildsunrise marked this pull request as ready for review March 30, 2026 13:37
@brianschubert

Copy link
Copy Markdown
Collaborator

This has conflicts now, @mildsunrise can you take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants