Skip to content

Commit

Permalink
remove hints.AnnoField (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
junkmd authored Dec 31, 2022
1 parent 0cadf77 commit 39d9e00
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 166 deletions.
32 changes: 16 additions & 16 deletions comtypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,10 @@ class _cominterface_meta(type):
"""

if TYPE_CHECKING:
_case_insensitive_ = hints.AnnoField() # type: bool
_iid_ = hints.AnnoField() # type: GUID
_methods_ = hints.AnnoField() # type: List[_ComMemberSpec]
_disp_methods_ = hints.AnnoField() # type: List[_DispMemberSpec]
_case_insensitive_: bool
_iid_: GUID
_methods_: List[_ComMemberSpec]
_disp_methods_: List[_DispMemberSpec]

# This flag is set to True by the atexit handler which calls
# CoUninitialize.
Expand Down Expand Up @@ -862,9 +862,9 @@ class _IUnknown_Base(c_void_p):
`builtins.object`.
"""

__com_QueryInterface = hints.AnnoField() # type: Callable[[Any, Any], int]
__com_AddRef = hints.AnnoField() # type: Callable[[], int]
__com_Release = hints.AnnoField() # type: Callable[[], int]
__com_QueryInterface: Callable[[Any, Any], int]
__com_AddRef: Callable[[], int]
__com_Release: Callable[[], int]

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


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


class _COAUTHIDENTITY(Structure):
Expand Down Expand Up @@ -1115,10 +1115,10 @@ class _COSERVERINFO(Structure):
("dwReserved2", c_ulong),
]
if TYPE_CHECKING:
dwReserved1 = hints.AnnoField() # type: int
pwszName = hints.AnnoField() # type: Optional[str]
pAuthInfo = hints.AnnoField() # type: _COAUTHINFO
dwReserved2 = hints.AnnoField() # type: int
dwReserved1: int
pwszName: Optional[str]
pAuthInfo: _COAUTHINFO
dwReserved2: int


COSERVERINFO = _COSERVERINFO
Expand Down
46 changes: 22 additions & 24 deletions comtypes/automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ def as_decimal(self):
# helper extension. At least the get/set methods.
class tagVARIANT(Structure):
if TYPE_CHECKING:
vt = hints.AnnoField() # type: int
_ = hints.AnnoField() # type: U_VARIANT1.__tagVARIANT.U_VARIANT2
null = hints.AnnoField() # type: ClassVar[VARIANT]
empty = hints.AnnoField() # type: ClassVar[VARIANT]
missing = hints.AnnoField() # type: ClassVar[VARIANT]
vt: int
_: "U_VARIANT1.__tagVARIANT.U_VARIANT2"
null: ClassVar["VARIANT"]
empty: ClassVar["VARIANT"]
missing: ClassVar["VARIANT"]

class U_VARIANT1(Union):
class __tagVARIANT(Structure):
Expand Down Expand Up @@ -709,15 +709,15 @@ def Next(self, celt):

class tagEXCEPINFO(Structure):
if TYPE_CHECKING:
wCode = hints.AnnoField() # type: int
wReserved = hints.AnnoField() # type: int
bstrSource = hints.AnnoField() # type: str
bstrDescription = hints.AnnoField() # type: str
bstrHelpFile = hints.AnnoField() # type: str
dwHelpContext = hints.AnnoField() # type: int
pvReserved = hints.AnnoField() # type: Optional[int]
pfnDeferredFillIn = hints.AnnoField() # type: Optional[int]
scode = hints.AnnoField() # type: int
wCode: int
wReserved: int
bstrSource: str
bstrDescription: str
bstrHelpFile: str
dwHelpContext: int
pvReserved: Optional[int]
pfnDeferredFillIn: Optional[int]
scode: int

def __repr__(self):
return "<EXCEPINFO %s>" % (
Expand Down Expand Up @@ -750,10 +750,10 @@ def __repr__(self):

class tagDISPPARAMS(Structure):
if TYPE_CHECKING:
rgvarg = hints.AnnoField() # type: Array[VARIANT]
rgdispidNamedArgs = hints.AnnoField() # type: _Pointer[DISPID]
cArgs = hints.AnnoField() # type: int
cNamedArgs = hints.AnnoField() # type: int
rgvarg: Array[VARIANT]
rgdispidNamedArgs: _Pointer[DISPID]
cArgs: int
cNamedArgs: int
_fields_ = [
# C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 696
("rgvarg", POINTER(VARIANTARG)),
Expand Down Expand Up @@ -802,12 +802,10 @@ def __del__(self):

class IDispatch(IUnknown):
if TYPE_CHECKING:
_disp_methods_ = (
hints.AnnoField()
) # type: ClassVar[List[comtypes._DispMemberSpec]]
_GetTypeInfo = hints.AnnoField() # type: Callable[[int, int], IUnknown]
__com_GetIDsOfNames = hints.AnnoField() # type: RawGetIDsOfNamesFunc
__com_Invoke = hints.AnnoField() # type: RawInvokeFunc
_disp_methods_: ClassVar[List[comtypes._DispMemberSpec]]
_GetTypeInfo: Callable[[int, int], IUnknown]
__com_GetIDsOfNames: RawGetIDsOfNamesFunc
__com_Invoke: RawInvokeFunc

_iid_ = GUID("{00020400-0000-0000-C000-000000000046}")
_methods_ = [
Expand Down
29 changes: 0 additions & 29 deletions comtypes/hints.pyi
Original file line number Diff line number Diff line change
@@ -1,33 +1,4 @@
from typing import (
Any,
Callable,
Generic,
NoReturn,
Optional,
overload,
SupportsIndex,
Type,
TypeVar,
Union as _UnionT,
)

# symbols those what might occur recursive imports in runtime.
from comtypes.automation import IDispatch as IDispatch, VARIANT as VARIANT
from comtypes.server import IClassFactory as IClassFactory
from comtypes.typeinfo import ITypeInfo as ITypeInfo

def AnnoField() -> Any:
"""**THIS IS `TYPE_CHECKING` ONLY SYMBOL.
This is workaround for class field type annotations for old
python versions.
Examples:
# instead of class field annotation, like below
class Foo:
# spam: int # <- not available in old versions.
if TYPE_CHECKING:
spam = AnnoField() # type: int # <- available in old versions.
"""
...
5 changes: 2 additions & 3 deletions comtypes/tools/tlbparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
Union as _UnionT,
)
from ctypes import _CData, _Pointer
from comtypes import hints


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

class Parser(object):
if TYPE_CHECKING:
tlib = hints.AnnoField() # type: typeinfo.ITypeLib
items = hints.AnnoField() # type: Dict[str, Any]
tlib: typeinfo.ITypeLib
items: Dict[str, Any]

def make_type(self, tdesc, tinfo):
# type: (typeinfo.TYPEDESC, typeinfo.ITypeInfo) -> Any
Expand Down
18 changes: 7 additions & 11 deletions comtypes/tools/typedesc_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,13 @@ def __init__(self, struct):

class _Struct_Union_Base(object):
if TYPE_CHECKING:
name = comtypes.hints.AnnoField() # type: str
align = comtypes.hints.AnnoField() # type: int
members = (
comtypes.hints.AnnoField()
) # type: List[_UnionT[Field, Method, Constructor]]
bases = comtypes.hints.AnnoField() # type: List[_Struct_Union_Base]
artificial = comtypes.hints.AnnoField() # type: Optional[Any]
size = comtypes.hints.AnnoField() # type: Optional[int]
_recordinfo_ = (
comtypes.hints.AnnoField()
) # type: Tuple[str, int, int, int, str]
name: str
align: int
members: List[_UnionT["Field", Method, Constructor]]
bases: List["_Struct_Union_Base"]
artificial: Optional[Any]
size: Optional[int]
_recordinfo_: Tuple[str, int, int, int, str]

location = None

Expand Down
Loading

0 comments on commit 39d9e00

Please sign in to comment.