Created
November 16, 2010 23:24
-
-
Save fredpalmer/702728 to your computer and use it in GitHub Desktop.
How to bypass a decorator in Python
This file contains 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
# Bypass a decorator | |
import types | |
class decorator_test(object): | |
def __init__(self, f): | |
self.f = f | |
def __call__(self): | |
print "In decorator ... entering: ", self.f.__name__ | |
self.f() | |
print "In decorator ... exiting: ", self.f.__name__ | |
@decorator_test | |
def func1(): | |
print "inside func1()" | |
print "\nCalling func1 with decorator..." | |
func1() | |
print "\nBypassing decorator..." | |
for value in func1.__dict__.values(): | |
if isinstance(value, types.FunctionType) and value.func_name == "func1": | |
value.__call__() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment