diff --git a/CHANGES.md b/CHANGES.md index 29eb008c76..17626d24a4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,6 +18,17 @@ As of build 305, installation .exe files have been deprecated; see Coming in build 312, as yet unreleased -------------------------------------- +* The following classes will now use the correct subclass name in `repr`: (mhammond#2570, [@Avasam][Avasam]) + * `pywin.tools.browser.HLIPythonObject` + * `win32com.client.VARIANT` + * `win32com.client.build.MapEntry` + * `win32com.server.exception.COMException` + * `win32comext.axdebug.debugger.ModuleTreeNode` + * `win32comext.axscript.client.pyscript.NamedScriptAttribute` + * `win32comext.axscript.client.error.AXScriptException` + * `win32pdhquery.QueryError` + * `win32rcparser.StringDef` + Build 311, released 2025/07/14 ------------------------------ diff --git a/Pythonwin/pywin/tools/browser.py b/Pythonwin/pywin/tools/browser.py index b5629dc065..72b2bb7a3a 100644 --- a/Pythonwin/pywin/tools/browser.py +++ b/Pythonwin/pywin/tools/browser.py @@ -46,7 +46,7 @@ def __eq__(self, other): def __repr__(self): return ( - f"{self.__class__.__name__}(name={self.name!r}, object={self.myobject!r})" + f"{self.__class__.__name__}(myobject={self.myobject!r}, name={self.name!r})" ) def GetText(self): diff --git a/com/win32com/client/__init__.py b/com/win32com/client/__init__.py index 84e59a2fa2..d072221cb9 100644 --- a/com/win32com/client/__init__.py +++ b/com/win32com/client/__init__.py @@ -678,7 +678,7 @@ def __bool__(self): # A very simple VARIANT class. Only to be used with poorly-implemented COM # objects. If an object accepts an arg which is a simple "VARIANT", but still -# is very pickly about the actual variant type (eg, isn't happy with a VT_I4, +# is very picky about the actual variant type (eg, isn't happy with a VT_I4, # which it would get from a Python integer), you can use this to force a # particular VT. class VARIANT: @@ -700,4 +700,4 @@ def _del_value(self): value = property(_get_value, _set_value, _del_value) def __repr__(self): - return f"win32com.client.VARIANT({self.varianttype!r}, {self._value!r})" + return f"{self.__class__.__module__}.{self.__class__.__name__}({self.varianttype!r}, {self._value!r})" diff --git a/com/win32com/client/build.py b/com/win32com/client/build.py index b4c5e75699..84a3107a39 100644 --- a/com/win32com/client/build.py +++ b/com/win32com/client/build.py @@ -70,7 +70,7 @@ class NotSupportedException(Exception): class MapEntry: - "Simple holder for named attibutes - items in a map." + """Simple holder for named attributes - items in a map.""" def __init__( self, @@ -99,7 +99,7 @@ def __init__( def __repr__(self): return ( - "MapEntry(dispid={s.dispid}, desc={s.desc}, names={s.names}, doc={s.doc!r}, " + "{s.__class__.__name__}(dispid={s.dispid}, desc={s.desc}, names={s.names}, doc={s.doc!r}, " "resultCLSID={s.resultCLSID}, resultDocumentation={s.resultDocumentation}, " "wasProperty={s.wasProperty}, hidden={s.hidden}" ).format(s=self) diff --git a/com/win32com/server/exception.py b/com/win32com/server/exception.py index 571a951de2..e346ce454c 100644 --- a/com/win32com/server/exception.py +++ b/com/win32com/server/exception.py @@ -78,7 +78,7 @@ def __init__( pythoncom.com_error.__init__(self, scode, self.description, None, -1) def __repr__(self): - return f"{self.__class__.__name__}(scode={self.scode!r}, desc={self.description!r})" + return f"{self.__class__.__name__}(description={self.description!r}, scode={self.scode!r})" def IsCOMException(t=None): diff --git a/com/win32comext/axdebug/debugger.py b/com/win32comext/axdebug/debugger.py index d0585b9b6f..9e5bce674a 100644 --- a/com/win32comext/axdebug/debugger.py +++ b/com/win32comext/axdebug/debugger.py @@ -19,7 +19,7 @@ def __init__(self, module): self.cont = codecontainer.SourceModuleContainer(module) def __repr__(self): - return f"" + return f"<{self.__class__.__name__} wrapping {self.module}>" def Attach(self, parentRealNode): self.realNode.Attach(parentRealNode) diff --git a/win32/Lib/win32pdhquery.py b/win32/Lib/win32pdhquery.py index e356f89142..dc1db54be7 100644 --- a/win32/Lib/win32pdhquery.py +++ b/win32/Lib/win32pdhquery.py @@ -565,6 +565,6 @@ def __init__(self, query: BaseQuery): self.query = query def __repr__(self): - return f"" + return f"<{self.__class__.__name__} in {self.query!r}>" __str__ = __repr__ diff --git a/win32/Lib/win32rcparser.py b/win32/Lib/win32rcparser.py index 183f075b1c..2792995832 100644 --- a/win32/Lib/win32rcparser.py +++ b/win32/Lib/win32rcparser.py @@ -169,7 +169,7 @@ def __init__(self, id, idNum, value): self.value = value def __repr__(self): - return f"StringDef({self.id!r}, {self.idNum!r}, {self.value!r})" + return f"{self.__class__.__name__}({self.id!r}, {self.idNum!r}, {self.value!r})" class RCParser: