Skip to content

Commit 08e7475

Browse files
authored
Update some repr to produce a valid string representation valid for eval (#2573)
1 parent f8f9441 commit 08e7475

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

CHANGES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ Coming in build 311, as yet unreleased
1717
* Fixed `TypeError: cannot unpack non-iterable NoneType object` when registering an axscript client ScriptItem (#2513, @Avasam)
1818
* Fixed a memory leak when SafeArrays are used as out parameters (@the-snork)
1919
* Fixed dispatch handling for properties (@the-snork)
20+
* The following classes now produce a valid `eval` string representation when calling `repr`: (#2573, @Avasam)
21+
* `pywin.tools.browser.HLIPythonObject`
22+
* `win32com.server.exception.COMException`
23+
* `win32comext.axscript.client.error.AXScriptException`
24+
* `win32comext.axscript.client.pyscript.NamedScriptAttribute`
2025

2126
Build 310, released 2025/03/16
2227
------------------------------

Pythonwin/pywin/tools/browser.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@ def __eq__(self, other):
4545
return self.name == other.name
4646

4747
def __repr__(self):
48-
try:
49-
type = self.GetHLIType()
50-
except:
51-
type = "Generic"
52-
return f"HLIPythonObject({type}) - name: {self.name} object: {self.myobject!r}"
48+
return (
49+
f"{self.__class__.__name__}(name={self.name!r}, object={self.myobject!r})"
50+
)
5351

5452
def GetText(self):
5553
try:

com/win32com/server/exception.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __init__(
7878
pythoncom.com_error.__init__(self, scode, self.description, None, -1)
7979

8080
def __repr__(self):
81-
return f"<COM Exception - scode={self.scode}, desc={self.description}>"
81+
return f"{self.__class__.__name__}(scode={self.scode!r}, desc={self.description!r})"
8282

8383

8484
def IsCOMException(t=None):

com/win32comext/axscript/client/error.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,6 @@ def ExtractTracebackInfo(self, tb: TracebackType, site: COMScript):
218218
line = None
219219
return filename, lineno, name, line
220220

221-
def __repr__(self):
222-
return "AXScriptException Object with description:" + self.description
223-
224221

225222
def ProcessAXScriptException(
226223
scriptingSite: AXSite,

com/win32comext/axscript/client/pyscript.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def __init__(self, scriptItem):
109109
self.__dict__["_scriptItem_"] = scriptItem
110110

111111
def __repr__(self):
112-
return f"<NamedItemAttribute{self._scriptItem_!r}>"
112+
return f"{self.__class__.__name__}({self._scriptItem_!r})"
113113

114114
def __getattr__(self, attr):
115115
# If a known subitem, return it.

0 commit comments

Comments
 (0)