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-141070: Add PyUnstable_Object_Dump() function by vstinner · Pull Request #141072 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Nov 5, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member
  • Promote _PyObject_Dump() as a public function.
  • Keep _PyObject_Dump() alias to PyUnstable_Object_Dump() for backward compatibility.
  • Replace _PyObject_Dump() with PyUnstable_Object_Dump().
  • Issue: [C API] Promote _PyObject_Dump() to a public function #141070

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

Sorry, something went wrong.

Uh oh!

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

All reactions
@vstinner
pythongh-141070: Add PyObject_Dump() function
2d55425
* Promote _PyObject_Dump() as a public function.
* Keep _PyObject_Dump() alias to PyObject_Dump() for backward
  compatibility.
* Replace _PyObject_Dump() with PyObject_Dump().
@vstinner
vstinner requested review from AA-Turner, ZeroIntensity and ericsnowcurrently as code owners November 5, 2025 21:10
@bedevere-app bedevere-app Bot added the awaiting core review label Nov 5, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Nov 5, 2025
[C API] Promote _PyObject_Dump() to a public function #141070
Closed
@vstinner

vstinner commented Nov 5, 2025

Copy link
Copy Markdown
Member Author

cc @ZeroIntensity @picnixz

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner vstinner added type-feature A feature request or enhancement topic-C-API labels Nov 5, 2025
@vstinner
Fix doc formatting
8abec04
@vstinner vstinner removed the type-feature A feature request or enhancement label Nov 5, 2025
@ZeroIntensity

ZeroIntensity commented Nov 5, 2025

Copy link
Copy Markdown
Member

The tests seem to be failing on Windows.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner
Try to fix test on Windows
4338ac0
@vstinner

vstinner commented Nov 5, 2025

Copy link
Copy Markdown
Member Author

The tests seem to be failing on Windows.

object address : 0000017EAEAFA4D0

Ah yes, printf("%p", ptr) doesn't print 0x prefix on Windows.

All reactions

Sorry, something went wrong.

Uh oh!

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

ZeroIntensity
ZeroIntensity approved these changes Nov 5, 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 with a few English nitpicks on the docs.

Sorry, something went wrong.

Uh oh!

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

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

Uh oh!

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

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

Uh oh!

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

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

Uh oh!

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

@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Nov 5, 2025
vstinner and others added 3 commits November 6, 2025 00:18
@vstinner @ZeroIntensity
Update Doc/c-api/object.rst
2e982a1
Co-authored-by: Peter Bierma <[email protected]>
@vstinner @ZeroIntensity
Update Doc/c-api/object.rst
e4c7cdc
Co-authored-by: Peter Bierma <[email protected]>
@vstinner @ZeroIntensity
Update Doc/c-api/object.rst
c65db8f
Co-authored-by: Peter Bierma <[email protected]>
kumaraditya303
kumaraditya303 reviewed Nov 6, 2025
View reviewed changes
Comment thread Doc/c-api/object.rst Resolved

Uh oh!

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

kumaraditya303
kumaraditya303 approved these changes Nov 6, 2025
View reviewed changes
@encukou

encukou commented Nov 6, 2025

Copy link
Copy Markdown
Member

I think this is a great candidate for unstable API.

All reactions

Sorry, something went wrong.

Uh oh!

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

encukou
encukou reviewed Nov 6, 2025
View reviewed changes
Comment thread Doc/c-api/object.rst Resolved

Uh oh!

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

vstinner and others added 4 commits November 6, 2025 12:07
@vstinner @kumaraditya303
Update Doc/c-api/object.rst
94b9315
Co-authored-by: Kumar Aditya <[email protected]>
@vstinner @encukou
Enhance the doc
423d25a
Co-authored-by: Petr Viktorin <[email protected]>
@vstinner
Enhance tests: test NULL and release the GIL
f64a812
@vstinner
The output format may change at any time
bf279d3
@vstinner vstinner mentioned this pull request Nov 6, 2025
Add PyUnstable_Object_Dump() function: promote private _PyObject_Dump() to a public function capi-workgroup/decisions#87
Closed
5 tasks done
@vstinner

vstinner commented Nov 6, 2025

Copy link
Copy Markdown
Member Author

I created a C API Working Group decision issue.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner
Fix NULL test on macOS and Windows
70f5433
@ZeroIntensity

ZeroIntensity commented Nov 8, 2025

Copy link
Copy Markdown
Member

Hm, @encukou, why make this an unstable API? I don't think we ever plan to remove the ability to print objects from the C API. If you're concerned about people relying on the exact output, we can just tell them "don't do that" in the docs.

picnixz 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 commented Nov 10, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

I don't think we ever plan to remove the ability to print objects from the C API.

That we don't, but _PyObject_Dump is about dumping object internals to a fixed stream. AFAICS, it's strictly a debugging tool.

Or is there a use case where you call this from a releasable extension?

All reactions

Sorry, something went wrong.

Uh oh!

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

@ZeroIntensity

ZeroIntensity commented Nov 10, 2025

Copy link
Copy Markdown
Member

Or is there a use case where you call this from a releasable extension?

Absolutely, we do it ourselves. It's a convenient debugging tool, but it's also quite handy as a last-ditch effort to display something to the user, like with PyErr_Display.

I think as long as we specify the function as "dump non-specific debugging information about an object", it should be fine to add it as a non-unstable API. If we do add it to PyUnstable, I'd be strongly -1 on any proposal to remove it, which I feel kind of defeats the point of the unstable API in the first place.

All reactions

Sorry, something went wrong.

Uh oh!

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

vstinner added 2 commits November 18, 2025 16:34
@vstinner
Rename to PyUnstable_Object_Dump()
56ac7ef
@vstinner
Merge branch 'main' into object_dump
b98c9b2
vstinner
vstinner commented Nov 18, 2025
View reviewed changes
Comment thread Doc/whatsnew/3.15.rst

* Add a new :c:func:`PyImport_CreateModuleFromInitfunc` C-API for creating
a module from a *spec* and *initfunc*.
(Contributed by Itamar Oren in :gh:`116146`.)

@vstinner vstinner Nov 18, 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.

Entries should be sorted.

Sorry, something went wrong.

Uh oh!

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

All reactions

@encukou encukou Nov 18, 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.

I didn't know that. What's the sort key?

Sorry, something went wrong.

Uh oh!

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

All reactions

@vstinner vstinner Nov 18, 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.

"Sorted alphabetically". @hugovk added comments like that in the What's New document:

.. Add C API deprecations above alphabetically, not here at the end.

We should add a similar comment for C API "New features". I think that it was @AA-Turner who started to sort items in What's New In Python 3.14.

Sorry, something went wrong.

Uh oh!

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

All reactions
@vstinner
simplify test
376a186
@vstinner

vstinner commented Nov 18, 2025

Copy link
Copy Markdown
Member Author

I renamed the function to PyUnstable_Object_Dump().

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner vstinner changed the title gh-141070: Add PyObject_Dump() function gh-141070: Add PyUnstable_Object_Dump() function Nov 18, 2025
@encukou

encukou commented Nov 18, 2025

Copy link
Copy Markdown
Member

Absolutely, we do it ourselves.

That's debugging helper. Unstable API is great for those :)

If we do add it to PyUnstable, I'd be strongly -1 on any proposal to remove it, which I feel kind of defeats the point of the unstable API in the first place.

There's a bunch of unstable API like that -- I think some people would be sad to PyUnstable_Code_GetExtra go, for example.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Nov 18, 2025

Copy link
Copy Markdown
Member Author

@ZeroIntensity: I prefer the PyUnstable prefix since the function behavior is not well defined. It can change between Python versions, especially the output, even if it has not changed frequently. Also, this function should only be used for debugging purpose. Well, I proposed PyUnstable_Object_Dump() name to the C API Working Group and it's been accepted (4/5 votes so far).

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner
vstinner enabled auto-merge (squash) November 18, 2025 16:05
@vstinner
vstinner merged commit 600f3fe into python:main Nov 18, 2025
46 checks passed

Uh oh!

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

@vstinner
vstinner deleted the object_dump branch November 18, 2025 16:13
@bedevere-app bedevere-app Bot removed the awaiting merge label Nov 18, 2025
serhiy-storchaka
serhiy-storchaka reviewed Nov 18, 2025
View reviewed changes
Comment thread Objects/object.c
_PyObject_Dump(PyObject* op)
PyUnstable_Object_Dump(PyObject* op)
{
if (_PyObject_IsFreed(op)) {

@serhiy-storchaka serhiy-storchaka Nov 18, 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.

Maybe add a special case for op == NULL?

And for type == NULL?

Sorry, something went wrong.

Uh oh!

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

All reactions

@vstinner vstinner Nov 18, 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.

It displays freed in both cases. There is now an unit test for that.

How do you suggest to format op==NULL and/or type==NULL?

Sorry, something went wrong.

Uh oh!

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

All reactions

@serhiy-storchaka serhiy-storchaka Nov 18, 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.

If this is already tested, then good. I was not sure that _PyObject_IsFreed() works with NULL (it could crash).

If type==NULL (very unlikely), then type->tp_name and repr() will crash. They will also crash if type was freed or if it is just a garbage. We could skip prints in that case avoid crash, although it may be too late.

Looking at the code, it seems the ideas I had (testing against the patterns used to fill the freed memory) was already implemented in _PyMem_IsPtrFreed().

Sorry, something went wrong.

Uh oh!

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

All reactions

@vstinner vstinner Nov 18, 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.

If type==NULL (very unlikely), then type->tp_name and repr() will crash

_PyObject_IsFreed() checks _PyMem_IsPtrFreed(Py_TYPE(op)). We just display freed in this case, without displaying tp_name or trying to call repr().

Sorry, something went wrong.

Uh oh!

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

All reactions
@ZeroIntensity

ZeroIntensity commented Nov 18, 2025

Copy link
Copy Markdown
Member

There's a bunch of unstable API like that -- I think some people would be sad to PyUnstable_Code_GetExtra go, for example.

What's the point of an unstable API that we can't remove?

All reactions

Sorry, something went wrong.

Uh oh!

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

StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
@vstinner @ZeroIntensity
@kumaraditya303 @encukou @StanFromIreland
pythongh-141070: Add PyUnstable_Object_Dump() function (python#141072)
7aab25c
* Promote _PyObject_Dump() as a public function.
* Keep _PyObject_Dump() alias to PyUnstable_Object_Dump()
  for backward compatibility.
* Replace _PyObject_Dump() with PyUnstable_Object_Dump().

Co-authored-by: Peter Bierma <[email protected]>
Co-authored-by: Kumar Aditya <[email protected]>
Co-authored-by: Petr Viktorin <[email protected]>
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
@serhiy-storchaka serhiy-storchaka serhiy-storchaka left review comments
@ZeroIntensity ZeroIntensity ZeroIntensity approved these changes
@kumaraditya303 kumaraditya303 kumaraditya303 approved these changes
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@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

topic-C-API

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

@vstinner @ZeroIntensity @encukou @serhiy-storchaka @kumaraditya303
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.