Skip to content

Add support for Include What You Use/Clang Include Cleaner in Python.h #137744

@EugeneZelenko

Description

@EugeneZelenko

Feature or enhancement

Proposal:

It'll be great to add IWYU pragma: begin_exports/IWYU pragma: end_exports around internal CPython headers in Python.h.

Currently Clang Include Cleaner complains that Python.h is not used as well as headers for all used parts of CPython API are not included directly.

Example output snippet for Clang Include Cleaner run as Clang-Tidy check:

test.cpp:10:1: warning: included header Python.h is not used directly [misc-include-cleaner]
   10 | #include <Python.h>
      | ^~~~~~~~~~~~~~~~~~~
   11 | #include <cstddef>
test.cpp:50:5: warning: no header providing "PyObject_HEAD" is directly included [misc-include-cleaner]
   50 |     PyObject_HEAD
      |     ^
test.cpp:57:1: warning: no header providing "PyObject" is directly included [misc-include-cleaner]
   12 | PyObject* test_iter_new(Test_Object* element, PyTypeObject* iter_type)
      | ^

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions