Created
April 15, 2012 15:27
-
-
Save rik0/2393423 to your computer and use it in GitHub Desktop.
Funny decorator
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
import functools | |
class rusty_method(object): | |
def __init__(self, hits, chain_effect): | |
self.hits = hits | |
self.chain_effect = chain_effect | |
self.hit_memory = [] | |
def __call__(self, func): | |
def aux(that, *args): | |
self.hit_memory.append(args) | |
if self.hits > 0: | |
self.hits -= 1 | |
else: | |
cols = zip(*self.hit_memory) | |
self.hit_memory.pop() | |
arguments = [reduce(self.chain_effect, col) | |
for col in cols] | |
return func(that, *arguments) | |
functools.update_wrapper(aux, func) | |
return aux |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment