✕
Skip to content

[C API] Change PyTypeObject.tp_flags type to uint64_t #161562

Open

Description

@vstinner

Feature or enhancement

Currently, PyTypeObject.tp_flags type is unsigned long which is 32-bit on Windows and 32-bit platforms. There are less and less available type flags: https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_flags.

I propose extending PyTypeObject.tp_flags to uint64_t to get 32 additional flags.

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

The issue was discussed at We’re out of type flags, let’s add new API for new ones.

Linked PRs

Activity

  1. self-assigned this
    on Nov 7, 2026
  2. added 2 commits that reference this issue on Nov 7, 2026
  3. ronaldoussoren commented on Nov 8, 2026

    @ronaldoussoren
    Contributor

    Isn't this a duplicate for #134860?

    As mentioned in that issue: Flags are also an unsigned int in PyType_Spec, which is part of the stable ABI. See https://docs.python.org/3/c-api/type.html#c.PyType_Spec.flags

    Likewise for PyType_GetFlags where the return value is an unsigned long (32-bit on 32-bit platforms, and on 64-bit windows)

  4. vstinner commented on Nov 8, 2026

    @vstinner
    MemberAuthor

    Isn't this a duplicate for #134860?

    Oh, I wasn't aware of this issue. Well, this issue is a concrete change to implement the "Change PyTypeObject.tp_flags type to uint64_t" option.

    As mentioned in that issue: Flags are also an unsigned int in PyType_Spec, which is part of the stable ABI. See https://docs.python.org/3/c-api/type.html#c.PyType_Spec.flags

    The updated PyType_Spec documentation in the PR suggest using PyType_FromSlots() if you need 64-bit flags. If you don't need new 64-bit flags, it's fine to still use PyType_Spec().

    Likewise for PyType_GetFlags where the return value is an unsigned long (32-bit on 32-bit platforms, and on 64-bit windows)

    With my change, PyType_GetFlags() return type changes to uint64_t when using non-limited C API or when using the limited C API version 3.16 or newer. It stays as unsigned long when using the limited C API version 3.15 or newer (stable ABI!). See the PR for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions