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-121249: adjust formatting codes for complex types in struct/ctypes modules by skirpichev · Pull Request #132827 · python/cpython

Conversation

@skirpichev

@skirpichev skirpichev commented Apr 23, 2025 •
edited by github-actions Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

For compatibility with numpy:

  • 'F' - for float _Complex
  • 'D' - for double _Complex
  • 'G' - for long double _Complex (not supported by the struct module)
  • Issue: Add support for C99 complex type (_Complex) to the struct module #121249

📚 Documentation preview 📚: https://cpython-previews--132827.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

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

All reactions
@skirpichev
pythongh-121249: adjust formatting codes for complex types in struct/…
e5bd3dc
…ctypes modules

F - for float _Complex
D - for double _Complex
G - for long double _Complex (not supported by the struct module)
@bedevere-app bedevere-app Bot added the awaiting review label Apr 23, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Apr 23, 2025
Add support for C99 complex type (_Complex) to the struct module #121249
Closed
@skirpichev skirpichev added the skip news label Apr 23, 2025
dalcinl
dalcinl reviewed Apr 23, 2025
View reviewed changes
Comment thread Lib/test/test_ctypes/test_c_simple_type_meta.py Resolved

Uh oh!

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

dalcinl
dalcinl reviewed Apr 23, 2025
View reviewed changes
Comment thread Lib/ctypes/__init__.py
_type_ = "C"
_type_ = "D"
_check_size(c_double_complex)
class c_float_complex(_SimpleCData):

@dalcinl dalcinl Apr 23, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should define c_float_complex first, just like c_float is defined before c_double above?

Sorry, something went wrong.

Uh oh!

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

All reactions
dalcinl
dalcinl reviewed Apr 23, 2025
View reviewed changes
Comment thread Modules/_ctypes/callproc.c
Comment on lines +656 to +657
double complex D;
float complex F;

@dalcinl dalcinl Apr 23, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe change order?

Suggested change
double complex D;
float complex F;
float complex F;
double complex D;

Sorry, something went wrong.

Uh oh!

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

All reactions
@dalcinl

dalcinl commented Apr 23, 2025

Copy link
Copy Markdown
Contributor

@skirpichev At the expense of a larger diff, maybe you should review defining/declaring things related to float complex BEFORE things related to double complex. Right now there is a mixture of orders, and that may make things confusing or error-prone with future maintenance tasks.

All reactions

Sorry, something went wrong.

Uh oh!

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

@skirpichev

skirpichev commented Apr 23, 2025

Copy link
Copy Markdown
Member Author

maybe you should review defining/declaring things related to float complex BEFORE things related to double complex.

I'm not sure this worth.

Right now there is a mixture of orders

And fixing that for complex types will not change this state.

All reactions

Sorry, something went wrong.

Uh oh!

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

vstinner
vstinner approved these changes Apr 23, 2025
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sorry, something went wrong.

Uh oh!

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

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Apr 23, 2025
skirpichev
skirpichev commented Apr 23, 2025
View reviewed changes
Comment thread Modules/_ctypes/callproc.c
long l;
long long q;
long double D;
long double g;

@skirpichev skirpichev Apr 23, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vstinner, this is something I worry about here.

IIUIC, this is a private interface and we can rename it's members. It seems this is not used across the codebase, but I appreciate a second look. (No tests seems to be affected, though maybe it's just lack of test coverage.)

Sorry, something went wrong.

Uh oh!

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

All reactions

@vstinner vstinner Apr 23, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this is not used across the codebase,

I confirm, the long double member is simply not used. I would suggest to remove it (but in a separated PR).

Sorry, something went wrong.

Uh oh!

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

All reactions

@skirpichev skirpichev Apr 23, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to remove it

I'm not sure. It seems, naming of union members aren't used - only size is important.

As long as we keep one-letter codes, I think it's good to have corresponding members in this struct.

Same holds for struct tagPyCArgObject - I forgot to update that. I'll make a patch. BTW do we need different (wrt union result) unnamed union here? I doubt.

Sorry, something went wrong.

Uh oh!

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

All reactions
@vstinner
vstinner merged commit 85f89cb into python:main Apr 23, 2025
@bedevere-app bedevere-app Bot removed the awaiting merge label Apr 23, 2025
@vstinner

vstinner commented Apr 23, 2025

Copy link
Copy Markdown
Member

Merged, thank you.

All reactions

Sorry, something went wrong.

Uh oh!

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

@skirpichev
skirpichev deleted the rename-struct-types/121249 branch April 23, 2025 14:16
@skirpichev skirpichev mentioned this pull request May 1, 2025
gh-61103: don't use native complex types in ctypes #133237
Merged
@vstinner vstinner mentioned this pull request Apr 17, 2026
Add support for numpy buffer format Zf and Zd #148675
Closed
@vstinner vstinner mentioned this pull request Jun 3, 2026
Deprecated F and D format in the struct module in Python 3.16 (use Zf and Zd instead) python/steering-council#352
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner approved these changes
+1 more reviewer
@dalcinl dalcinl dalcinl left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

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

Assignees

No one assigned

Labels

skip news

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 @dalcinl @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 01402520 — 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.