Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- logging full trace once
- '__init__': [
- {'init_method_1':
- [
- {'init_method_1_1': []}
- ]}
- {'init_method_2': []}
- ],
- 'main_function': [
- {'first_main_function': [
- {'condition_method_3': []},
- {'condition_method_5': []}
- ]}
- ]
- import types
- class DecoMeta(type):
- def __new__(cls, name, bases, attrs):
- for attr_name, attr_value in attrs.items():
- if isinstance(attr_value, types.FunctionType):
- attrs[attr_name] = cls.deco(attr_value)
- return super(DecoMeta, cls).__new__(cls, name, bases, attrs)
- @classmethod
- def deco(cls, func):
- def wrapper(*args, **kwargs):
- name = func.__name__
- stacktrace_full.setdefault(name, [])
- sorted_functions = stacktrace_full[name]
- if len(sorted_functions) > 0:
- stacktrace_full[name].append(name)
- result = func(*args, **kwargs)
- print("after",func.__name__)
- return result
- return wrapper
- class MyKlass(metaclass=DecoMeta):
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement