Skip to content

Add PyUnstable_Object_Dump() function: promote private _PyObject_Dump() to a public function #87

Closed

Description

@vstinner

I propose promoting the private _PyObject_Dump() function to a public function, as PyUnstable_Object_Dump().

API: void PyUnstable_Object_Dump(PyObject *op)

  • Dump an object op to stderr. This should only be used for debugging.
  • The output is intended to try dumping objects even after memory corruption (see the PR for the whole documentation).
  • Example of output:
object address  : 0x7f80124702c0
object refcount : 2
object type     : 0x9902e0
object type name: str
object repr     : 'abcdef'

See:

Vote:

Activity

  1. vstinner commented on Nov 12, 2025

    @vstinner
    Author
  2. vstinner commented on Nov 17, 2025

    @vstinner
    Author
  3. vstinner commented on Nov 18, 2025

    @vstinner
    Author

    Ok, the C API Working Group approved this API. Thanks you all!

  4. serhiy-storchaka commented on Nov 18, 2025

    @serhiy-storchaka

    Is there a need to add a parameter for the output stream or file descriptor?

  5. vstinner commented on Nov 18, 2025

    @vstinner
    Author

    Is there a need to add a parameter for the output stream or file descriptor?

    I don't think so. I prefer to hardcode stderr, since stderr is used for debugging. It simplify the code.

    In practice, the code writes to the C stderr stream and to the Python sys.stderr object.

  6. vstinner commented on Nov 18, 2025

    @vstinner
    Author

    In practice, the code writes to the C stderr stream and to the Python sys.stderr object.

    Sorry, I just checked the code, it's only the C stderr stream.

  7. encukou commented on Dec 16, 2025

    @encukou
    Collaborator

    Reopening to make this fully public -- see the Discourse thread.

    Expose this as PyObject_Dump rather than PyUnstable_Object_Dump.

    I'll abstain.

  8. added
    voteThe WG is voting (or has voted)
    on Dec 16, 2025
  9. erlend-aasland commented on Dec 16, 2025

    @erlend-aasland

    Why do you abstain? From your latest comment over at DPO, it appears you are approving.

  10. encukou commented on Dec 16, 2025

    @encukou
    Collaborator

    I'd prefer either PyUnstable_Object_Dump (purity -- debug helpers should be unstable) or Py_Dump (practicality -- short to type in gdb). I don't think the compromise solves much.
    But I'll yield to the majority.

  11. davidhewitt commented on Dec 16, 2025

    @davidhewitt

    What about PyUnstable_Dump?

  12. vstinner commented on Jan 8, 2026

    @vstinner
    Author
  13. zooba commented on Jan 12, 2026

    @zooba

    +1 to PyObject_Dump

  14. encukou commented on Jan 15, 2026

    @encukou
    Collaborator
  15. serhiy-storchaka commented on Jan 15, 2026

    @serhiy-storchaka

    Sorry, I though I already voted for this.

    BTW, I recently searched bugs in set, and needed to output the dump of the set, including empty and dummy entries. I initially tried to use PyUnstable_Object_Dump(), but it was not so helpful when output several dumps one after other. More compact format with indentation would be more convenient. But this was a special one-time case. I ended with using simple fprintf(). If make PyObject_Dump() more configurable, it will be less convenient in cases where it is currently used.

  16. vstinner commented on Jan 16, 2026

    @vstinner
    Author

    The C API Working approved renaming the function to PyObject_Dump(). I close the issue. See PR python/cpython#142848 to rename the function.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    voteThe WG is voting (or has voted)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions