Created
September 2, 2014 15:37
-
-
Save carymrobbins/32255be72a1b34b7d2cd to your computer and use it in GitHub Desktop.
Metaclass to debug your methods
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
| # Debugging metaclass | |
| # Put this in your class definition. | |
| def __metaclass__(name, bases, attrs): | |
| from functools import wraps | |
| try: | |
| import ipdb as pdb | |
| except ImportError: | |
| import pdb | |
| def debug_wrapper(f): | |
| @wraps(f) | |
| def wrapped(*args, **kwargs): | |
| pdb.set_trace() | |
| return f(*args, **kwargs) | |
| return wrapped | |
| for attr, value in attrs.items(): | |
| if callable(value): | |
| attrs[attr] = debug_wrapper(value) | |
| # You may have to change this out with the appropriate type. | |
| return type(name, bases, attrs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment