diff --git a/com/win32com/client/__init__.py b/com/win32com/client/__init__.py index 84e59a2fa2..a261c516ed 100644 --- a/com/win32com/client/__init__.py +++ b/com/win32com/client/__init__.py @@ -557,11 +557,8 @@ def __dir__(self): def __repr__(self): # Need to get the docstring for the module for this class. try: - mod_doc = sys.modules[self.__class__.__module__].__doc__ - if mod_doc: - mod_name = "win32com.gen_py." + mod_doc - else: - mod_name = sys.modules[self.__class__.__module__].__name__ + module = sys.modules[self.__class__.__module__] + mod_name = "win32com.gen_py." + (module.__doc__ or module.__name__) except KeyError: mod_name = "win32com.gen_py.unknown" return f"<{mod_name}.{self.__class__.__name__} instance at 0x{id(self)}>" @@ -630,7 +627,7 @@ def __init__(self, oobj=None): self.__dict__["_dispobj_"] = self.default_interface(oobj) def __repr__(self): - return f"" + return f"<{self.__class__.__module__}.{self.__class__.__name__}>" def __getattr__(self, attr): d = self.__dict__["_dispobj_"] diff --git a/com/win32com/client/dynamic.py b/com/win32com/client/dynamic.py index 3738da9031..9b6b8deb56 100644 --- a/com/win32com/client/dynamic.py +++ b/com/win32com/client/dynamic.py @@ -221,7 +221,7 @@ def __bool__(self): # desirable??? def __repr__(self): - return "" % (self._username_) + return f"" def __str__(self): # __str__ is used when the user does "print(object)", so we gracefully diff --git a/com/win32comext/axscript/client/framework.py b/com/win32comext/axscript/client/framework.py index c4a04329f8..6f39152435 100644 --- a/com/win32comext/axscript/client/framework.py +++ b/com/win32comext/axscript/client/framework.py @@ -166,7 +166,7 @@ def __init__(self): self.name = "" def __repr__(self): - return "<%s at %d: %s>" % (self.__class__.__name__, id(self), self.name) + return f"<{self.__class__.__name__} at {id(self)}: {self.name}>" def Reset(self): pass @@ -318,12 +318,7 @@ def __repr__(self): flagsDesc = "" if self.flags is not None and self.flags & axscript.SCRIPTITEM_GLOBALMEMBERS: flagsDesc = "/Global" - return "<%s at %d: %s%s>" % ( - self.__class__.__name__, - id(self), - self.name, - flagsDesc, - ) + return f"<{self.__class__.__name__} at {id(self)}: {self.name}{flagsDesc}>" def _dump_(self, level): flagDescs = [] diff --git a/win32/Lib/win32timezone.py b/win32/Lib/win32timezone.py index d9f69700ab..411713949b 100644 --- a/win32/Lib/win32timezone.py +++ b/win32/Lib/win32timezone.py @@ -663,11 +663,8 @@ def _LoadDynamicInfoFromKey(self, key) -> None: ) def __repr__(self) -> str: - result = f"{self.__class__.__name__}({self.timeZoneName!r}" - if self.fixedStandardTime: - result += ", True" - result += ")" - return result + fix_standard_time = ", True" if self.fixedStandardTime else "" + return f"{self.__class__.__name__}({self.timeZoneName!r}{fix_standard_time})" def __str__(self) -> str: return self.displayName