From 9092bccc07756f9344f90ffb40b90e687c3e92ef Mon Sep 17 00:00:00 2001 From: Gabriel Tkacz Date: Fri, 7 Jun 2024 18:40:02 -0300 Subject: [PATCH 1/2] Modifying all __repr__ methods so that subclassing will print out the correct class name --- box/box.py | 2 +- box/box_list.py | 2 +- box/config_box.py | 2 +- box/shorthand_box.py | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/box/box.py b/box/box.py index 158a55e..191903e 100644 --- a/box/box.py +++ b/box/box.py @@ -777,7 +777,7 @@ def popitem(self): return key, self.pop(key) def __repr__(self) -> str: - return f"Box({self})" + return f"{self.__class__.__name__}({self})" def __str__(self) -> str: return str(self.to_dict()) diff --git a/box/box_list.py b/box/box_list.py index 048b014..5a983b8 100644 --- a/box/box_list.py +++ b/box/box_list.py @@ -133,7 +133,7 @@ def _dotted_helper(self) -> List[str]: return keys def __repr__(self): - return f"BoxList({self.to_list()})" + return f"{self.__class__.__name__}({self.to_list()})" def __str__(self): return str(self.to_list()) diff --git a/box/config_box.py b/box/config_box.py index 0202ca3..4c48877 100644 --- a/box/config_box.py +++ b/box/config_box.py @@ -124,7 +124,7 @@ def getfloat(self, item, default=None): return self.float(item, default) def __repr__(self): - return "ConfigBox({0})".format(str(self.to_dict())) + return f"{self.__class__.__name__}({str(self.to_dict())})" def copy(self): return ConfigBox(super().copy()) diff --git a/box/shorthand_box.py b/box/shorthand_box.py index 99dfc8d..a82edbd 100644 --- a/box/shorthand_box.py +++ b/box/shorthand_box.py @@ -44,7 +44,7 @@ def toml(self) -> str: return self.to_toml() def __repr__(self): - return f"SBox({self})" + return f"{self.__class__.__name__}({self})" def copy(self) -> "SBox": return SBox(super(SBox, self).copy()) @@ -66,4 +66,4 @@ def __new__(cls, *args, **kwargs): return obj def __repr__(self) -> str: - return f"DDBox({self})" + return f"{self.__class__.__name__}({self})" From 192cbe38d758dd31b411486e2b7f57652322f60f Mon Sep 17 00:00:00 2001 From: Gabriel Tkacz Date: Fri, 7 Jun 2024 18:43:24 -0300 Subject: [PATCH 2/2] Altering documentation to reflect new __repr__ changes --- AUTHORS.rst | 1 + CHANGES.rst | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/AUTHORS.rst b/AUTHORS.rst index b67a735..e0f80c0 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -30,6 +30,7 @@ Code contributions: - Michał Górny (mgorny) - Serge Lu (Serge45) - Eric Prestat (ericpre) +- Gabriel Mitelman Tkacz (gtkacz) diff --git a/CHANGES.rst b/CHANGES.rst index 0272697..3029993 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,11 @@ Changelog ========= +Version 7.1.2 +------------- + +* Fixing #261 altering all `__repr__` methods so that subclassing will output the correct class name + Version 7.1.1 -------------