Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Breaking backward compatibility betweenctypes and metaclasses in Python 3.13. #124520

Closed
Labels
3.13bugs and security fixesdocsDocumentation in the Doc dirtopic-ctypes
@junkmd

Description

@junkmd

Documentation

Background

I am one of the maintainers ofcomtypes.comtypes is based onctypes and uses metaclasses to implementIUnknown.

It was reported to thecomtypes community thatan error occurs when attempting to use conventional metaclasses with Python 3.13.

A similar error was encountered inpyglet, which also uses metaclasses to implement COM interfaces, when running on Python 3.13.

By referring topyglet/pyglet#1196 andpyglet/pyglet#1199, I made several modifications to the code through trial and error, and nowcomtypes works in both Python 3.13 and earlier versions without problems:

  • https://github.com/enthought/comtypes/compare/a3a8733..04b766a
    • 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.
    • After callingtype.__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 usingsys.version_info is necessary.

I think these changes are likely related to#114314 and#117142 and were introduced by the PRs linked to those issues.

Since this change toctypes breaks compatibility, I think it should be mentioned in theWhat’s New In Python 3.13 and/or in thectypes documentation.
There are likely other projects besidescomtypes andpyglet that rely on the combination ofctypes and metaclasses, and I want to prevent confusion for those maintainers when they try to support Python 3.13.

(Additionally, I would like to ask with thectypes maintainers to confirm whether the changes for the metaclasses incomtypes (andpyglet) are appropriate.)

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixesdocsDocumentation in the Doc dirtopic-ctypes

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp