Skip to content

Instantly share code, notes, and snippets.

@tkf
Created May 13, 2015 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkf/155160f6dca716db37ca to your computer and use it in GitHub Desktop.
Save tkf/155160f6dca716db37ca to your computer and use it in GitHub Desktop.
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