From a412a9a14a73f8041af34f0612c534c80bf9d13d Mon Sep 17 00:00:00 2001 From: Malfurious Date: Sat, 11 Mar 2023 08:56:26 -0500 Subject: Prefer __repr__ for pretty-printing objects Define human-readable string formatting for objects in repr, rather than str, as this will enable an interactive interpreter to more conveniently show this data to the user. I believe this especially makes sense in cases where __str__ doesn't perform a semantic type conversion for its class (currently, all affected cases). Scripts can still easily yield this information by using `print(object)`, as print will fallback to repr(object) when there is not an explicitly defined __str__. Furthermore, this patch still maintains backwards compatability (for the time being) of using str(object) to retrieve the information. This is because the default __str__ implementation will defer to __repr__ if provided. This made the Symtbl case of providing both of them especially redundant. Signed-off-by: Malfurious Signed-off-by: dusoleil --- sploit/symtbl.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'sploit/symtbl.py') diff --git a/sploit/symtbl.py b/sploit/symtbl.py index 05021f7..aa6fc69 100644 --- a/sploit/symtbl.py +++ b/sploit/symtbl.py @@ -170,11 +170,7 @@ class SymtblImpl: return symbol in self.__entries__ def __repr__(self): - """Return string representation of Symtbl""" - return str(self) - - def __str__(self): - """Return string representation of Symtbl""" + """Return human-readable Symtbl""" FMT = "\n{:<20} {:<20}" s = f"{len(self)} symbols @ {hex(self)}" s += FMT.format("ADDRESS", "SYMBOL") -- cgit v1.2.3