Skip to content

Instantly share code, notes, and snippets.

@carymrobbins
Created September 2, 2014 15:37
Show Gist options
  • Save carymrobbins/32255be72a1b34b7d2cd to your computer and use it in GitHub Desktop.
Save carymrobbins/32255be72a1b34b7d2cd to your computer and use it in GitHub Desktop.
Metaclass to debug your methods
# 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