Skip to content

Respect subclass names in repr #2570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ Coming in build 311, as yet unreleased
* Fixed `TypeError: cannot unpack non-iterable NoneType object` when registering an axscript client ScriptItem (#2513, @Avasam)
* Fixed a memory leak when SafeArrays are used as out parameters (@the-snork)
* Fixed dispatch handling for properties (@the-snork)
* The following classes will now use the correct subclass name in `repr`: (#2570, @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`
* Resolved a handful of deprecation warnings (#2567, #2576, @Avasam)
* The following classes now produce a valid `eval` string representation when calling `repr`: (#2573, @Avasam)
* `pywin.tools.browser.HLIPythonObject`
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/tools/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions com/win32com/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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})"
4 changes: 2 additions & 2 deletions com/win32com/client/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion com/win32com/server/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion com/win32comext/axdebug/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, module):
self.cont = codecontainer.SourceModuleContainer(module)

def __repr__(self):
return f"<ModuleTreeNode wrapping {self.module}>"
return f"<{self.__class__.__name__} wrapping {self.module}>"

def Attach(self, parentRealNode):
self.realNode.Attach(parentRealNode)
Expand Down
2 changes: 1 addition & 1 deletion win32/Lib/win32pdhquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,6 @@ def __init__(self, query: BaseQuery):
self.query = query

def __repr__(self):
return f"<Query Error in {self.query!r}>"
return f"<{self.__class__.__name__} in {self.query!r}>"

__str__ = __repr__
2 changes: 1 addition & 1 deletion win32/Lib/win32rcparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down