Skip to content

Support Python 3.15 PyCArgObject layout changes in comtypes.util #938

Description

@junkmd

Summary

comtypes.util._calc_offset.<locals>.PyCArgObject mirrors CPython's internal _ctypes.PyCArgObject structure. CPython 3.15 changes the layout of this internal structure, so we needs to update its definition accordingly.

This is similar to the work previously done for Python 3.14 compatibility in #839

Background

The relevant CPython definitions are:

The Python 3.15 change that affects comtypes is NOT related to the _type_ code changes (F/D/GZf/Zd/Zg) (Related issue: python/cpython#148675).

Instead, the compatibility issue comes from changes in the internal PyCArgObject structure itself.

Required changes

1. tag

CPython changed:

char tag;

to:

const char *tag;

Therefore the corresponding field in comtypes.util._calc_offset.<locals>.PyCArgObject should change from:

("tag", c_char)

to:

("tag", c_char_p)

for Python 3.15+.

2. size

The structure contains:

Py_ssize_t size; /* for the "V" tag */

The current our definition uses c_int, but the actual CPython type is Py_ssize_t.

Therefore the field should be updated to:

("size", c_ssize_t)

for Python 3.15+.

Proposed implementation

Maintain backward compatibility with a version bridge:

if sys.version_info >= (3, 15):
    ...
else:
    ...

so that:

  • Python 3.13 and 3.14 continue using the existing layout.
  • Python 3.15+ uses the updated layout matching CPython.

Acceptance criteria

  • PyCArgObject definition matches CPython 3.15.

  • Existing Python 3.13 and 3.14 support remains unchanged.

  • CI passes on supported Python versions.

  • New tests verify the expected field types:

    • tagc_char_p
    • sizec_ssize_t

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions