Skip to content

Commit a4760cc

Browse files
authored
bpo-42747: Remove Py_TPFLAGS_HAVE_AM_SEND and make Py_TPFLAGS_HAVE_VERSION_TAG no-op (GH-27260)
* Remove code that checks Py_TPFLAGS_HAVE_VERSION_TAG The field is always present in the type struct, as explained in the added comment. * Remove Py_TPFLAGS_HAVE_AM_SEND The flag is not needed, and since it was added in 3.10 it can be removed now.
1 parent 7d28a6e commit a4760cc

File tree

7 files changed

+24
-56
lines changed

7 files changed

+24
-56
lines changed

Doc/c-api/typeobj.rst

+1-10
Original file line numberDiff line numberDiff line change
@@ -1098,8 +1098,7 @@ and :c:type:`PyType_Type` effectively act as defaults.)
10981098

10991099
This is a bitmask of all the bits that pertain to the existence of certain
11001100
fields in the type object and its extension structures. Currently, it includes
1101-
the following bits: :const:`Py_TPFLAGS_HAVE_STACKLESS_EXTENSION`,
1102-
:const:`Py_TPFLAGS_HAVE_VERSION_TAG`.
1101+
the following bits: :const:`Py_TPFLAGS_HAVE_STACKLESS_EXTENSION`.
11031102

11041103
**Inheritance:**
11051104

@@ -1179,14 +1178,6 @@ and :c:type:`PyType_Type` effectively act as defaults.)
11791178

11801179
.. versionadded:: 3.9
11811180

1182-
1183-
.. data:: Py_TPFLAGS_HAVE_AM_SEND
1184-
1185-
This bit is set when the :c:member:`~PyAsyncMethods.am_send` entry is present in the
1186-
:c:member:`~PyTypeObject.tp_as_async` slot of type structure.
1187-
1188-
.. versionadded:: 3.10
1189-
11901181
.. data:: Py_TPFLAGS_IMMUTABLETYPE
11911182

11921183
This bit is set for type objects that are immutable: type attributes cannot be set nor deleted.

Include/object.h

+12-14
Original file line numberDiff line numberDiff line change
@@ -368,18 +368,12 @@ given type object has a specified feature.
368368
/* Objects behave like an unbound method */
369369
#define Py_TPFLAGS_METHOD_DESCRIPTOR (1UL << 17)
370370

371-
/* Objects support type attribute cache */
372-
#define Py_TPFLAGS_HAVE_VERSION_TAG (1UL << 18)
371+
/* Object has up-to-date type attribute cache */
373372
#define Py_TPFLAGS_VALID_VERSION_TAG (1UL << 19)
374373

375374
/* Type is abstract and cannot be instantiated */
376375
#define Py_TPFLAGS_IS_ABSTRACT (1UL << 20)
377376

378-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000
379-
/* Type has am_send entry in tp_as_async slot */
380-
#define Py_TPFLAGS_HAVE_AM_SEND (1UL << 21)
381-
#endif
382-
383377
// This undocumented flag gives certain built-ins their unique pattern-matching
384378
// behavior, which allows a single positional subpattern to match against the
385379
// subject itself (rather than a mapped attribute on it):
@@ -397,19 +391,23 @@ given type object has a specified feature.
397391

398392
#define Py_TPFLAGS_DEFAULT ( \
399393
Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \
400-
Py_TPFLAGS_HAVE_VERSION_TAG | \
401394
0)
402395

403-
/* NOTE: The following flags reuse lower bits (removed as part of the
396+
/* NOTE: Some of the following flags reuse lower bits (removed as part of the
404397
* Python 3.0 transition). */
405398

406-
/* The following flag is kept for compatibility. Starting with 3.8,
407-
* binary compatibility of C extensions across feature releases of
408-
* Python is not supported anymore, except when using the stable ABI.
399+
/* The following flags are kept for compatibility; in previous
400+
* versions they indicated presence of newer tp_* fields on the
401+
* type struct.
402+
* Starting with 3.8, binary compatibility of C extensions across
403+
* feature releases of Python is not supported anymore (except when
404+
* using the stable ABI, in which all classes are created dynamically,
405+
* using the interpreter's memory layout.)
406+
* Note that older extensions using the stable ABI set these flags,
407+
* so the bits must not be repurposed.
409408
*/
410-
411-
/* Type structure has tp_finalize member (3.4) */
412409
#define Py_TPFLAGS_HAVE_FINALIZE (1UL << 0)
410+
#define Py_TPFLAGS_HAVE_VERSION_TAG (1UL << 18)
413411

414412

415413
/*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The ``Py_TPFLAGS_HAVE_VERSION_TAG`` type flag now does nothing. The
2+
``Py_TPFLAGS_HAVE_AM_SEND`` flag (which was added in 3.10) is removed. Both
3+
were unnecessary because it is not possible to have type objects with the
4+
relevant fields missing.

Modules/_asynciomodule.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -1764,8 +1764,7 @@ static PyTypeObject FutureIterType = {
17641764
.tp_dealloc = (destructor)FutureIter_dealloc,
17651765
.tp_as_async = &FutureIterType_as_async,
17661766
.tp_getattro = PyObject_GenericGetAttr,
1767-
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
1768-
Py_TPFLAGS_HAVE_AM_SEND,
1767+
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
17691768
.tp_traverse = (traverseproc)FutureIter_traverse,
17701769
.tp_iter = PyObject_SelfIter,
17711770
.tp_iternext = (iternextfunc)FutureIter_iternext,

Objects/abstract.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -2804,9 +2804,7 @@ PyIter_Send(PyObject *iter, PyObject *arg, PyObject **result)
28042804
_Py_IDENTIFIER(send);
28052805
assert(arg != NULL);
28062806
assert(result != NULL);
2807-
if (PyType_HasFeature(Py_TYPE(iter), Py_TPFLAGS_HAVE_AM_SEND)) {
2808-
assert (Py_TYPE(iter)->tp_as_async != NULL);
2809-
assert (Py_TYPE(iter)->tp_as_async->am_send != NULL);
2807+
if (Py_TYPE(iter)->tp_as_async && Py_TYPE(iter)->tp_as_async->am_send) {
28102808
PySendResult res = Py_TYPE(iter)->tp_as_async->am_send(iter, arg, result);
28112809
assert(_Py_CheckSlotResult(iter, "am_send", res != PYGEN_ERROR));
28122810
return res;

Objects/genobject.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,7 @@ PyTypeObject PyGen_Type = {
782782
PyObject_GenericGetAttr, /* tp_getattro */
783783
0, /* tp_setattro */
784784
0, /* tp_as_buffer */
785-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
786-
Py_TPFLAGS_HAVE_AM_SEND, /* tp_flags */
785+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
787786
0, /* tp_doc */
788787
(traverseproc)gen_traverse, /* tp_traverse */
789788
0, /* tp_clear */
@@ -1029,8 +1028,7 @@ PyTypeObject PyCoro_Type = {
10291028
PyObject_GenericGetAttr, /* tp_getattro */
10301029
0, /* tp_setattro */
10311030
0, /* tp_as_buffer */
1032-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
1033-
Py_TPFLAGS_HAVE_AM_SEND, /* tp_flags */
1031+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
10341032
0, /* tp_doc */
10351033
(traverseproc)gen_traverse, /* tp_traverse */
10361034
0, /* tp_clear */
@@ -1415,8 +1413,7 @@ PyTypeObject PyAsyncGen_Type = {
14151413
PyObject_GenericGetAttr, /* tp_getattro */
14161414
0, /* tp_setattro */
14171415
0, /* tp_as_buffer */
1418-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
1419-
Py_TPFLAGS_HAVE_AM_SEND, /* tp_flags */
1416+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
14201417
0, /* tp_doc */
14211418
(traverseproc)async_gen_traverse, /* tp_traverse */
14221419
0, /* tp_clear */

Objects/typeobject.c

+2-21
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,6 @@ PyType_Modified(PyTypeObject *type)
324324
325325
Invariants:
326326
327-
- Py_TPFLAGS_VALID_VERSION_TAG is never set if
328-
Py_TPFLAGS_HAVE_VERSION_TAG is not set (in case of a
329-
bizarre MRO, see type_mro_modified()).
330-
331327
- before Py_TPFLAGS_VALID_VERSION_TAG can be set on a type,
332328
it must first be set on all super types.
333329
@@ -379,9 +375,6 @@ type_mro_modified(PyTypeObject *type, PyObject *bases) {
379375
PyObject *mro_meth = NULL;
380376
PyObject *type_mro_meth = NULL;
381377

382-
if (!_PyType_HasFeature(type, Py_TPFLAGS_HAVE_VERSION_TAG))
383-
return;
384-
385378
if (custom) {
386379
mro_meth = lookup_maybe_method(
387380
(PyObject *)type, &PyId_mro, &unbound);
@@ -404,17 +397,15 @@ type_mro_modified(PyTypeObject *type, PyObject *bases) {
404397
assert(PyType_Check(b));
405398
cls = (PyTypeObject *)b;
406399

407-
if (!_PyType_HasFeature(cls, Py_TPFLAGS_HAVE_VERSION_TAG) ||
408-
!PyType_IsSubtype(type, cls)) {
400+
if (!PyType_IsSubtype(type, cls)) {
409401
goto clear;
410402
}
411403
}
412404
return;
413405
clear:
414406
Py_XDECREF(mro_meth);
415407
Py_XDECREF(type_mro_meth);
416-
type->tp_flags &= ~(Py_TPFLAGS_HAVE_VERSION_TAG|
417-
Py_TPFLAGS_VALID_VERSION_TAG);
408+
type->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG;
418409
type->tp_version_tag = 0; /* 0 is not a valid version tag */
419410
}
420411

@@ -431,8 +422,6 @@ assign_version_tag(struct type_cache *cache, PyTypeObject *type)
431422

432423
if (_PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG))
433424
return 1;
434-
if (!_PyType_HasFeature(type, Py_TPFLAGS_HAVE_VERSION_TAG))
435-
return 0;
436425
if (!_PyType_HasFeature(type, Py_TPFLAGS_READY))
437426
return 0;
438427

@@ -5978,14 +5967,6 @@ type_ready_pre_checks(PyTypeObject *type)
59785967
_PyObject_ASSERT((PyObject *)type, type->tp_call != NULL);
59795968
}
59805969

5981-
/* Consistency check for Py_TPFLAGS_HAVE_AM_SEND - flag requires
5982-
* type->tp_as_async->am_send to be present.
5983-
*/
5984-
if (type->tp_flags & Py_TPFLAGS_HAVE_AM_SEND) {
5985-
_PyObject_ASSERT((PyObject *)type, type->tp_as_async != NULL);
5986-
_PyObject_ASSERT((PyObject *)type, type->tp_as_async->am_send != NULL);
5987-
}
5988-
59895970
/* Consistency checks for pattern matching
59905971
* Py_TPFLAGS_SEQUENCE and Py_TPFLAGS_MAPPING are mutually exclusive */
59915972
_PyObject_ASSERT((PyObject *)type, (type->tp_flags & COLLECTION_FLAGS) != COLLECTION_FLAGS);

0 commit comments

Comments
 (0)