Last active
December 23, 2015 05:49
-
-
Save porterjamesj/6589965 to your computer and use it in GitHub Desktop.
fooling around with some FauxO tooling
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
from functools import wraps | |
from copy import deepcopy | |
def fauxothis(fn): | |
@wraps(fn) | |
def wrapper(self): | |
new = deepcopy(self) | |
fn(new) | |
return new | |
return wrapper | |
class Test(object): | |
@fauxothis | |
def stuff(self): | |
self.hey +=1 | |
# test | |
a = Test() | |
a.hey = 1 | |
a.stuff() | |
# a.hey => 1 | |
b = a.stuff() | |
# a.hey => 1 | |
# b.hey => 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment