diff options
author | Malfurious <m@lfurio.us> | 2023-03-11 08:56:26 -0500 |
---|---|---|
committer | dusoleil <howcansocksbereal@gmail.com> | 2023-03-13 19:21:48 -0400 |
commit | a412a9a14a73f8041af34f0612c534c80bf9d13d (patch) | |
tree | 7e3f0939417b2511da7804274b1aee223d4c0f52 /sploit/symtbl.py | |
parent | 1b4e81c5753bb551d9a81e174d851c98d63e0124 (diff) | |
download | nsploit-a412a9a14a73f8041af34f0612c534c80bf9d13d.tar.gz nsploit-a412a9a14a73f8041af34f0612c534c80bf9d13d.zip |
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 <m@lfurio.us>
Signed-off-by: dusoleil <howcansocksbereal@gmail.com>
Diffstat (limited to 'sploit/symtbl.py')
-rw-r--r-- | sploit/symtbl.py | 6 |
1 files changed, 1 insertions, 5 deletions
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") |