Skip to content
1 change: 0 additions & 1 deletion stubs/pywin32/@tests/stubtest_allowlist_win32.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ win32com.client.combrowse
win32com.client.tlbrowse

# Utilities to generate python bindings
win32com.client.build.*
win32com.client.CLSIDToClass
win32com.client.connect
# "dynamic.CDipatch" is necessary for mypy to not throw AssertionError
Expand Down
46 changes: 22 additions & 24 deletions stubs/pywin32/win32com/client/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,25 @@ from win32com.client import dynamic

_Stringifiable: TypeAlias = object

def GetObject(Pathname: str | None = ..., Class: Incomplete | None = ..., clsctx: Incomplete | None = ...) -> CDispatch: ...
def GetActiveObject(Class, clsctx=...): ...
def Moniker(Pathname, clsctx=...): ...
def GetObject(Pathname: str | None = None, Class=None, clsctx=None) -> CDispatch: ...
def GetActiveObject(Class: str, clsctx=...): ...
def Moniker(Pathname: str, clsctx=...): ...
def Dispatch(
dispatch: str | dynamic.PyIDispatchType | dynamic._GoodDispatchTypes | dynamic.PyIUnknownType,
userName: str | None = ...,
resultCLSID: _Stringifiable | None = ...,
typeinfo: _win32typing.PyITypeInfo | None = ...,
userName: str | None = None,
resultCLSID: _Stringifiable | None = None,
typeinfo: _win32typing.PyITypeInfo | None = None,
clsctx: int = ...,
) -> dynamic.CDispatch: ...
def DispatchEx(
clsid,
machine: Incomplete | None = ...,
userName: Incomplete | None = ...,
resultCLSID: Incomplete | None = ...,
typeinfo: Incomplete | None = ...,
clsctx: Incomplete | None = ...,
): ...
def DispatchEx(clsid, machine=None, userName=None, resultCLSID=None, typeinfo=None, clsctx=None): ...

class CDispatch(dynamic.CDispatch):
def __dir__(self): ...
def __dir__(self) -> list[str]: ...

def CastTo(ob, target, typelib: Incomplete | None = ...): ...
def CastTo(ob, target, typelib=None): ...

class Constants:
__dicts__: Incomplete
__dicts__: list[Incomplete]
def __getattr__(self, a: str): ...

constants: Final[Constants]
Expand All @@ -45,22 +38,22 @@ class EventsProxy:
def __getattr__(self, attr: str): ...
def __setattr__(self, attr: str, val) -> None: ...

def DispatchWithEvents(clsid, user_event_class): ...
def DispatchWithEvents(clsid, user_event_class) -> EventsProxy: ...
def WithEvents(disp, user_event_class): ...
def getevents(clsid): ...
def Record(name, object) -> com_record: ...
def register_record_class(cls) -> None: ...

class DispatchBaseClass:
def __init__(self, oobj: Incomplete | None = ...) -> None: ...
def __dir__(self): ...
def __eq__(self, other): ...
def __ne__(self, other): ...
def __init__(self, oobj=None) -> None: ...
def __dir__(self) -> list[str]: ...
def __eq__(self, other) -> bool: ...
def __ne__(self, other) -> bool: ...
def __getattr__(self, attr: str): ...
def __setattr__(self, attr: str, value) -> None: ...

class CoClassBaseClass:
def __init__(self, oobj: Incomplete | None = ...) -> None: ...
def __init__(self, oobj=None) -> None: ...
def __getattr__(self, attr: str): ...
def __setattr__(self, attr: str, value) -> None: ...
def __call__(self, *args, **kwargs): ...
Expand All @@ -73,4 +66,9 @@ class CoClassBaseClass:
class VARIANT:
varianttype: Incomplete
def __init__(self, vt, value) -> None: ...
value: Incomplete
@property
def value(self): ...
@value.setter
def value(self, newval) -> None: ...
@value.deleter
def value(self) -> None: ...
84 changes: 59 additions & 25 deletions stubs/pywin32/win32com/client/build.pyi
Original file line number Diff line number Diff line change
@@ -1,36 +1,70 @@
from _typeshed import Incomplete
from collections.abc import Iterable
from typing import ClassVar, Final, Literal

class NotSupportedException(Exception): ...

DropIndirection: Final = "DropIndirection"
NoTranslateTypes: Final[list[int]]
NoTranslateMap: Final[set[int]]

class MapEntry:
dispid: Incomplete
desc: Incomplete | None
names: Incomplete
doc: Incomplete
resultCLSID: Incomplete
resultDocumentation: Incomplete | None
wasProperty: Incomplete
hidden: bool | Literal[0, 1]
def __init__(
self, desc_or_id, names=None, doc=None, resultCLSID=..., resultDoc=None, hidden: bool | Literal[0, 1] = 0
) -> None: ...
def GetResultCLSID(self) -> Incomplete | None: ...
def GetResultCLSIDStr(self) -> str: ...
def GetResultName(self) -> Incomplete | None: ...

class OleItem:
typename: str
typename: ClassVar[str]
doc: Incomplete
python_name: Incomplete
bWritten: int
bIsDispatch: int
bIsSink: int
clsid: Incomplete
co_class: Incomplete
def __init__(self, doc: Incomplete | None = ...) -> None: ...
python_name: Incomplete | None
bWritten: bool | Literal[0, 1]
bIsDispatch: bool | Literal[0, 1]
bIsSink: bool | Literal[0, 1]
clsid: Incomplete | None
co_class: Incomplete | None
def __init__(self, doc=None) -> None: ...

class DispatchItem(OleItem):
typename: str
propMap: Incomplete
propMapGet: Incomplete
propMapPut: Incomplete
mapFuncs: Incomplete
defaultDispatchName: Incomplete
hidden: int
def __init__(
self, typeinfo: Incomplete | None = ..., attr: Incomplete | None = ..., doc: Incomplete | None = ..., bForUser: int = ...
) -> None: ...
typename: ClassVar[str]
propMap: dict[Incomplete, Incomplete]
propMapGet: dict[Incomplete, Incomplete]
propMapPut: dict[Incomplete, Incomplete]
mapFuncs: dict[Incomplete, Incomplete]
defaultDispatchName: Incomplete | None
hidden: bool | Literal[0, 1]
def __init__(self, typeinfo=None, attr=None, doc=None, bForUser: bool | Literal[0, 1] = 1) -> None: ...
clsid: Incomplete
bIsDispatch: Incomplete
def Build(self, typeinfo, attr, bForUser: int = ...) -> None: ...
def CountInOutOptArgs(self, argTuple): ...
def MakeFuncMethod(self, entry, name, bMakeClass: int = ...): ...
def MakeDispatchFuncMethod(self, entry, name, bMakeClass: int = ...): ...
def MakeVarArgsFuncMethod(self, entry, name, bMakeClass: int = ...): ...
bIsDispatch: bool | Literal[0, 1]
def Build(self, typeinfo, attr, bForUser: bool | Literal[0, 1] = 1) -> None: ...
def CountInOutOptArgs(self, argTuple: Iterable[Incomplete]) -> tuple[int, int, int]: ...
def MakeFuncMethod(self, entry, name: str, bMakeClass: bool | Literal[0, 1] = 1) -> list[str]: ...
def MakeDispatchFuncMethod(self, entry, name: str, bMakeClass: bool | Literal[0, 1] = 1) -> list[str]: ...
def MakeVarArgsFuncMethod(self, entry, name: str, bMakeClass: bool | Literal[0, 1] = 1) -> list[str]: ...

class VTableItem(DispatchItem):
vtableFuncs: list[tuple[Incomplete, Incomplete, Incomplete]]
def Build(self, typeinfo, attr, bForUser: bool | Literal[0, 1] = 1) -> None: ...

class LazyDispatchItem(DispatchItem):
typename: str
typename: ClassVar[str]
clsid: Incomplete
def __init__(self, attr, doc) -> None: ...

typeSubstMap: Final[dict[int, int]]
valid_identifier_chars: Final[str]

def demunge_leading_underscores(className: str) -> str: ...
def MakePublicAttributeName(className: str, is_global: bool = False) -> str: ...
def MakeDefaultArgRepr(defArgVal) -> str | None: ...
def BuildCallList(fdesc, names, defNamedOptArg, defNamedNotOptArg, defUnnamedArg, defOutArg, is_comment: bool = False) -> str: ...
37 changes: 19 additions & 18 deletions stubs/pywin32/win32com/client/dynamic.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from _typeshed import Incomplete
from typing import Any, Protocol, TypeVar, overload
from typing import Any, Final, Literal, Protocol, TypeVar, overload, type_check_only
from typing_extensions import TypeAlias

import _win32typing
Expand All @@ -9,23 +9,24 @@ from win32com.client import build
_T_co = TypeVar("_T_co", covariant=True)
_T = TypeVar("_T")

@type_check_only
class _DispatchCreateClass(Protocol[_T_co]):
Comment on lines +11 to 12
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @brianschubert I didn’t find any occurrences of this name in the source code (via grep), so I thought this case might also be interesting for your stubtest patch.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is covered by an allowlist entry, which is why it hasn't been flagged yet:

# "dynamic.CDipatch" is necessary for mypy to not throw AssertionError
win32com.client.dynamic.*

Maybe you can refine that while we're here?

@staticmethod
def __call__(
IDispatch: str | PyIDispatchType | _GoodDispatchTypes | PyIUnknownType,
olerepr: build.DispatchItem | build.LazyDispatchItem,
userName: str | None = ...,
lazydata: Incomplete | None = ...,
userName: str | None = None,
lazydata=None,
) -> _T_co: ...

debugging: int
debugging_attr: int
LCID: int
ERRORS_BAD_CONTEXT: Incomplete
ALL_INVOKE_TYPES: Incomplete
LCID: Final = 0x0
ERRORS_BAD_CONTEXT: Final[list[int]]
ALL_INVOKE_TYPES: Final[list[int]]

def debug_print(*args) -> None: ...
def debug_attr_print(*args) -> None: ...
def debug_print(*args: object) -> None: ...
def debug_attr_print(*args: object) -> None: ...

PyIDispatchType = _win32typing.PyIDispatch
PyIUnknownType = _win32typing.PyIUnknown
Expand All @@ -37,32 +38,32 @@ def Dispatch(
IDispatch: str | PyIDispatchType | _GoodDispatchTypes | PyIUnknownType,
userName: str | None,
createClass: _DispatchCreateClass[_T],
typeinfo: _win32typing.PyITypeInfo | None = ...,
typeinfo: _win32typing.PyITypeInfo | None = None,
clsctx: int = ...,
) -> _T: ...
@overload
def Dispatch(
IDispatch: str | PyIDispatchType | _GoodDispatchTypes | PyIUnknownType,
userName: str | None = ...,
userName: str | None = None,
createClass: None = None,
typeinfo: _win32typing.PyITypeInfo | None = ...,
typeinfo: _win32typing.PyITypeInfo | None = None,
clsctx: int = ...,
) -> CDispatch: ...
def MakeOleRepr(IDispatch, typeinfo, typecomp): ...
def DumbDispatch(IDispatch, userName: Incomplete | None = ..., createClass: Incomplete | None = ..., clsctx=...): ...
def MakeOleRepr(IDispatch, typeinfo, typecomp) -> build.DispatchItem | build.LazyDispatchItem: ...
def DumbDispatch(IDispatch, userName=None, createClass=None, clsctx=...): ...

class CDispatch:
def __init__(self, IDispatch, olerepr, userName: Incomplete | None = ..., lazydata: Incomplete | None = ...) -> None: ...
def __init__(self, IDispatch, olerepr, userName=None, lazydata=None) -> None: ...
def __call__(self, *args): ...
def __bool__(self) -> bool: ...
def __dir__(self): ...
def __eq__(self, other): ...
def __ne__(self, other): ...
def __dir__(self) -> list[str]: ...
def __eq__(self, other) -> bool: ...
def __ne__(self, other) -> bool: ...
def __int__(self) -> int: ...
def __len__(self) -> int: ...
def __getitem__(self, index): ...
def __setitem__(self, index, *args) -> None: ...
def __LazyMap__(self, attr): ...
def __LazyMap__(self, attr) -> Literal[0, 1] | None: ...
def __AttrToID__(self, attr): ...
ob: Incomplete
# CDispatch objects are dynamically generated and too complex to type
Expand Down
5 changes: 4 additions & 1 deletion stubs/pywin32/win32com/client/gencache.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from typing import Literal

from win32com.client import dynamic

def EnsureDispatch(
prog_id: str | dynamic.PyIDispatchType | dynamic._GoodDispatchTypes | dynamic.PyIUnknownType, bForDemand: int = ...
prog_id: str | dynamic.PyIDispatchType | dynamic._GoodDispatchTypes | dynamic.PyIUnknownType,
bForDemand: bool | Literal[0, 1] = 1,
) -> dynamic.CDispatch: ...
102 changes: 52 additions & 50 deletions stubs/pywin32/win32com/olectl.pyi
Original file line number Diff line number Diff line change
@@ -1,54 +1,56 @@
FACILITY_CONTROL: int
from typing import Final

FACILITY_CONTROL: Final = 0xA

def MAKE_SCODE(sev: int, fac: int, code: int) -> int: ...
def STD_CTL_SCODE(n: int) -> int: ...

CTL_E_ILLEGALFUNCTIONCALL: int
CTL_E_OVERFLOW: int
CTL_E_OUTOFMEMORY: int
CTL_E_DIVISIONBYZERO: int
CTL_E_OUTOFSTRINGSPACE: int
CTL_E_OUTOFSTACKSPACE: int
CTL_E_BADFILENAMEORNUMBER: int
CTL_E_FILENOTFOUND: int
CTL_E_BADFILEMODE: int
CTL_E_FILEALREADYOPEN: int
CTL_E_DEVICEIOERROR: int
CTL_E_FILEALREADYEXISTS: int
CTL_E_BADRECORDLENGTH: int
CTL_E_DISKFULL: int
CTL_E_BADRECORDNUMBER: int
CTL_E_BADFILENAME: int
CTL_E_TOOMANYFILES: int
CTL_E_DEVICEUNAVAILABLE: int
CTL_E_PERMISSIONDENIED: int
CTL_E_DISKNOTREADY: int
CTL_E_PATHFILEACCESSERROR: int
CTL_E_PATHNOTFOUND: int
CTL_E_INVALIDPATTERNSTRING: int
CTL_E_INVALIDUSEOFNULL: int
CTL_E_INVALIDFILEFORMAT: int
CTL_E_INVALIDPROPERTYVALUE: int
CTL_E_INVALIDPROPERTYARRAYINDEX: int
CTL_E_SETNOTSUPPORTEDATRUNTIME: int
CTL_E_SETNOTSUPPORTED: int
CTL_E_NEEDPROPERTYARRAYINDEX: int
CTL_E_SETNOTPERMITTED: int
CTL_E_GETNOTSUPPORTEDATRUNTIME: int
CTL_E_GETNOTSUPPORTED: int
CTL_E_PROPERTYNOTFOUND: int
CTL_E_INVALIDCLIPBOARDFORMAT: int
CTL_E_INVALIDPICTURE: int
CTL_E_PRINTERERROR: int
CTL_E_CANTSAVEFILETOTEMP: int
CTL_E_SEARCHTEXTNOTFOUND: int
CTL_E_REPLACEMENTSTOOLONG: int
CONNECT_E_FIRST: int
CONNECT_E_LAST: int
CONNECT_S_FIRST: int
CONNECT_S_LAST: int
CONNECT_E_NOCONNECTION: int
CONNECT_E_ADVISELIMIT: int
CONNECT_E_CANNOTCONNECT: int
CONNECT_E_OVERRIDDEN: int
CLASS_E_NOTLICENSED: int
CTL_E_ILLEGALFUNCTIONCALL: Final = -2146828283
CTL_E_OVERFLOW: Final = -2146828282
CTL_E_OUTOFMEMORY: Final = -2146828281
CTL_E_DIVISIONBYZERO: Final = -2146828277
CTL_E_OUTOFSTRINGSPACE: Final = -2146828274
CTL_E_OUTOFSTACKSPACE: Final = -2146828260
CTL_E_BADFILENAMEORNUMBER: Final = -2146828236
CTL_E_FILENOTFOUND: Final = -2146828235
CTL_E_BADFILEMODE: Final = -2146828234
CTL_E_FILEALREADYOPEN: Final = -2146828233
CTL_E_DEVICEIOERROR: Final = -2146828231
CTL_E_FILEALREADYEXISTS: Final = -2146828230
CTL_E_BADRECORDLENGTH: Final = -2146828229
CTL_E_DISKFULL: Final = -2146828227
CTL_E_BADRECORDNUMBER: Final = -2146828225
CTL_E_BADFILENAME: Final = -2146828224
CTL_E_TOOMANYFILES: Final = -2146828221
CTL_E_DEVICEUNAVAILABLE: Final = -2146828220
CTL_E_PERMISSIONDENIED: Final = -2146828218
CTL_E_DISKNOTREADY: Final = -2146828217
CTL_E_PATHFILEACCESSERROR: Final = -2146828213
CTL_E_PATHNOTFOUND: Final = -2146828212
CTL_E_INVALIDPATTERNSTRING: Final = -2146828195
CTL_E_INVALIDUSEOFNULL: Final = -2146828194
CTL_E_INVALIDFILEFORMAT: Final = -2146827967
CTL_E_INVALIDPROPERTYVALUE: Final = -2146827908
CTL_E_INVALIDPROPERTYARRAYINDEX: Final = -2146827907
CTL_E_SETNOTSUPPORTEDATRUNTIME: Final = -2146827906
CTL_E_SETNOTSUPPORTED: Final = -2146827905
CTL_E_NEEDPROPERTYARRAYINDEX: Final = -2146827903
CTL_E_SETNOTPERMITTED: Final = -2146827901
CTL_E_GETNOTSUPPORTEDATRUNTIME: Final = -2146827895
CTL_E_GETNOTSUPPORTED: Final = -2146827894
CTL_E_PROPERTYNOTFOUND: Final = -2146827866
CTL_E_INVALIDCLIPBOARDFORMAT: Final = -2146827828
CTL_E_INVALIDPICTURE: Final = -2146827807
CTL_E_PRINTERERROR: Final = -2146827806
CTL_E_CANTSAVEFILETOTEMP: Final = -2146827553
CTL_E_SEARCHTEXTNOTFOUND: Final = -2146827544
CTL_E_REPLACEMENTSTOOLONG: Final = -2146827542
CONNECT_E_FIRST: Final = -2147220992
CONNECT_E_LAST: Final = -2147220977
CONNECT_S_FIRST: Final = 262656
CONNECT_S_LAST: Final = 262671
CONNECT_E_NOCONNECTION: Final = -2147220992
CONNECT_E_ADVISELIMIT: Final = -2147220991
CONNECT_E_CANNOTCONNECT: Final = -2147220990
CONNECT_E_OVERRIDDEN: Final = -2147220989
CLASS_E_NOTLICENSED: Final = -2147221230
Loading
Loading