Created
October 27, 2021 14:32
-
-
Save thclark/d664b31deada9b141abe70d1440f6866 to your computer and use it in GitHub Desktop.
Stack Printing Mixin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StackMixin: | |
""" A mixin to print out methods as they're called on classes. | |
Mix this in to classes whose logic flow you're trying to analyse, and you'll get a clear print out | |
of what methods are called and when. | |
""" | |
def __getattribute__(self, attr): | |
method = object.__getattribute__(self, attr) | |
if callable(method): | |
method_name = method.__repr__().split(" ")[2] | |
print(f"Calling {method_name}") | |
return method |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment