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

Replace ctypes.DllGetClassObject and remove DllCanUnloadNow #127369

Open
@encukou

Description

@encukou

As far as I can tell, these functions are hooks: third-party code is meant to replace them.

Their implementation inctypes (i.e. their default behaviour) is to import and call the same-named functions from a third-party library,comtypes.server.inprocserver. This is not good.comtypes should instead register their hook on import.

Here's a possible plan to make the API boundary better without breaking users.

DllCanUnloadNow

While the Python interpreter is running, it is not safe to unload the shared library that contains_ctypes. Therefore:

  • The C functionDllCanUnloadNow exported from _ctypes should be changed to always returnS_FALSE. We should change that now, without a deprecation period. (Note thatthecomtypes hook already does this.)
  • We should stop importing and callingcomtypes.server.inprocserver. I'm not sure about the necessary deprecation period, but I think that it should be a non-breaking change and can also be done immediately. Or is someone relying on it for side effects? O_o
  • Setting and getting the hook should be deprecated. In about Python 3.18 we should stop calling it, and remove it.

DllGetClassObject

This one, on the other hand, sounds like a useful hook. It also looks like an inprocess COM server need a special build so it's not useful to allow multiple hooks -- replacing a global one is enough. Is that so?
If yes:

  • ctypes.DllGetClassObject (the default implementation) should raise aDeprecationWarning. In about Python 3.18, it should be changed to do nothing, just, returnCLASS_E_CLASSNOTAVAILABLE.
  • comtypes should be changed: on import, it should replacectypes.DllGetClassObject with its own hook.

This should ensure thatold versions ofcomtypes still work as before (until after the deprecation period).

Does that sound reasonable?
cc@junkmd

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp