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-95245: Document Py_TPFLAGS_PREHEADER by sergey-miryanov · Pull Request #135861 · python/cpython

Conversation

@sergey-miryanov

@sergey-miryanov sergey-miryanov commented Jun 23, 2025 •
edited by encukou
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

I see following usages of Py_TPFLAGS_PREHEADER:

  1. Calculate size of preheader (but preheader also contains GC info)
  2. Check if types are support managed dict or managed weakref

I checked all linked PR from #95245 and can't find any explanation. I also checked https://github.com/python/cpython/blob/main/Objects/object_layout.md.

@encukou Please take a look.

  • Issue: Reduce the size of plain Python objects from 8 to 6 machine words. #95245

Sorry, something went wrong.

Uh oh!

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

All reactions
@sergey-miryanov
Add comemnt for Py_TPFLAGS_PREHEADER
0eb59b3
@bedevere-app bedevere-app Bot added the awaiting review label Jun 23, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Jun 23, 2025
Undocumented 3.14 C API #135755
Closed
39 tasks done
ZeroIntensity
ZeroIntensity reviewed Jun 23, 2025
View reviewed changes

@ZeroIntensity ZeroIntensity 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.

We should include documentation on the type object page too.

Sorry, something went wrong.

Uh oh!

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

encukou and sergey-miryanov reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
@encukou encukou changed the title gh-135755: Document Py_TPFLAGS_PREHEADER gh-95245: Document Py_TPFLAGS_PREHEADER Jun 24, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Jun 24, 2025
Reduce the size of plain Python objects from 8 to 6 machine words. #95245
Closed
sergey-miryanov added 2 commits June 24, 2025 13:06
@sergey-miryanov
Add Py_TPFLAGS_PREHEADER to typeobj.rst
3195c33
@sergey-miryanov
Add news
6b37dcf
@sergey-miryanov

sergey-miryanov commented Jun 24, 2025

Copy link
Copy Markdown
Contributor Author

@ZeroIntensity Thanks for review! Fixed (I hope :)

All reactions

Sorry, something went wrong.

Uh oh!

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

@sergey-miryanov
Fix news entry
fc7fb85
ZeroIntensity
ZeroIntensity reviewed Jun 24, 2025
View reviewed changes

@ZeroIntensity ZeroIntensity 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.

I think that if this is internal-only, it would be better to completely drop it from public headers rather than document it as such.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Misc/NEWS.d/next/Core_and_Builtins/2025-06-24-13-08-15.gh-issue-95245.3whjTE.rst Resolved

Uh oh!

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

@ZeroIntensity ZeroIntensity added skip news docs Documentation in the Doc dir labels Jun 24, 2025
@github-project-automation github-project-automation Bot added this to Docs PRs Jun 24, 2025
@github-project-automation github-project-automation Bot moved this to Todo in Docs PRs Jun 24, 2025
@ZeroIntensity

ZeroIntensity commented Jun 24, 2025

Copy link
Copy Markdown
Member

I think that if this is internal-only, it would be better to completely drop it from public headers rather than document it as such.

(Don't do this yet, by the way. Let's come to a consensus in the issue.)

sergey-miryanov 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.

@sergey-miryanov

sergey-miryanov commented Jul 5, 2025

Copy link
Copy Markdown
Contributor Author

As no comments from @iritkatriel or @markshannon I propose to make it internal as @ZeroIntensity suggested and rename it to _Py_TPFLAGS_PREHEADER.

@encukou WDYT?

All reactions

Sorry, something went wrong.

Uh oh!

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

@encukou

encukou commented Jul 7, 2025

Copy link
Copy Markdown
Member

Per PEP-387, removing (or renaming) it probablyneeds a deprecation cycle. Or is there evidence that no existing code uses it?

All reactions

Sorry, something went wrong.

Uh oh!

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

@markshannon

markshannon commented Jul 7, 2025

Copy link
Copy Markdown
Member

Since the tp_flags flags must be public, it seemed sensible to put Py_TPFLAGS_PREHEADER in the same header.
I have no objection to moving it.

It might be better to rename it to Py_TPFLAGS_VM_MANAGED_FIELDS to focus on the semantics, not the layout, and keep it public?

All reactions

Sorry, something went wrong.

Uh oh!

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

@sergey-miryanov

sergey-miryanov commented Jul 7, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Per PEP-387, removing (or renaming) it probablyneeds a deprecation cycle. Or is there evidence that no existing code uses it?

https://grep.app/search?q=Py_TPFLAGS_PREHEADER shows close to nothing of usage. Also, I'm downloading top-pypi packages to checks usage (as described here https://hugovk.dev/blog/2022/how-to-search-5000-python-projects/), will report as it finished.

All reactions

Sorry, something went wrong.

Uh oh!

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

@sergey-miryanov

sergey-miryanov commented Jul 7, 2025

Copy link
Copy Markdown
Contributor Author

It might be better to rename it to Py_TPFLAGS_VM_MANAGED_FIELDS to focus on the semantics, not the layout, and keep it public?

@markshannon WDYT about wordings in this PR? Can you suggest some improvements?

All reactions

Sorry, something went wrong.

Uh oh!

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

@sergey-miryanov

sergey-miryanov commented Jul 7, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

will report as it finished.

Searched over 13k+ packages:

➜ .\python.exe ../misc/cpython/search_pypi_top.py -q ..\top-pypi\output\  "Py_TPFLAGS_PREHEADER"
..\top-pypi\output\recordclass-0.23.1.tar.gz: recordclass-0.23.1/lib/recordclass/_dataobject.c: tp->tp_flags &= ~Py_TPFLAGS_PREHEADER;

Time: 0:01:10.586519
Found 1 matching lines in 1 projects

➜ ( Get-ChildItem ..\top-pypi\output\ | Measure-Object ).Count;
13961
All reactions

Sorry, something went wrong.

Uh oh!

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

@encukou

encukou commented Jul 7, 2025

Copy link
Copy Markdown
Member

It might be better to rename it to Py_TPFLAGS_VM_MANAGED_FIELDS to focus on the semantics, not the layout, and keep it public?

If it's public, it's best not to rename it.

All reactions

Sorry, something went wrong.

Uh oh!

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

encukou
encukou reviewed Jul 7, 2025
View reviewed changes
Comment thread Doc/c-api/typeobj.rst Resolved

Uh oh!

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

sergey-miryanov and others added 2 commits July 7, 2025 16:58
@sergey-miryanov @encukou
Update Doc/c-api/typeobj.rst
2062b3d
Co-authored-by: Petr Viktorin <[email protected]>
@sergey-miryanov
Delete news entry
fd1f311
ZeroIntensity
ZeroIntensity reviewed Jul 7, 2025
View reviewed changes
Comment thread Doc/c-api/typeobj.rst Resolved

Uh oh!

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

@ZeroIntensity

ZeroIntensity commented Jul 7, 2025

Copy link
Copy Markdown
Member

If it's public, it's best not to rename it.

I think it's probably safe to rename it, at least for 3.14. Based on a code search, we're the only ones who use it (all the non-CPython mentions are people copying our headers).

All reactions

Sorry, something went wrong.

Uh oh!

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

@sergey-miryanov

sergey-miryanov commented Jul 7, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

If it's public, it's best not to rename it.

I think it's probably safe to rename it, at least for 3.14. Based on a code search, we're the only ones who use it (all the non-CPython mentions are people copying our headers).

Only recordclass uses it - #135861 (comment)

All reactions

Sorry, something went wrong.

Uh oh!

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

@ZeroIntensity ZeroIntensity added the topic-C-API label Aug 18, 2025
ZeroIntensity
ZeroIntensity reviewed Aug 18, 2025
View reviewed changes
Comment thread Doc/c-api/typeobj.rst Resolved

Uh oh!

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

sergey-miryanov and others added 2 commits August 22, 2025 22:59
@sergey-miryanov @ZeroIntensity
Update Doc/c-api/typeobj.rst
0c8436b
Co-authored-by: Peter Bierma <[email protected]>
@sergey-miryanov
Apply suggestions from review
e788241
@sergey-miryanov

sergey-miryanov commented Aug 22, 2025

Copy link
Copy Markdown
Contributor Author

@ZeroIntensity Please take a look.

All reactions

Sorry, something went wrong.

Uh oh!

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

ZeroIntensity
ZeroIntensity reviewed Aug 22, 2025
View reviewed changes

@ZeroIntensity ZeroIntensity 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.

Thanks, this mostly looks good.

Sorry, something went wrong.

Uh oh!

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

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

Uh oh!

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

sergey-miryanov and others added 2 commits August 22, 2025 23:08
@sergey-miryanov
Merge branch 'main' into pythongh-135755-document-preheader-flag
7595c18
@sergey-miryanov @ZeroIntensity
Update Doc/c-api/typeobj.rst
8134bc8
Co-authored-by: Peter Bierma <[email protected]>
ZeroIntensity
ZeroIntensity approved these changes Aug 22, 2025
View reviewed changes

@ZeroIntensity ZeroIntensity 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.

I'm not a huge fan of documenting things that should be private, but I think it's too late to move this to internal headers or rename it. We should consider deprecating this in 3.15.

@encukou Would you like to finish up your review?

Sorry, something went wrong.

Uh oh!

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

sergey-miryanov reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Aug 22, 2025
@encukou

encukou commented Aug 25, 2025

Copy link
Copy Markdown
Member

It's hard to deprecate a macro, so adding warnings in docs look best.
Thank you for sticking to this, @sergey-miryanov!

All reactions

Sorry, something went wrong.

Uh oh!

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

@encukou
encukou merged commit 5baa7a0 into python:main Aug 25, 2025
@bedevere-app bedevere-app Bot removed the awaiting merge label Aug 25, 2025
@github-project-automation github-project-automation Bot moved this from Todo to Done in Docs PRs Aug 25, 2025
@sergey-miryanov

sergey-miryanov commented Aug 25, 2025

Copy link
Copy Markdown
Contributor Author

Thanks everyone!

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 encukou left review comments
@ZeroIntensity ZeroIntensity ZeroIntensity approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

docs Documentation in the Doc dir skip news topic-C-API

Projects

Docs PRs
Status: Done

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.

4 participants

@sergey-miryanov @ZeroIntensity @encukou @markshannon
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.