GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-61103: use PEP 3118 codes in the ctypes by skirpichev · Pull Request #149344 · python/cpython

Conversation

@skirpichev

@skirpichev skirpichev commented May 4, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This change only buffer protocol support for complex types, _type_ properties aren't affected.

  • Issue: Add support for C99 complex type (_Complex) as ctypes.c_complex #61103

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@skirpichev
pythongh-61103: use PEP 3118 codes in the ctypes
92b6cbb
This change only buffer protocol support for complex types,
`_type_` properties aren't affected.
@bedevere-app bedevere-app Bot added the awaiting review label May 4, 2026
@bedevere-app bedevere-app Bot mentioned this pull request May 4, 2026
Add support for C99 complex type (_Complex) as ctypes.c_complex #61103
Closed
@skirpichev
+correct
9528d51
This was referenced May 4, 2026
Decide buffer protocol format string for complex numbers python/steering-council#345
Closed
gh-121249: remove F/D type codes from table in the struct module #149346
Merged
@skirpichev
skirpichev requested review from encukou, hugovk and vstinner May 4, 2026 10:44
@skirpichev

skirpichev commented May 4, 2026

Copy link
Copy Markdown
Member Author

@encukou, I think this should fix compatibility with NumPy (buffer protocol). We can decide later what to do with _type_ (use same code or not).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@encukou

encukou commented May 4, 2026

Copy link
Copy Markdown
Member

I'm worried that this is a breaking change relative to Python 3.14.
It should definitely be mentioned in What's New if it gets in.

But, with #148676 this would be redundant.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@skirpichev
add news
7aa47c3
@skirpichev
skirpichev requested a review from AA-Turner as a code owner May 4, 2026 13:02
@read-the-docs-community

read-the-docs-community Bot commented May 4, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #32526288 | 📁 Comparing 7aa47c3 against main (2ba0a81)

  🔍 Preview build  

10 files changed · ± 10 modified

± Modified

  • deprecations/index.html
  • deprecations/pending-removal-in-3.19.html
  • library/calendar.html
  • library/http.cookies.html
  • whatsnew/3.12.html
  • whatsnew/3.13.html
  • whatsnew/3.14.html
  • whatsnew/3.15.html
  • whatsnew/changelog.html
  • whatsnew/index.html
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@skirpichev

skirpichev commented May 4, 2026

Copy link
Copy Markdown
Member Author

It should definitely be mentioned in What's New if it gets in.

Done.

But, with #148676 this would be redundant.

(I think merging that pr is a bad idea.)

Though, you are right, my 3 PRs - only an alternative.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@skirpichev skirpichev closed this May 4, 2026
@skirpichev
skirpichev deleted the fix-ctypes-buffer branch May 4, 2026 15:09
@vstinner

vstinner commented May 4, 2026

Copy link
Copy Markdown
Member

I merged my PR instead which changes ctypes _type_. This change would be an alternative if we decide later to leave _type_ unchanged and only change the used buffer format.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@skirpichev

skirpichev commented May 5, 2026

Copy link
Copy Markdown
Member Author

@vstinner, you already closed this door by #149368.

Anyway, that's a kind of direction I would like to support, instead of #148676. No multiple type codes. I only worry, that in this way you also introduce incompatibility with the NumPy.

That's why reversion of my changes in 3.15 and struct (deprecation) looks better for me. Lets wait decision on a PEP. Then extend the struct module in The Right Way. Then adapt other stuff. This PR does make sense only on this kind of road.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented May 5, 2026

Copy link
Copy Markdown
Member

I only worry, that in this way you also introduce incompatibility with the NumPy.
That's why reversion of my changes in 3.15 and struct (deprecation) looks better for me.

Converting an array.array to numpy.array just works:

$ python3.15 
>>> import array, numpy as np
>>> a=array.array('Zd', [0])
>>> a.typecode
'Zd'
>>> n=np.array(a)
>>> n.dtype
dtype('complex128')

Converting a memoryview to numpy.array also works:

$ python3.15 
>>> import struct, numpy as np
>>> data = struct.pack('Zd', 1j)
>>> m = memoryview(data).cast('Zd')
>>> n=np.array(m)
>>> n.dtype
dtype('complex128')
>>> n
array([0.+1.j])

I suggest continuing this discussion at https://discuss.python.org/t/choice-of-complex-buffer-protocol-format-intentional-break-with-pep/106949.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

@encukou encukou Awaiting requested review from encukou
@vstinner vstinner Awaiting requested review from vstinner
@hugovk hugovk Awaiting requested review from hugovk
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@skirpichev @encukou @vstinner
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.