Skip to content

[C API] How many slots of static types should be exposed in PyType_GetSlot() #85784

Closed as not planned

Description

@shihai1991
BPO 41618
Nosy @vstinner, @encukou, @shihai1991

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2020-08-23.08:48:18.095>
labels = ['expert-C-API', 'type-feature', '3.10']
title = '[C API] How many slots of static types should be exposed in PyType_GetSlot()'
updated_at = <Date 2021-01-16.05:36:16.127>
user = 'https://github.com/shihai1991'

bugs.python.org fields:

activity = <Date 2021-01-16.05:36:16.127>
actor = 'shihai1991'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['C API']
creation = <Date 2020-08-23.08:48:18.095>
creator = 'shihai1991'
dependencies = []
files = []
hgrepos = []
issue_num = 41618
keywords = []
message_count = 10.0
messages = ['375808', '375809', '376568', '379110', '379948', '380303', '380414', '380510', '383973', '385135']
nosy_count = 3.0
nosy_names = ['vstinner', 'petr.viktorin', 'shihai1991']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue41618'
versions = ['Python 3.10']

Activity

  1. shihai1991 commented on Aug 23, 2020

    @shihai1991
    MemberAuthor

    In order to resolve bpo-41073, we want to extend PyType_GetSlot() to accept static types. But there have another question we should be considered: How many slots should be exposed in PyType_GetSlot().

    petr's opinion from PR-21931:I would not want to expose the Py_tp_as_* slots at all; their contents are covered in other slots that should be used instead. And slots like Py_tp_version_tag are specific to CPython; I don't think they should be exposed in the general C API.

  2. added
    3.10 (EOL)
    type-feature
    on Aug 23, 2020
  3. shihai1991 commented on Aug 23, 2020

    @shihai1991
    MemberAuthor

    related bpo: bpo-41073

  4. encukou commented on Sep 8, 2020

    @encukou
    Member

    IMO, a slot should be exposed if there is some reason for exposing it.

    bpo-41073 talks about tp_dealloc, which is already exposed as Py_tp_dealloc.
    Recently, Py_bf_* slots were exposed (but not as part of the limited API), in bpo-40724 which links to the reasons for exposing them.

    Which other slots are we missing?

  5. encukou commented on Oct 20, 2020

    @encukou
    Member

    Also: PyType_GetSlot should return a function pointer, not data.

    For some slots (Py_tp_doc, Py_tp_methods, Py_tp_members, Py_tp_getset) that ship has sailed, but for new ones, we should honor the distinction between data and function pointers. The C standard says they're distinct, so it might bite us in the future (e.g. compiling to WebAssembly).

  6. shihai1991 commented on Oct 30, 2020

    @shihai1991
    MemberAuthor

    IMO, a slot should be exposed if there is some reason for exposing it.

    Can we write those info to docs? In case some developer want to exposing slot in future.

    Which other slots are we missing?

    nb_inserved in PyNumberMethods should be removed?

  7. encukou commented on Nov 3, 2020

    @encukou
    Member

    Can we write those info to docs? In case some developer want to exposing slot in future.

    Do you mean something like "only expose a slot if you have a reason for exposing it"? That sounds like a tautology.
    Where in the docs would this go?

    nb_inserved in PyNumberMethods should be removed?

    You mean nb_reserved, right?
    It can't be removed; old-style initialization is positional.
    But it could be replaced according to PEP-387:

    • in 3.x, raise a warning if it is not set to NULL (in static types)
    • in 3.x+2, throw an error if it is not set to NULL (in static types)
    • in 3.x+3 or later, it can be replaced by another slot, if there's something we need to add to PyNumberMethods
  8. encukou commented on Nov 5, 2020

    @encukou
    Member

    My views on individual slots:

    Not a function, shouldn't be used with PyType_Slot:

    • tp_dict - I'd add a PyType_GetDict if there is a need to get this
    • tp_mro - I'd add a PyType_GetMRO if there is a need to get this
      (There are existing slots that aren't functions; I'd like to deprecate them in the long term.)

    internal use only, do not expose:

    • tp_cache
    • tp_subclasses
    • tp_weaklist
    • tp_as_*

    Not part of limited API, do not expose:

    • tp_vectorcall

    Can be exposed if we deem all of the related API stable:

    • bf_getbuffer
    • bf_releasebuffer
  9. shihai1991 commented on Nov 7, 2020

    @shihai1991
    MemberAuthor

    Do you mean something like "only expose a slot if you have a reason for > exposing it"? That sounds like a tautology.
    Where in the docs would this go?

    Add a friend Note in docs of PyType_GetSlot MAYBE?

    You mean nb_reserved, right?
    Yes, thanks for your description.

  10. encukou commented on Dec 29, 2020

    @encukou
    Member

    Documentation for developers *of* CPython should generally go in the dev guide, a comment in the code, or in issues like this.

  11. shihai1991 commented on Jan 16, 2021

    @shihai1991
    MemberAuthor

    Not a function, shouldn't be used with PyType_Slot:

    • tp_dict - I'd add a PyType_GetDict if there is a need to get this
    • tp_mro - I'd add a PyType_GetMRO if there is a need to get this

    I checked some other projects which use type fileds directly.
    cpython doesn't expose the tp_dict and tp_mro directly in headers.
    I am not sure which way is more better(calling function vs using fileld directly).

    refs:
    https://gitlab.gnome.org/GNOME/pygobject/-/blob/master/gi/gimodule.c#L1168
    https://github.com/biolab/orange2/blob/db40a9449cb45b507d63dcd5739b223f9cffb8e6/source/orange/cls_orange.cpp#L587

  12. transferred this issue fromon Apr 10, 2022
  13. vstinner commented on Jan 28, 2025

    @vstinner
    Member

    At the end, nothing has to be done, and I just close the issue.

    In the meanwhile (in 2020), PyType_GetSlot() was modified to accept static types: a13b26c.

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

    topic-C-APItype-feature

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions