Skip to content

Instantly share code, notes, and snippets.

@thclark
Created October 27, 2021 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thclark/d664b31deada9b141abe70d1440f6866 to your computer and use it in GitHub Desktop.
Save thclark/d664b31deada9b141abe70d1440f6866 to your computer and use it in GitHub Desktop.
Stack Printing Mixin
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