Created
May 13, 2015 16:31
-
-
Save tkf/155160f6dca716db37ca to your computer and use it in GitHub Desktop.
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
def constant(cls): | |
cls.__repr__ = cls.__reduce__ = lambda self: self.__class__.__name__ | |
return cls() | |
@constant | |
class MyConstant(object): | |
pass | |
import pickle | |
assert pickle.loads(pickle.dumps(MyConstant)) is MyConstant | |
assert repr(MyConstant) == 'MyConstant' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment