comtypes icon indicating copy to clipboard operation
comtypes copied to clipboard

Supporting Python 3.14

Open junkmd opened this issue 11 months ago • 2 comments

Hello, comtypesers,

Python 3.14 beta 1 is scheduled for release on May 6, 2025. We recognize that it's time to begin preparations to ensure that comtypes continues to function reliably both on this upcoming version and on all currently supported versions (up to 3.13).

As many of you know, comtypes heavily depends on Python’s foreign function interface library, ctypes. One major upcoming change in Python 3.14 is an internal update to the ctypes.POINTER() caching mechanism (cpython/issues/100926, cpython/pull/131282, ctypes._CData.__pointer_type__ documentation).

This change is not immediately backward-incompatible in Python 3.14. The old pointer caching mechanism will be deprecated and will issue a DeprecationWarning, but it remains functional in 3.14. However, as shown below, this mechanism is scheduled for removal in Python 3.19.

PS current\dir> ...\cpython\PCbuild\amd64\python.exe -m unittest discover -v -s ./comtypes/test -t comtypes\test
...
...\comtypes\_post_coinit\unknwn.py:131: DeprecationWarning: 'ctypes._pointer_type_cache' is deprecated and slated for removal in Python 3.19
  _pointer_type_cache[self] = p

This removal will prevent comtypes from working correctly unless its production codebase is modified.

To mitigate the impact of this change, I’ve been working closely with CPython contributors, engaging in discussions on the related issue and pull request. As a result, I now have a clear technical strategy for updating comtypes to remain compatible with Python 3.14 (cpython PR comment). Moreover, the proposed fix has been reviewed by CPython contributors and confirmed to be consistent with the direction of ctypes design and implementation (cpython PR comment).

Once Python 3.14 beta 1 is out, and after we've made a revision release of comtypes, I plan to merge the necessary compatibility changes into the main branch. I might start by opening a draft PR.

Here’s how the community can help: we would greatly appreciate it if you could test the "supporting python 3.14" branch in your environment. If you encounter any issues—such as errors or unexpected behavior—please report them along with detailed reproduction steps and any error messages you receive. This information will be invaluable in helping us investigate and fix any problems.

Your feedback, whether it's suggestions or test results, is always welcome. Community contributions are vital to ensuring comtypes remains stable and compatible with the latest Python versions.

Thank you!

junkmd avatar May 03 '25 03:05 junkmd

The beta is now available: https://www.python.org/downloads/release/python-3140b1/

moi15moi avatar May 07 '25 19:05 moi15moi

I opened #839 as a draft.

For comtypes users with the necessary resources, please help verify the branch.

junkmd avatar May 14 '25 23:05 junkmd

After merging #865, I noticed that util doesn't work with Python 3.14.

This has been reported to CPython: https://github.com/python/cpython/issues/136847

junkmd avatar Jul 20 '25 02:07 junkmd