Skip to content

Commit b792dcb

Browse files
committed
Update some repr to produce a valid string representation valid for eval
1 parent 16c4981 commit b792dcb

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

CHANGES.txt

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ Coming in build 311, as yet unreleased
1616
* Fixed a regression that broke special __dunder__ methods with CoClass. (#1870, #2493, @Avasam, @geppi)
1717
* Fixed a memory leak when SafeArrays are used as out parameters (@the-snork)
1818
* Fixed dispatch handling for properties (@the-snork)
19+
* The following classes now produce a valid `eval` string representation when calling `repr`: (#2573, @Avasam)
20+
* `pywin.tools.browser.HLIPythonObject`
21+
* `win32com.server.exception.COMException`
22+
* `win32comext.axscript.client.error.AXScriptException`
23+
* `win32comext.axscript.client.pyscript.NamedScriptAttribute`
1924

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

Pythonwin/pywin/tools/browser.py

+3-5
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

+1-1
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

-3
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

+1-1
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)