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-47146: Soft-deprecate structmember.h, expose its contents via Python.h by encukou · Pull Request #99014 · python/cpython

Conversation

@encukou

@encukou encukou commented Nov 2, 2022 •
edited by bedevere-bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

The structmember.h header is deprecated, though it continues to be available and there are no plans to remove it. There are no deprecation warnings. Old code can stay unchanged (unless the extra include and non-namespaced macros bother you greatly). Specifically, no uses in CPython are updated -- that would just be unnecessary churn.

The header's contents are now available just by including Python.h, with a PY_ prefix added if it was missing:

  • PyMemberDef, PyMember_GetOne, PyMember_SetOne
  • Type macros like PY_T_INT, PY_T_DOUBLE, etc. (previously T_INT, T_DOUBLE, etc.)
  • The flags PY_READONLY (previously READONLY) and PY_AUDIT_READ (name unchanged)

Several items are not exposed from Python.h:

  • T_OBJECT (use PY_T_OBJECT_EX)
  • T_NONE (previously undocumented, and pretty quirky)
  • The macro WRITE_RESTRICTED which does nothing.
  • The macros RESTRICTED and READ_RESTRICTED, equivalents of PY_AUDIT_READ.
  • In some configurations, <stddef.h> is not included from Python.h.
    It should be included manually when using offsetof().

The PY_T_*, PY_READONLY and PY_AUDIT_READ macros are added to the stable API manifest. This is just a clerical change, really -- Stable ABI extensions in the wild use structmember.h, and PyMemberDef & Py_tp_members are already listed.

There is discussion on the issue to rename T_PYSSIZET to PY_T_SSIZE or similar. I chose not to do that -- users will probably copy/paste that with any spelling, and not renaming it makes migration docs simpler.

Co-Authored-By: Alexander Belopolsky [email protected]
Co-Authored-By: Matthias Braun [email protected]

  • Issue: PyMemberDef missing in limited API / Deprecate structmember.h #47146

Sorry, something went wrong.

Uh oh!

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

All reactions
encukou added 4 commits November 2, 2022 17:15
@encukou
Move structmember.h definitions to descrobject.h, adding PY_ prefixes
33e614a
Old names are kept as aliases.
@encukou
Add to limited API
388c6ef
@encukou
All the docs
498365d
These docs were ripe for an overhaul, so I did one when touching the code.
@encukou
NEWS & What's New
714bd57
@bedevere-bot bedevere-bot mentioned this pull request Nov 2, 2022
PyMemberDef missing in limited API / Deprecate structmember.h #47146
Closed
@bedevere-bot bedevere-bot added the awaiting core review label Nov 2, 2022
@encukou encukou mentioned this pull request Nov 2, 2022
bpo-2897: Make PyMemberDef part of stable ABI; deprecate structmember.h #20462
Closed
@encukou
Fix ReST syntax
9927fa2
@encukou

encukou commented Nov 7, 2022

Copy link
Copy Markdown
Member Author

Today I noticed the style guide says macros should have the Py_ prefix, not PY_. A minor point, but since this is renaming a bunch of macros, I'll switch to the preferred form.

All reactions

Sorry, something went wrong.

Uh oh!

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

@encukou
encukou marked this pull request as draft November 7, 2022 12:45
@encukou
Change the prefix to Py_, per PEP 7
26246d8
@encukou
encukou marked this pull request as ready for review November 8, 2022 14:10
@encukou
Add back PY_AUDIT_READ
01b61a2
@encukou
encukou marked this pull request as draft November 8, 2022 16:33
@encukou

encukou commented Nov 8, 2022

Copy link
Copy Markdown
Member Author

The PY_T_*, PY_READONLY and PY_AUDIT_READ macros are added to the stable API manifest. This is just a clerical change, really -- Stable ABI extensions in the wild use structmember.h, and PyMemberDef & Py_tp_members are already listed.

And by the same token, PyMember_GetOne and PyMember_SetOne should be added too.

erlend-aasland reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@encukou
Expose PyMember_?etOne in Limited API (again?)
f3e9765
@encukou
encukou marked this pull request as ready for review November 10, 2022 13:19
encukou added 4 commits November 15, 2022 13:56
@encukou
Fix footnotes in docs
e6b626d
@encukou
Merge main branch
3cb05e9
@encukou
Use the right prefix in stable_abi.toml
779d14e
@encukou
Move tests to _testcapi/, add tests for the new API
e44b7ca
@encukou
encukou requested a review from a team as a code owner November 15, 2022 14:17
@encukou

encukou commented Nov 16, 2022

Copy link
Copy Markdown
Member Author

And here are tests.
I'd appreciate a review, if anyone can spare the time.

All reactions

Sorry, something went wrong.

Uh oh!

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

@encukou encukou added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 16, 2022
@bedevere-bot

bedevere-bot commented Nov 16, 2022

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @encukou for commit e44b7ca 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 16, 2022
erlend-aasland
erlend-aasland approved these changes Nov 16, 2022
View reviewed changes

@erlend-aasland erlend-aasland left a comment

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.

Looks good. I did some nitpicking.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/c-api/structures.rst Resolved

Uh oh!

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

Comment thread Doc/c-api/structures.rst Resolved

Uh oh!

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

Comment thread Doc/c-api/structures.rst Resolved

Uh oh!

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

Comment thread Modules/_testcapi/structmember.c Resolved

Uh oh!

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

Comment thread Modules/_testcapi/structmember.c Resolved

Uh oh!

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

Comment thread Modules/_testcapi/structmember.c Resolved

Uh oh!

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

Comment thread Modules/_testcapi/structmember.c Resolved

Uh oh!

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

Comment thread Modules/_testcapi/structmember.c Resolved

Uh oh!

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

@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Nov 16, 2022
@encukou
Address review comments
8f7609e
@encukou
Merge in the main branch
88aa9a1
@encukou

encukou commented Nov 21, 2022

Copy link
Copy Markdown
Member Author

Thank you! I did the changes, and will merge once everything is green.

erlend-aasland reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@encukou
encukou merged commit 4d82f62 into python:main Nov 22, 2022
@bedevere-bot bedevere-bot removed the awaiting merge label Nov 22, 2022
@encukou
encukou deleted the structmember-public branch November 22, 2022 07:25
@vstinner

vstinner commented Nov 22, 2022

Copy link
Copy Markdown
Member

Nice work!

erlend-aasland reacted with thumbs up emoji erlend-aasland reacted with rocket emoji
All reactions
  • 👍 1 reaction
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

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

@encukou encukou mentioned this pull request Dec 6, 2022
gh-97908: CAPI docs: Remove repeated struct names from member docs #100054
Merged
@iritkatriel iritkatriel mentioned this pull request Feb 18, 2023
Remove documentation and internal use of the *RESTRICTED constants for PyMemberDef's flags field #80536
Closed
serhiy-storchaka
serhiy-storchaka reviewed Jul 18, 2023
View reviewed changes
Comment thread Modules/_testcapi/structmember.c Resolved

Uh oh!

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

@serhiy-storchaka

serhiy-storchaka commented Jul 25, 2023

Copy link
Copy Markdown
Member

Isn't it strange that the only public constant for object has an _EX suffix? Why not rename Py_T_OBJECT_EX to Py_T_OBJECT?

erlend-aasland reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Jul 25, 2023

Copy link
Copy Markdown
Member

I agree that _Py_T_OBJECT is surprising: returning None if an attribute doesn't exist, so it's not possible to know if the attribute value is None or if the attribute doesn't exist.

Py_T_OBJECT_EX behavior of raising an AttributeError if the attribute value is NULL doesn't better. I agree with @serhiy-storchaka, it should just be Py_T_OBJECT.

By the way, how was _Py_T_NONE used in the past? It's documented as:

Deprecated. Value is always None.

All reactions

Sorry, something went wrong.

Uh oh!

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

@serhiy-storchaka

serhiy-storchaka commented Jul 25, 2023

Copy link
Copy Markdown
Member

Both _Py_T_OBJECT and Py_T_OBJECT_EX correspond to behavior of attributes of instances of Python classes. Just the latter is the default behavior, and the former is for the case when an instance attribute shadows the class attribute set to None. See an example in #107253.

T_NONE was introduced in 50e9fb9. I have not found a single case of its use.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Jul 25, 2023

Copy link
Copy Markdown
Member

T_NONE was introduced in 50e9fb9. I have not found a single case of its use.

Maybe it's not worth it to add _Py_NONE in this case. I don't know.

All reactions

Sorry, something went wrong.

Uh oh!

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

@encukou

encukou commented Aug 2, 2023

Copy link
Copy Markdown
Member Author

Isn't it strange that the only public constant for object has an _EX suffix? Why not rename Py_T_OBJECT_EX to Py_T_OBJECT?

T_OBJECT is still public API, it's just discouraged. (Probably not properly “soft-deprecated” in the new sense though?)
Since all the others add Py_, I thought it would be confusing to also drop the suffix in this case.

All reactions

Sorry, something went wrong.

Uh oh!

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

@XuehaiPan XuehaiPan mentioned this pull request Oct 2, 2023
deps(python): enable Python 3.12 support metaopt/optree#90
Merged
8 of 12 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Aug 1, 2026
builtins: exception, iterator and function attribute surface parity pyre-lang/pyre#950
Merged
@coderabbitai coderabbitai Bot mentioned this pull request Aug 23, 2026
cpyext: type mirrors, types built from C, and slots bound to the type that owns the method pyre-lang/pyre#1429
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@serhiy-storchaka serhiy-storchaka serhiy-storchaka left review comments
@erlend-aasland erlend-aasland erlend-aasland approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

None yet

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.

5 participants

@encukou @bedevere-bot @vstinner @serhiy-storchaka @erlend-aasland
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.