Skip to content

Deprecation of PyException_HEAD #142410

Closed
Closed

Description

@Krishna-web-hub

Summary

This issue proposes the depreciation of the PyException_HEAD macro.

During review of PR #141522 (Document PyException_HEAD), the reviewers indicated that
this macro is internal, should not be documented, and should instead be deprecated.

  • PyException_HEAD is an internal macro used in CPython to define exception types.
  • It is not part of the public C API and was never intended to be used externally.
  • However, a small number of external projects have copied this pattern (for example,
    confluent_kafka).
  • If there are some internals change in the future (e.g. for PEP 697), this macro will
    create a maintenance burden.

This deprecation would allow external projects time to migrate, rather than breaking
them immediately.

Proposed actions

  • Marking the macro as deprecated in the header using Py_DEPRECATED() or a
    compiler warning.
  • We can also add the documentation note stating that the macro is deprecated and may be
    removed in a future release.
  • We can add a NEWS entry.
  • Recommending that new code use exception creation patterns compatible with PEP 697.

No behavior change or removal is proposed at this time.

CC

@ZeroIntensity
@vstinner
@StanFromIreland

Has this already been discussed elsewhere?

This has been discussed in one of the closed pr #141522

Links to previous discussion of this feature:

#141522

Linked PRs

Activity

  1. added
    type-feature
    on Dec 8, 2025
  2. added
    interpreter-core
    on Dec 8, 2025
  3. picnixz commented on Dec 8, 2025

    @picnixz
    Member

    For the record, it's non-trivial to deprecate a macro. Unlike functions, macros don't have compiler's attributes. We could make an ugly hack where the fields in this macro are deprecated though.

  4. ZeroIntensity commented on Dec 8, 2025

    @ZeroIntensity
    Member

    We'll just soft-deprecate this if approved by the C API WG: capi-workgroup/decisions#86. It might be worth doing a hard-deprecation at some point, but I'm not going to bother fighting that battle right now.

  5. Krishna-web-hub commented on Dec 8, 2025

    @Krishna-web-hub
    Author
  6. ZeroIntensity commented on Dec 8, 2025

    @ZeroIntensity
    Member

    Let's wait until the C API WG has finished voting, then we can document the soft deprecation.

  7. picnixz commented on Dec 8, 2025

    @picnixz
  8. Krishna-web-hub commented on Dec 8, 2025

    @Krishna-web-hub
    Author
  9. vstinner commented on Dec 8, 2025

    @vstinner
    Member

    This issue proposes the depreciation of the PyException_HEAD macro.

    I would prefer a soft deprecation rather than a hard deprecation. I don't think that this issue is severe enough to justify a hard deprecation.

  10. Krishna-web-hub commented on Dec 9, 2025

    @Krishna-web-hub
    ContributorAuthor

    Thank you @vstinner. That makes sense. I will wait for the C API WG decision, and if approved, I can submit a PR that
    adds the documentation note and NEWS entry for the soft deprecation.

  11. Krishna-web-hub commented on Feb 13, 2026

    @Krishna-web-hub
    ContributorAuthor

    Hello @vstinner , @picnixz , @ZeroIntensity as C API WG has decided to soft deprecate the PyException_Head so should i raise a pr for the soft deprecation of PyException_Head.

  12. vstinner commented on Feb 13, 2026

    @vstinner
    Member

    Yes, you can open a PR to soft deprecate the PyException_HEAD macro.

  13. added 2 commits that reference this issue on Mar 1, 2026
  14. ZeroIntensity commented on Mar 1, 2026

    @ZeroIntensity
    Member

    I thought I already marked it as deprecated as part of #143896. I haven't added a warning note to any of the other soft-deprecated APIs, so I don't think it makes sense for PyException_HEAD to have one either.

  15. Krishna-web-hub commented on Mar 1, 2026

    @Krishna-web-hub
    ContributorAuthor

    @ZeroIntensity then should i close the PR and the Issue for this or any changes you want?.

  16. ZeroIntensity commented on Mar 2, 2026

    @ZeroIntensity
    Member

    Yeah, I think we're done here.

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

    interpreter-coretopic-C-APItype-feature

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions