diff --git a/CHANGES.txt b/CHANGES.txt index 5c915caa07..d5bf3ac906 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -16,6 +16,11 @@ Coming in build 311, as yet unreleased * Fixed a regression that broke special __dunder__ methods with CoClass. (#1870, #2493, @Avasam, @geppi) * Fixed a memory leak when SafeArrays are used as out parameters (@the-snork) * Fixed dispatch handling for properties (@the-snork) +* The following classes now produce a valid `eval` string representation when calling `repr`: (#2573, @Avasam) + * `pywin.tools.browser.HLIPythonObject` + * `win32com.server.exception.COMException` + * `win32comext.axscript.client.error.AXScriptException` + * `win32comext.axscript.client.pyscript.NamedScriptAttribute` Build 310, released 2025/03/16 ------------------------------ diff --git a/Pythonwin/pywin/tools/browser.py b/Pythonwin/pywin/tools/browser.py index 8346d7d019..b5629dc065 100644 --- a/Pythonwin/pywin/tools/browser.py +++ b/Pythonwin/pywin/tools/browser.py @@ -45,11 +45,9 @@ def __eq__(self, other): return self.name == other.name def __repr__(self): - try: - type = self.GetHLIType() - except: - type = "Generic" - return f"HLIPythonObject({type}) - name: {self.name} object: {self.myobject!r}" + return ( + f"{self.__class__.__name__}(name={self.name!r}, object={self.myobject!r})" + ) def GetText(self): try: diff --git a/com/win32com/server/exception.py b/com/win32com/server/exception.py index 43c08fcac1..571a951de2 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"" + return f"{self.__class__.__name__}(scode={self.scode!r}, desc={self.description!r})" def IsCOMException(t=None): diff --git a/com/win32comext/axscript/client/error.py b/com/win32comext/axscript/client/error.py index 41711abdd8..31f28c9e7a 100644 --- a/com/win32comext/axscript/client/error.py +++ b/com/win32comext/axscript/client/error.py @@ -218,9 +218,6 @@ def ExtractTracebackInfo(self, tb: TracebackType, site: COMScript): line = None return filename, lineno, name, line - def __repr__(self): - return "AXScriptException Object with description:" + self.description - def ProcessAXScriptException( scriptingSite: AXSite, diff --git a/com/win32comext/axscript/client/pyscript.py b/com/win32comext/axscript/client/pyscript.py index 91d3ed2c1e..0fde749576 100644 --- a/com/win32comext/axscript/client/pyscript.py +++ b/com/win32comext/axscript/client/pyscript.py @@ -109,7 +109,7 @@ def __init__(self, scriptItem): self.__dict__["_scriptItem_"] = scriptItem def __repr__(self): - return f"" + return f"{self.__class__.__name__}({self._scriptItem_!r})" def __getattr__(self, attr): # If a known subitem, return it.