Title: Breaking backward compatibility between `ctypes` and metaclasses in Python 3.13. · Issue #124520 · python/cpython · GitHub
Open Graph Title: Breaking backward compatibility between `ctypes` and metaclasses in Python 3.13. · Issue #124520 · python/cpython
X Title: Breaking backward compatibility between `ctypes` and metaclasses in Python 3.13. · Issue #124520 · python/cpython
Description: Documentation Background I am one of the maintainers of comtypes. comtypes is based on ctypes and uses metaclasses to implement IUnknown. It was reported to the comtypes community that an error occurs when attempting to use conventional ...
Open Graph Description: Documentation Background I am one of the maintainers of comtypes. comtypes is based on ctypes and uses metaclasses to implement IUnknown. It was reported to the comtypes community that an error occ...
X Description: Documentation Background I am one of the maintainers of comtypes. comtypes is based on ctypes and uses metaclasses to implement IUnknown. It was reported to the comtypes community that an error occ...
Opengraph URL: https://github.com/python/cpython/issues/124520
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Breaking backward compatibility between `ctypes` and metaclasses in Python 3.13.","articleBody":"# Documentation\r\n\r\n\r\n## Background\r\nI am one of the maintainers of [`comtypes`](https://github.com/enthought/comtypes/). `comtypes` is based on `ctypes` and uses metaclasses to implement [`IUnknown`](https://learn.microsoft.com/en-us/windows/win32/api/unknwn/nn-unknwn-iunknown).\r\n\r\nIt was reported to the `comtypes` community that [an error occurs when attempting to use conventional metaclasses with Python 3.13](https://github.com/enthought/comtypes/issues/618#issuecomment-2366905288).\r\n\r\nA similar error was encountered in [`pyglet`](https://github.com/pyglet/pyglet), which also uses metaclasses to implement COM interfaces, when running on Python 3.13.\r\n\r\nBy referring to https://github.com/pyglet/pyglet/issues/1196 and https://github.com/pyglet/pyglet/pull/1199, I made several modifications to the code through trial and error, and now `comtypes` works in both Python 3.13 and earlier versions without problems:\r\n- https://github.com/enthought/comtypes/compare/a3a8733..04b766a\r\n - It is necessary to pass arguments directly to the metaclass instead of using `__new__` in places where the metaclass is instantiated (i.e., where the class is dynamically defined). This also works in versions prior to Python 3.13.\r\n - After calling `type.__new__`, any remaining initialization would be handled in `__init__` instead of in `__new__`. Since this results in an error in versions prior to Python 3.13, a bridge using `sys.version_info` is necessary.\r\n\r\nI think these changes are likely related to https://github.com/python/cpython/issues/114314 and https://github.com/python/cpython/issues/117142 and were introduced by the PRs linked to those issues.\r\n\r\nSince this change to `ctypes` breaks compatibility, I think it should be mentioned in the [What’s New In Python 3.13](https://docs.python.org/3.13/whatsnew/3.13.html) and/or in the [`ctypes` documentation](https://docs.python.org/3.13/library/ctypes.html).\r\nThere are likely other projects besides `comtypes` and `pyglet` that rely on the combination of `ctypes` and metaclasses, and I want to prevent confusion for those maintainers when they try to support Python 3.13.\r\n\r\n(Additionally, I would like to ask with the `ctypes` maintainers to confirm whether the changes for the metaclasses in `comtypes` (and `pyglet`) are appropriate.)\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-124546\n* gh-124708\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/junkmd","@type":"Person","name":"junkmd"},"datePublished":"2024-09-25T15:14:59.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":19},"url":"https://github.com/124520/cpython/issues/124520"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:19ccf05e-5d51-be49-0125-e2cafaec1d1b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8144:2786B7:1CEA84:26913E:6969CA3D |
| html-safe-nonce | 8163cce469336c9dc24c77189c00c02c1879bea8c2a18e55bc18e2f6fb5a7dd6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MTQ0OjI3ODZCNzoxQ0VBODQ6MjY5MTNFOjY5NjlDQTNEIiwidmlzaXRvcl9pZCI6IjU0MjUzMTY3NDc3ODAxNDc3NzMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e01adec055d43672a599a6afc27a54b01f68a4b0a38e9f3adb5bea4f862bb839 |
| hovercard-subject-tag | issue:2548280606 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/124520/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8bf6473ef821e4459925123cbb700ad09d1e1c8f650d48eab68c9810234bf35f/python/cpython/issues/124520 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8bf6473ef821e4459925123cbb700ad09d1e1c8f650d48eab68c9810234bf35f/python/cpython/issues/124520 |
| og:image:alt | Documentation Background I am one of the maintainers of comtypes. comtypes is based on ctypes and uses metaclasses to implement IUnknown. It was reported to the comtypes community that an error occ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | junkmd |
| hostname | github.com |
| expected-hostname | github.com |
| None | acedec8b5f975d9e3d494ddd8f949b0b8a0de59d393901e26f73df9dcba80056 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 83c08c21cdda978090dc44364b71aa5bc6dcea79 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width