|
3 | 3 |
|
4 | 4 | import atexit
|
5 | 5 | from ctypes import *
|
6 |
| -from ctypes import _SimpleCData |
| 6 | +from ctypes import _Pointer, _SimpleCData |
7 | 7 |
|
8 | 8 | try:
|
9 | 9 | from _ctypes import COMError
|
|
22 | 22 | import sys
|
23 | 23 | import types
|
24 | 24 |
|
| 25 | +# fmt: off |
| 26 | +from typing import ( |
| 27 | + Any, ClassVar, overload, TYPE_CHECKING, TypeVar, |
| 28 | + # instead of `builtins`. see PEP585 |
| 29 | + Dict, List, Tuple, Type, |
| 30 | + # instead of `collections.abc`. see PEP585 |
| 31 | + Callable, Iterable, Iterator, |
| 32 | + # instead of `A | B` and `None | A`. see PEP604 |
| 33 | + Optional, Union as _UnionT, # avoiding confusion with `ctypes.Union` |
| 34 | +) |
| 35 | +# fmt: on |
| 36 | +if TYPE_CHECKING: |
| 37 | + from ctypes import _CData # only in `typeshed`, private in runtime |
| 38 | + from comtypes import hints as hints # type: ignore |
| 39 | +else: |
| 40 | + _CData = _SimpleCData.__mro__[:-1][-1] |
| 41 | + |
| 42 | +from comtypes.GUID import GUID |
| 43 | +from comtypes import patcher |
| 44 | +from comtypes._npsupport import interop as npsupport |
| 45 | +from comtypes._memberspec import ( |
| 46 | + ComMemberGenerator, |
| 47 | + _ComMemberSpec, |
| 48 | + DispMemberGenerator, |
| 49 | + _DispMemberSpec, |
| 50 | + _encode_idl, |
| 51 | + _resolve_argspec, |
| 52 | +) |
| 53 | + |
| 54 | + |
25 | 55 | ################################################################
|
26 | 56 |
|
27 | 57 | # fmt: off
|
@@ -63,59 +93,6 @@ def wrapper(cls):
|
63 | 93 | return wrapper
|
64 | 94 | # fmt: on
|
65 | 95 |
|
66 |
| -################################################################ |
67 |
| - |
68 |
| -# type hinting symbols |
69 |
| -# |
70 |
| -# `if TYPE_CHECKING:` code block must not be executed because `TYPE_CHECKING` |
71 |
| -# is always `False` in runtime. |
72 |
| -# see https://peps.python.org/pep-0484/#runtime-or-type-checking |
73 |
| -# |
74 |
| -if sys.version_info >= (3, 5): |
75 |
| - from typing import TYPE_CHECKING |
76 |
| -else: # typehints in this package don't support Py<3.5 due to importing symbols. |
77 |
| - TYPE_CHECKING = False |
78 |
| -# |
79 |
| -# Annotations must be placed in a `# type:` comment in according to PEP484. |
80 |
| -# see https://peps.python.org/pep-0484/#suggested-syntax-for-python-2-7-and-straddling-code |
81 |
| -# - `NameError` never raises by using those symbols. |
82 |
| -# - It is not able to use any runtime introspections, such as |
83 |
| -# `typing.get_type_hints` or `typing.get_origin`. |
84 |
| -# |
85 |
| -if TYPE_CHECKING: |
86 |
| - from ctypes import _CData # only in `typeshed`, private in runtime |
87 |
| - |
88 |
| - # _CData = _SimpleCData.__mro__[:-1][-1] # defining in runtime |
89 |
| - from ctypes import _Pointer |
90 |
| - from typing import Any, ClassVar, overload, TypeVar |
91 |
| - |
92 |
| - # XXX: symbols for backward compatibility. |
93 |
| - # instead of `builtins`. see PEP585. |
94 |
| - from typing import Dict, List, Tuple, Type |
95 |
| - |
96 |
| - # instead of `collections.abc`. see PEP585. |
97 |
| - from typing import Callable, Iterable, Iterator |
98 |
| - |
99 |
| - # instead of `A | B` and `None | A`. see PEP604. |
100 |
| - from typing import Union as _UnionT # avoiding confusion with `ctypes.Union` |
101 |
| - from typing import Optional |
102 |
| - |
103 |
| - # utilities or workarounds for annotations. |
104 |
| - from comtypes import hints as hints |
105 |
| - |
106 |
| -################################################################ |
107 |
| - |
108 |
| -from comtypes.GUID import GUID |
109 |
| -from comtypes import patcher |
110 |
| -from comtypes._npsupport import interop as npsupport |
111 |
| -from comtypes._memberspec import ( |
112 |
| - ComMemberGenerator, |
113 |
| - _ComMemberSpec, |
114 |
| - DispMemberGenerator, |
115 |
| - _DispMemberSpec, |
116 |
| - _encode_idl, |
117 |
| - _resolve_argspec, |
118 |
| -) |
119 | 96 |
|
120 | 97 | ################################################################
|
121 | 98 | if sys.version_info >= (3, 0):
|
@@ -849,8 +826,9 @@ def COMMETHOD(idlflags, restype, methodname, *argspec):
|
849 | 826 | ################################################################
|
850 | 827 | # IUnknown, the root of all evil...
|
851 | 828 |
|
| 829 | +_T_IUnknown = TypeVar("_T_IUnknown", bound="IUnknown") |
| 830 | + |
852 | 831 | if TYPE_CHECKING:
|
853 |
| - _T_IUnknown = TypeVar("_T_IUnknown", bound="IUnknown") |
854 | 832 |
|
855 | 833 | class _IUnknown_Base(c_void_p):
|
856 | 834 | """This is workaround to avoid false-positive of static type checking.
|
|
0 commit comments