Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add _post_coinit subpackage #571

Merged
merged 5 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions comtypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
from comtypes import patcher # noqa
from comtypes._npsupport import interop as npsupport # noqa
from comtypes._tlib_version_checker import _check_version # noqa
from comtypes._bstr import BSTR # noqa
from comtypes._py_instance_method import instancemethod # noqa
from comtypes._idl_stuff import defaultvalue, helpstring, dispid # noqa
from comtypes._idl_stuff import STDMETHOD, DISPMETHOD, DISPPROPERTY, COMMETHOD # noqa
Expand Down Expand Up @@ -175,21 +174,26 @@ def CoUninitialize():

################################################################
# IUnknown, the root of all evil...
from comtypes.unknwn import IUnknown, _shutdown # noqa
from comtypes._post_coinit import _shutdown
from comtypes._post_coinit.unknwn import IUnknown # noqa

atexit.register(_shutdown)

################################################################

from comtypes._post_coinit.bstr import BSTR # noqa


################################################################
# IPersist is a trivial interface, which allows to ask an object about
# its clsid.
from comtypes._base import IPersist, IServiceProvider # noqa
from comtypes._post_coinit.misc import IPersist, IServiceProvider # noqa


################################################################


from comtypes._base import ( # noqa
from comtypes._post_coinit.misc import ( # noqa
_is_object,
CoGetObject,
CoCreateInstance,
Expand Down
15 changes: 15 additions & 0 deletions comtypes/_post_coinit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""comtypes._post_coinit

This subpackage contains symbols that should be imported into `comtypes/__init__.py`
after `CoInitializeEx` is defined and called, and symbols that can be defined in
any order during the initialization of the `comtypes` package.

These were previously defined in `comtypes/__init__.py`, but due to the codebase
of the file becoming bloated, reducing the ease of changes and increasing
cognitive load, they have been moved here.

This subpackage is called simultaneously with the initialization of `comtypes`.
So it is necessary to maintain minimal settings to keep the lightweight action
when the package is initialized.
"""
from comtypes._post_coinit.unknwn import _shutdown # noqa
File renamed without changes.
2 changes: 1 addition & 1 deletion comtypes/_base.py → comtypes/_post_coinit/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from comtypes._idl_stuff import COMMETHOD # noqa
from comtypes import CLSCTX_SERVER, CLSCTX_LOCAL_SERVER, CLSCTX_REMOTE_SERVER
from comtypes import _ole32, oledll, DWORD
from comtypes import IUnknown
from comtypes._post_coinit.unknwn import IUnknown


def _is_object(obj):
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ python_requires = >=3.7

packages =
comtypes
comtypes._post_coinit
comtypes.client
comtypes.server
comtypes.tools
Expand Down