Created
June 18, 2012 03:08
Stub object
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
class _Stub(object): | |
"""Class for creating stub object. | |
For internal use. | |
""" | |
def __getattribute__(self, *args, **kwargs): | |
return self | |
def next(self): | |
raise StopIteration | |
def __repr__(self): | |
return 'Dummy' | |
def __str__(self): | |
return '' | |
def __len__(self): | |
return 0 | |
def __eq__(self, other): | |
return self is other | |
def __hash__(self): | |
return hash(None) | |
def __call__(self, *args, **kwargs): | |
return self | |
__sub__ = __div__ = __mul__ = __floordiv__ = __mod__ = __and__ = __or__ = \ | |
__xor__ = __rsub__ = __rdiv__ = __rmul__ = __rfloordiv__ = __rmod__ = \ | |
__rand__ = __rxor__ = __ror__ = __radd__ = __pow__ = __rpow__ = \ | |
__rshift__ = __lshift__ = __rrshift__ = __rlshift__ = __truediv__ = \ | |
__rtruediv__ = __add__ = __getitem__ = __neg__ = __pos__ = __abs__ = \ | |
__invert__ = __setattr__ = __delattr__ = __delitem__ = __setitem__ = \ | |
__iter__ = __call__ | |
Stub = _Stub() # You can do whatever you like with it now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment