@@ -122,29 +122,21 @@ The macros simplify hand-written literals.
122122For more complex use cases, like compatibility between several Python versions,
123123or templated/auto-generated slot arrays, as well as for non-C users of the
124124C API, the slot struct definitions can be written out.
125- For example, if the transition from `` tp_getattr `` to `` tp_getattro ``
126- was happening in the near future (say, CPython 3.17), rather than 1.4, and
127- the user wanted to support CPython with and without `` tp_getattro ``, they could
128- add a "`` HAS_FALLBACK ``" flag ::
125+ For example, if the `` nb_matrix_multiply `` slot ( :pep: ` 465 `) was added in the
126+ near future (say, CPython 3.17) rather than in 3.5, users could add it with
127+ an "`` OPTIONAL ``" flag, making their class support the `` @ `` operator only
128+ on CPython versions with that operator ::
129129
130130 static PySlot myClass_slots[] = {
131131 ...
132132 { // skipped if not supported
133- .sl_id=Py_tp_getattro,
134- .sl_flags=PySlot_HAS_FALLBACK,
135- .sl_func=myClass_getattro,
136- },
137- { // used if if the slot above was skipped
138- .sl_id=Py_tp_getattr,
139- .sl_func=myClass_old_getattr,
133+ .sl_id=Py_nb_matrix_multiply,
134+ .sl_flags=PySlot_OPTIONAL,
135+ .sl_func=myClass_matmul,
140136 },
141137 PySlot_END,
142138 }
143139
144- Similarly, if the ``nb_matrix_multiply `` slot (:pep: `465 `) was added in the
145- near future, users could add it with an "``OPTIONAL ``" flag, making their class
146- support the ``@ `` operator only on CPython versions with that operator.
147-
148140
149141.. _pep820-rationale :
150142
@@ -400,17 +392,6 @@ Flags
400392 *array * of ``PyMemberDef `` structures, then the entire array, as well as the
401393 ``name `` and ``doc `` strings in its elements, must be static and constant.
402394
403- - ``PySlot_HAS_FALLBACK ``: If the slot ID is unknown, the interpreter will
404- ignore the slot.
405- If it's known, the interpreter should ignore subsequent slots up to
406- (and including) the first one without HAS_FALLBACK.
407-
408- Effectively, consecutive slots with the HAS_FALLBACK flag, plus the first
409- non-HAS_FALLBACK slot after them, form a “block” where the the interpreter
410- will only consider the *first * slot in the block that it understands.
411- If the entire block is to be optional, it should end with a
412- slot with the OPTIONAL flag.
413-
414395- ``PySlot_INTPTR ``: The data is stored in ``sl_ptr ``, and must be cast to
415396 the appropriate type.
416397
@@ -474,13 +455,8 @@ Each ``PyType_Slot`` in the array will be converted to
474455``(PySlot){.sl_id=slot, .sl_flags=PySlot_INTPTR, .sl_ptr=func} ``,
475456and similar with ``PyModuleDef_Slot ``.
476457
477- The initial implementation will have restrictions that may be lifted
478- in the future:
479-
480- - ``Py_slot_subslots ``, ``Py_tp_slots `` and ``Py_mod_slots `` cannot use
481- ``PySlot_HAS_FALLBACK `` (the flag cannot be set on them nor a slot that
482- precedes them).
483- - Nesting depth will be limited to 5 levels.
458+ In the initial implementation, nesting depth will be limited to 5 levels.
459+ This restrictions may be lifted in the future.
484460
485461
486462New slot IDs
@@ -492,8 +468,7 @@ definitions, will be added:
492468- ``Py_slot_end `` (defined as ``0 ``): Marks the end of a slots array.
493469
494470 - The ``PySlot_INTPTR `` and ``PySlot_STATIC `` flags are ignored.
495- - The ``PySlot_OPTIONAL `` and ``PySlot_HAS_FALLBACK `` flags are not
496- allowed with ``Py_slot_end ``.
471+ - The ``PySlot_OPTIONAL `` flags is not allowed with ``Py_slot_end ``.
497472
498473- ``Py_slot_subslots ``, ``Py_tp_slots ``, ``Py_mod_slots ``: see
499474 :ref: `pep820-nested-tables ` above
@@ -701,6 +676,25 @@ For a bigger picture: anonymous unions can be a helpful tool for implemeting
701676tagged unions and for evolving public API in backwards-compatible ways.
702677This PEP intentionally opens the door to using them more often.
703678
679+ Fallback slots
680+ --------------
681+
682+ An earlier version of this PEP proposed a flag: ``PySlot_HAS_FALLBACK ``:
683+
684+ If the flagged slot's ID is unknown, the interpreter will ignore the slot.
685+ If it's known, the interpreter should ignore subsequent slots up to
686+ (and including) the first one without HAS_FALLBACK.
687+
688+ Effectively, consecutive slots with the HAS_FALLBACK flag, plus the first
689+ non-HAS_FALLBACK slot after them, form a "block" where the the interpreter
690+ will only consider the *first * slot in the block that it understands.
691+ If the entire block is to be optional, it should end with a
692+ slot with the OPTIONAL flag.
693+
694+ This flag may be added later, in the Python version where it's needed.
695+ (For backwards compatibility, all slots flagged HAS_FALLBACK will also need
696+ the OPTIONAL flag).
697+
704698
705699Open Issues
706700===========
@@ -711,10 +705,35 @@ None yet.
711705Acknowledgements
712706================
713707
714- Thanks to Da Woods, Antoine Pitrou and Mark Shannon
708+ Thanks to Da Woods, Antoine Pitrou, Mark Shannon and Victor Stinner
715709for substantial input on this iteration of the proposal.
716710
717711
712+ Change History
713+ ==============
714+
715+ * `12-Mar-2026 <https://discuss.python.org/t/105552/12 >`__
716+ - Remove unnecessary flag ``PySlot_HAS_FALLBACK ``
717+
718+ * `28-Jan-2026 <https://discuss.python.org/t/105552/6 >`__
719+
720+ - Be clearer that the PEP 793 API added in 3.15 alpha (``PyModExport ``,
721+ ``PyModule_FromSlotsAndSpec ``) will be changed to return the new slots.
722+
723+ - Deprecation of things that were documented to not work, but
724+ worked in practice:
725+
726+ - setting a slot value to NULL (except if the slot explicitly allows this)
727+ - repeating a slot ID in a definition (except )
728+
729+ - Add "third-party slot ID allocation" and "avoiding anonymous unions"
730+ to Rejected Ideas.
731+
732+
733+ * `06-Jan-2025 <https://discuss.python.org/t/105552 >`__
734+ - Initial PEP
735+
736+
718737Copyright
719738=========
720739
0 commit comments