diff --git a/CHANGES.txt b/CHANGES.txt index 8955b85a63..fb0bd8ce0b 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -14,6 +14,7 @@ https://mhammond.github.io/pywin32_installers.html . Coming in build 311, as yet unreleased -------------------------------------- * Fixed a regression that broke special __dunder__ methods with CoClass. (#1870, #2493, @Avasam, @geppi) +* Fixed dispatch handling for properties (@the-snork) Build 310, released 2025/03/16 ------------------------------ diff --git a/com/win32com/client/__init__.py b/com/win32com/client/__init__.py index d060fae00d..84e59a2fa2 100644 --- a/com/win32com/client/__init__.py +++ b/com/win32com/client/__init__.py @@ -524,11 +524,10 @@ class DispatchBaseClass: def __init__(self, oobj=None): if oobj is None: oobj = pythoncom.new(self.CLSID) - elif isinstance(oobj, DispatchBaseClass): + elif isinstance(oobj, (DispatchBaseClass, _PyIDispatchType)): try: - oobj = oobj._oleobj_.QueryInterface( - self.CLSID, pythoncom.IID_IDispatch - ) # Must be a valid COM instance + oobj = oobj._oleobj_ if isinstance(oobj, DispatchBaseClass) else oobj + oobj = oobj.QueryInterface(self.CLSID, pythoncom.IID_IDispatch) except pythoncom.com_error as details: import winerror @@ -537,7 +536,7 @@ def __init__(self, oobj=None): # So just let it use the existing object if E_NOINTERFACE if details.hresult != winerror.E_NOINTERFACE: raise - oobj = oobj._oleobj_ + self.__dict__["_oleobj_"] = oobj # so we don't call __setattr__ def __dir__(self):