Created
September 4, 2014 01:47
-
-
Save mscook/ee692d836e68c5cc1243 to your computer and use it in GitHub Desktop.
wrapt examples!
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
############################################################################## | |
# | |
# Handling arguments | |
# | |
# This is a wrapt decorator equivalent to Colton Meyers' skipIf presented | |
# from about the 15 minute mark in his PyCon 2014 talk | |
# | |
############################################################################## | |
import wrapt | |
def skipIf(conditional, message): | |
@wrapt.decorator() | |
def wrapper(wrapped, instance, args, kwargs): | |
print "Checking if we need to execute..." | |
if not conditional: | |
return wrapped(*args, **kwargs) | |
else: | |
print message | |
return wrapper | |
@skipIf(False, "Skipped") | |
def func1(): | |
print "Executing: func1" | |
@skipIf(True, "Skipped") | |
def func2(): | |
print "Executing: func2" | |
func1() | |
func2() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment