Skip to content

Commit 39d9e00

Browse files
authored
remove hints.AnnoField (#437)
1 parent 0cadf77 commit 39d9e00

File tree

6 files changed

+125
-166
lines changed

6 files changed

+125
-166
lines changed

comtypes/__init__.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,10 @@ class _cominterface_meta(type):
336336
"""
337337

338338
if TYPE_CHECKING:
339-
_case_insensitive_ = hints.AnnoField() # type: bool
340-
_iid_ = hints.AnnoField() # type: GUID
341-
_methods_ = hints.AnnoField() # type: List[_ComMemberSpec]
342-
_disp_methods_ = hints.AnnoField() # type: List[_DispMemberSpec]
339+
_case_insensitive_: bool
340+
_iid_: GUID
341+
_methods_: List[_ComMemberSpec]
342+
_disp_methods_: List[_DispMemberSpec]
343343

344344
# This flag is set to True by the atexit handler which calls
345345
# CoUninitialize.
@@ -862,9 +862,9 @@ class _IUnknown_Base(c_void_p):
862862
`builtins.object`.
863863
"""
864864

865-
__com_QueryInterface = hints.AnnoField() # type: Callable[[Any, Any], int]
866-
__com_AddRef = hints.AnnoField() # type: Callable[[], int]
867-
__com_Release = hints.AnnoField() # type: Callable[[], int]
865+
__com_QueryInterface: Callable[[Any, Any], int]
866+
__com_AddRef: Callable[[], int]
867+
__com_Release: Callable[[], int]
868868

869869
else:
870870
_IUnknown_Base = object
@@ -935,13 +935,13 @@ class IPersist(IUnknown):
935935
if TYPE_CHECKING:
936936
# Returns the CLSID that uniquely represents an object class that
937937
# defines the code that can manipulate the object's data.
938-
GetClassID = hints.AnnoField() # type: Callable[[], GUID]
938+
GetClassID: Callable[[], GUID]
939939

940940

941941
class IServiceProvider(IUnknown):
942942
_iid_ = GUID("{6D5140C1-7436-11CE-8034-00AA006009FA}")
943943
if TYPE_CHECKING:
944-
_QueryService = hints.AnnoField() # type: Callable[[Any, Any, Any], int]
944+
_QueryService: Callable[[Any, Any, Any], int]
945945
# Overridden QueryService to make it nicer to use (passing it an
946946
# interface and it returns a pointer to that interface)
947947
def QueryService(self, serviceIID, interface):
@@ -1072,9 +1072,9 @@ def GetActiveObject(clsid, interface=None):
10721072
class MULTI_QI(Structure):
10731073
_fields_ = [("pIID", POINTER(GUID)), ("pItf", POINTER(c_void_p)), ("hr", HRESULT)]
10741074
if TYPE_CHECKING:
1075-
pIID = hints.AnnoField() # type: GUID
1076-
pItf = hints.AnnoField() # type: _Pointer[c_void_p]
1077-
hr = hints.AnnoField() # type: HRESULT
1075+
pIID: GUID
1076+
pItf: _Pointer[c_void_p]
1077+
hr: HRESULT
10781078

10791079

10801080
class _COAUTHIDENTITY(Structure):
@@ -1115,10 +1115,10 @@ class _COSERVERINFO(Structure):
11151115
("dwReserved2", c_ulong),
11161116
]
11171117
if TYPE_CHECKING:
1118-
dwReserved1 = hints.AnnoField() # type: int
1119-
pwszName = hints.AnnoField() # type: Optional[str]
1120-
pAuthInfo = hints.AnnoField() # type: _COAUTHINFO
1121-
dwReserved2 = hints.AnnoField() # type: int
1118+
dwReserved1: int
1119+
pwszName: Optional[str]
1120+
pAuthInfo: _COAUTHINFO
1121+
dwReserved2: int
11221122

11231123

11241124
COSERVERINFO = _COSERVERINFO

comtypes/automation.py

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,11 @@ def as_decimal(self):
178178
# helper extension. At least the get/set methods.
179179
class tagVARIANT(Structure):
180180
if TYPE_CHECKING:
181-
vt = hints.AnnoField() # type: int
182-
_ = hints.AnnoField() # type: U_VARIANT1.__tagVARIANT.U_VARIANT2
183-
null = hints.AnnoField() # type: ClassVar[VARIANT]
184-
empty = hints.AnnoField() # type: ClassVar[VARIANT]
185-
missing = hints.AnnoField() # type: ClassVar[VARIANT]
181+
vt: int
182+
_: "U_VARIANT1.__tagVARIANT.U_VARIANT2"
183+
null: ClassVar["VARIANT"]
184+
empty: ClassVar["VARIANT"]
185+
missing: ClassVar["VARIANT"]
186186

187187
class U_VARIANT1(Union):
188188
class __tagVARIANT(Structure):
@@ -709,15 +709,15 @@ def Next(self, celt):
709709

710710
class tagEXCEPINFO(Structure):
711711
if TYPE_CHECKING:
712-
wCode = hints.AnnoField() # type: int
713-
wReserved = hints.AnnoField() # type: int
714-
bstrSource = hints.AnnoField() # type: str
715-
bstrDescription = hints.AnnoField() # type: str
716-
bstrHelpFile = hints.AnnoField() # type: str
717-
dwHelpContext = hints.AnnoField() # type: int
718-
pvReserved = hints.AnnoField() # type: Optional[int]
719-
pfnDeferredFillIn = hints.AnnoField() # type: Optional[int]
720-
scode = hints.AnnoField() # type: int
712+
wCode: int
713+
wReserved: int
714+
bstrSource: str
715+
bstrDescription: str
716+
bstrHelpFile: str
717+
dwHelpContext: int
718+
pvReserved: Optional[int]
719+
pfnDeferredFillIn: Optional[int]
720+
scode: int
721721

722722
def __repr__(self):
723723
return "<EXCEPINFO %s>" % (
@@ -750,10 +750,10 @@ def __repr__(self):
750750

751751
class tagDISPPARAMS(Structure):
752752
if TYPE_CHECKING:
753-
rgvarg = hints.AnnoField() # type: Array[VARIANT]
754-
rgdispidNamedArgs = hints.AnnoField() # type: _Pointer[DISPID]
755-
cArgs = hints.AnnoField() # type: int
756-
cNamedArgs = hints.AnnoField() # type: int
753+
rgvarg: Array[VARIANT]
754+
rgdispidNamedArgs: _Pointer[DISPID]
755+
cArgs: int
756+
cNamedArgs: int
757757
_fields_ = [
758758
# C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 696
759759
("rgvarg", POINTER(VARIANTARG)),
@@ -802,12 +802,10 @@ def __del__(self):
802802

803803
class IDispatch(IUnknown):
804804
if TYPE_CHECKING:
805-
_disp_methods_ = (
806-
hints.AnnoField()
807-
) # type: ClassVar[List[comtypes._DispMemberSpec]]
808-
_GetTypeInfo = hints.AnnoField() # type: Callable[[int, int], IUnknown]
809-
__com_GetIDsOfNames = hints.AnnoField() # type: RawGetIDsOfNamesFunc
810-
__com_Invoke = hints.AnnoField() # type: RawInvokeFunc
805+
_disp_methods_: ClassVar[List[comtypes._DispMemberSpec]]
806+
_GetTypeInfo: Callable[[int, int], IUnknown]
807+
__com_GetIDsOfNames: RawGetIDsOfNamesFunc
808+
__com_Invoke: RawInvokeFunc
811809

812810
_iid_ = GUID("{00020400-0000-0000-C000-000000000046}")
813811
_methods_ = [

comtypes/hints.pyi

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,4 @@
1-
from typing import (
2-
Any,
3-
Callable,
4-
Generic,
5-
NoReturn,
6-
Optional,
7-
overload,
8-
SupportsIndex,
9-
Type,
10-
TypeVar,
11-
Union as _UnionT,
12-
)
13-
141
# symbols those what might occur recursive imports in runtime.
152
from comtypes.automation import IDispatch as IDispatch, VARIANT as VARIANT
163
from comtypes.server import IClassFactory as IClassFactory
174
from comtypes.typeinfo import ITypeInfo as ITypeInfo
18-
19-
def AnnoField() -> Any:
20-
"""**THIS IS `TYPE_CHECKING` ONLY SYMBOL.
21-
22-
This is workaround for class field type annotations for old
23-
python versions.
24-
25-
Examples:
26-
# instead of class field annotation, like below
27-
28-
class Foo:
29-
# spam: int # <- not available in old versions.
30-
if TYPE_CHECKING:
31-
spam = AnnoField() # type: int # <- available in old versions.
32-
"""
33-
...

comtypes/tools/tlbparser.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
Union as _UnionT,
2121
)
2222
from ctypes import _CData, _Pointer
23-
from comtypes import hints
2423

2524

2625
# Is the process 64-bit?
@@ -124,8 +123,8 @@ def midlSAFEARRAY(typ):
124123

125124
class Parser(object):
126125
if TYPE_CHECKING:
127-
tlib = hints.AnnoField() # type: typeinfo.ITypeLib
128-
items = hints.AnnoField() # type: Dict[str, Any]
126+
tlib: typeinfo.ITypeLib
127+
items: Dict[str, Any]
129128

130129
def make_type(self, tdesc, tinfo):
131130
# type: (typeinfo.TYPEDESC, typeinfo.ITypeInfo) -> Any

comtypes/tools/typedesc_base.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,13 @@ def __init__(self, struct):
164164

165165
class _Struct_Union_Base(object):
166166
if TYPE_CHECKING:
167-
name = comtypes.hints.AnnoField() # type: str
168-
align = comtypes.hints.AnnoField() # type: int
169-
members = (
170-
comtypes.hints.AnnoField()
171-
) # type: List[_UnionT[Field, Method, Constructor]]
172-
bases = comtypes.hints.AnnoField() # type: List[_Struct_Union_Base]
173-
artificial = comtypes.hints.AnnoField() # type: Optional[Any]
174-
size = comtypes.hints.AnnoField() # type: Optional[int]
175-
_recordinfo_ = (
176-
comtypes.hints.AnnoField()
177-
) # type: Tuple[str, int, int, int, str]
167+
name: str
168+
align: int
169+
members: List[_UnionT["Field", Method, Constructor]]
170+
bases: List["_Struct_Union_Base"]
171+
artificial: Optional[Any]
172+
size: Optional[int]
173+
_recordinfo_: Tuple[str, int, int, int, str]
178174

179175
location = None
180176

0 commit comments

Comments
 (0)