gh-107603: Argument Clinic: Only include pycore_gc.h if needed (#108726)

Argument Clinic now only includes pycore_gc.h if PyGC_Head is needed,
and only includes pycore_runtime.h if _Py_ID() is needed.

* Add 'condition' optional argument to Clinic.add_include().
* deprecate_keyword_use() includes pycore_runtime.h when using
  the _PyID() function.
* Fix rendering of includes: comments start at the column 35.
* Mark PC/clinic/_wmimodule.cpp.h and
  "Objects/stringlib/clinic/*.h.h" header files as generated in
  .gitattributes.

Effects:

* 42 header files generated by AC no longer include the internal C
  API, instead of 4 header files before. For example,
  Modules/clinic/_abc.c.h no longer includes the internal C API.
* Fix _testclinic_depr.c.h: it now always includes pycore_runtime.h
  to get _Py_ID().
This commit is contained in:
Victor Stinner 2023-08-31 23:42:34 +02:00 committed by GitHub
parent 2bd960b579
commit ad73674283
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
131 changed files with 448 additions and 727 deletions

View file

@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
#include "pycore_abstract.h" // _PyNumber_Index()
static int
bytearray___init___impl(PyByteArrayObject *self, PyObject *arg,
@ -1285,4 +1284,4 @@ bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
{
return bytearray_sizeof_impl(self);
}
/*[clinic end generated code: output=d388e9027b333f00 input=a9049054013a1b77]*/
/*[clinic end generated code: output=94b9b5f492b5fed6 input=a9049054013a1b77]*/

View file

@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(bytes___bytes____doc__,
"__bytes__($self, /)\n"
@ -1061,4 +1060,4 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=9da56b6c04914e18 input=a9049054013a1b77]*/
/*[clinic end generated code: output=8a9f5c28cbfe7592 input=a9049054013a1b77]*/

View file

@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
PyDoc_STRVAR(method___reduce____doc__,
"__reduce__($self, /)\n"
"--\n"
@ -86,4 +80,4 @@ instancemethod_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
/*[clinic end generated code: output=2a5e7fa5947a86cb input=a9049054013a1b77]*/
/*[clinic end generated code: output=a0d17bad3b0734d9 input=a9049054013a1b77]*/

View file

@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
PyDoc_STRVAR(code_new__doc__,
"code(argcount, posonlyargcount, kwonlyargcount, nlocals, stacksize,\n"
" flags, codestring, constants, names, varnames, filename, name,\n"
@ -464,4 +463,4 @@ code__varname_from_oparg(PyCodeObject *self, PyObject *const *args, Py_ssize_t n
exit:
return return_value;
}
/*[clinic end generated code: output=0446968a1fbd13b2 input=a9049054013a1b77]*/
/*[clinic end generated code: output=b9ccfbfabe1a5f46 input=a9049054013a1b77]*/

View file

@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
PyDoc_STRVAR(complex_conjugate__doc__,
"conjugate($self, /)\n"
"--\n"
@ -157,4 +156,4 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=d438b7ed87f8459e input=a9049054013a1b77]*/
/*[clinic end generated code: output=002c74f8a33b6697 input=a9049054013a1b77]*/

View file

@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
static PyObject *
mappingproxy_new_impl(PyTypeObject *type, PyObject *mapping);
@ -167,4 +166,4 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=8dc1ddfcf764ac8e input=a9049054013a1b77]*/
/*[clinic end generated code: output=a97dc44d12f9f9b6 input=a9049054013a1b77]*/

View file

@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
PyDoc_STRVAR(dict_fromkeys__doc__,
"fromkeys($type, iterable, value=None, /)\n"
"--\n"
@ -197,4 +191,4 @@ dict___reversed__(PyDictObject *self, PyObject *Py_UNUSED(ignored))
{
return dict___reversed___impl(self);
}
/*[clinic end generated code: output=c0064abbea6091c5 input=a9049054013a1b77]*/
/*[clinic end generated code: output=582766ac0154c8bf input=a9049054013a1b77]*/

View file

@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
PyDoc_STRVAR(enum_new__doc__,
"enumerate(iterable, start=0)\n"
"--\n"
@ -107,4 +106,4 @@ reversed_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
/*[clinic end generated code: output=aba0ddbeab1601e3 input=a9049054013a1b77]*/
/*[clinic end generated code: output=661b29708f501d19 input=a9049054013a1b77]*/

View file

@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
PyDoc_STRVAR(float_is_integer__doc__,
"is_integer($self, /)\n"
"--\n"
@ -322,4 +316,4 @@ float___format__(PyObject *self, PyObject *arg)
exit:
return return_value;
}
/*[clinic end generated code: output=355c3f5102034a41 input=a9049054013a1b77]*/
/*[clinic end generated code: output=eb093cc601cc5426 input=a9049054013a1b77]*/

View file

@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
PyDoc_STRVAR(func_new__doc__,
"function(code, globals, name=None, argdefs=None, closure=None)\n"
"--\n"
@ -104,4 +103,4 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=777cead7b1f6fad3 input=a9049054013a1b77]*/
/*[clinic end generated code: output=b2d676ff51c992d0 input=a9049054013a1b77]*/

View file

@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(list_insert__doc__,
"insert($self, index, object, /)\n"
@ -384,4 +383,4 @@ list___reversed__(PyListObject *self, PyObject *Py_UNUSED(ignored))
{
return list___reversed___impl(self);
}
/*[clinic end generated code: output=537a17b562c57505 input=a9049054013a1b77]*/
/*[clinic end generated code: output=e2d9f4092498a5ca input=a9049054013a1b77]*/

View file

@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
#include "pycore_abstract.h" // _PyNumber_Index()
static PyObject *
long_new_impl(PyTypeObject *type, PyObject *x, PyObject *obase);
@ -476,4 +475,4 @@ int_is_integer(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return int_is_integer_impl(self);
}
/*[clinic end generated code: output=ea9c87ea532dadbe input=a9049054013a1b77]*/
/*[clinic end generated code: output=009a537ab558763c input=a9049054013a1b77]*/

View file

@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
PyDoc_STRVAR(memoryview__doc__,
"memoryview(object)\n"
"--\n"
@ -413,4 +412,4 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=28a632db32b44b63 input=a9049054013a1b77]*/
/*[clinic end generated code: output=7ebdadda3b0fcd35 input=a9049054013a1b77]*/

View file

@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
PyDoc_STRVAR(module___init____doc__,
"module(name, doc=None)\n"
"--\n"
@ -74,4 +73,4 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=a5a750cc8190576e input=a9049054013a1b77]*/
/*[clinic end generated code: output=9d3d7854d17a033c input=a9049054013a1b77]*/

View file

@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
PyDoc_STRVAR(OrderedDict_fromkeys__doc__,
"fromkeys($type, /, iterable, value=None)\n"
"--\n"
@ -332,4 +331,4 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=76d85a9162d62ca8 input=a9049054013a1b77]*/
/*[clinic end generated code: output=6d7ae9fb552c6108 input=a9049054013a1b77]*/

View file

@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
static PyObject *
structseq_new_impl(PyTypeObject *type, PyObject *arg, PyObject *dict);
@ -62,4 +61,4 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=802d5663c7d01024 input=a9049054013a1b77]*/
/*[clinic end generated code: output=2f88fe2a6f5c13a8 input=a9049054013a1b77]*/

View file

@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
PyDoc_STRVAR(tuple_index__doc__,
"index($self, value, start=0, stop=sys.maxsize, /)\n"
"--\n"
@ -118,4 +112,4 @@ tuple___getnewargs__(PyTupleObject *self, PyObject *Py_UNUSED(ignored))
{
return tuple___getnewargs___impl(self);
}
/*[clinic end generated code: output=48a9e0834b300ac3 input=a9049054013a1b77]*/
/*[clinic end generated code: output=7c5d9d12e0cf6a83 input=a9049054013a1b77]*/

View file

@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
PyDoc_STRVAR(type___instancecheck____doc__,
"__instancecheck__($self, instance, /)\n"
"--\n"
@ -266,4 +260,4 @@ object___dir__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return object___dir___impl(self);
}
/*[clinic end generated code: output=baf5ec2093815a3f input=a9049054013a1b77]*/
/*[clinic end generated code: output=943f639f264362d9 input=a9049054013a1b77]*/

View file

@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
PyDoc_STRVAR(typevar_new__doc__,
"typevar(name, *constraints, *, bound=None, covariant=False,\n"
" contravariant=False, infer_variance=False)\n"
@ -591,4 +590,4 @@ skip_optional_kwonly:
exit:
return return_value;
}
/*[clinic end generated code: output=d614edf64f28e346 input=a9049054013a1b77]*/
/*[clinic end generated code: output=db0b327ebbb1488f input=a9049054013a1b77]*/

View file

@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(EncodingMap_size__doc__,
"size($self, /)\n"
@ -1505,4 +1504,4 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=a64776a3ea1c970c input=a9049054013a1b77]*/
/*[clinic end generated code: output=8d08dfbb814c4393 input=a9049054013a1b77]*/

View file

@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(stringlib_expandtabs__doc__,
"expandtabs($self, /, tabsize=8)\n"
@ -279,4 +278,4 @@ stringlib_zfill(PyObject *self, PyObject *arg)
exit:
return return_value;
}
/*[clinic end generated code: output=a0338b2d41671b17 input=a9049054013a1b77]*/
/*[clinic end generated code: output=39cd1ee983137188 input=a9049054013a1b77]*/