enthought / comtypes

A pure Python, lightweight COM client and server framework, based on the ctypes Python FFI package.
Other
283 stars 96 forks source link

Split `IUnknown` definition from `__init__.py` #562

Closed junkmd closed 4 weeks ago

junkmd commented 4 weeks ago

The reason is same as #559,

The __init__.py of this package is very large. I think this is a barrier for newcomers to the community trying to understand this package.

Considering that the responsibility of __init__.py is to "handle the initialization of the package", calling CoInitializeEx is indeed initialization, so it is necessary in __init__.py.

However, for example, if we define things like the BSTR in other private modules and import it into __init__.py (such as current GUID module), __init__.py will become lightweight.

The metaclasses and _shutdown are strongly tied to the implementation of IUnknown, so they are also being moved to a new module.

The registration to com_interface_registry by the metaclass and the hook of CoUninitialize by _shutdown have been confirmed by tests to not break even when the codebase is moved to a different file.

The following will be done in the same way as #559.

In order to keep the change history even if we squash & merge, I will divide it into several PRs.