Skip to content

Commit 25e01da

Browse files
authored
Fix dispatch handling for properties (#2506)
1 parent 448c808 commit 25e01da

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ https://mhammond.github.io/pywin32_installers.html .
1414
Coming in build 311, as yet unreleased
1515
--------------------------------------
1616
* Fixed a regression that broke special __dunder__ methods with CoClass. (#1870, #2493, @Avasam, @geppi)
17+
* Fixed dispatch handling for properties (@the-snork)
1718

1819
Build 310, released 2025/03/16
1920
------------------------------

com/win32com/client/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -524,11 +524,10 @@ class DispatchBaseClass:
524524
def __init__(self, oobj=None):
525525
if oobj is None:
526526
oobj = pythoncom.new(self.CLSID)
527-
elif isinstance(oobj, DispatchBaseClass):
527+
elif isinstance(oobj, (DispatchBaseClass, _PyIDispatchType)):
528528
try:
529-
oobj = oobj._oleobj_.QueryInterface(
530-
self.CLSID, pythoncom.IID_IDispatch
531-
) # Must be a valid COM instance
529+
oobj = oobj._oleobj_ if isinstance(oobj, DispatchBaseClass) else oobj
530+
oobj = oobj.QueryInterface(self.CLSID, pythoncom.IID_IDispatch)
532531
except pythoncom.com_error as details:
533532
import winerror
534533

@@ -537,7 +536,7 @@ def __init__(self, oobj=None):
537536
# So just let it use the existing object if E_NOINTERFACE
538537
if details.hresult != winerror.E_NOINTERFACE:
539538
raise
540-
oobj = oobj._oleobj_
539+
541540
self.__dict__["_oleobj_"] = oobj # so we don't call __setattr__
542541

543542
def __dir__(self):

0 commit comments

Comments
 (0)