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/G → Zf/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:
to:
Therefore the corresponding field in comtypes.util._calc_offset.<locals>.PyCArgObject should change from:
to:
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:
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:
tag → c_char_p
size → c_ssize_t
Summary
comtypes.util._calc_offset.<locals>.PyCArgObjectmirrors CPython's internal_ctypes.PyCArgObjectstructure. 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:
ctypes.hctypes.hctypes.hThe Python 3.15 change that affects
comtypesis NOT related to the_type_code changes (F/D/G→Zf/Zd/Zg) (Related issue: python/cpython#148675).Instead, the compatibility issue comes from changes in the internal
PyCArgObjectstructure itself.Required changes
1.
tagCPython changed:
to:
Therefore the corresponding field in
comtypes.util._calc_offset.<locals>.PyCArgObjectshould change from:to:
for Python 3.15+.
2.
sizeThe structure contains:
The current our definition uses
c_int, but the actual CPython type isPy_ssize_t.Therefore the field should be updated to:
for Python 3.15+.
Proposed implementation
Maintain backward compatibility with a version bridge:
so that:
Acceptance criteria
PyCArgObjectdefinition 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:
tag→c_char_psize→c_ssize_t