Skip to content

Instantly share code, notes, and snippets.

@TheWaWaR
Last active August 29, 2015 14:00
Show Gist options
  • Save TheWaWaR/11021588 to your computer and use it in GitHub Desktop.
Save TheWaWaR/11021588 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
#coding: utf-8
# ==============================================================================
# python -m doctest -v test_rsub.py
# ==============================================================================
class Left1(int):
"""
>>> print Left1(3) - Right(8)
call Left1.__sub__: 3 8
call Right.__rsub__: 8 3
-5
"""
def __sub__(self, other):
print 'call Left1.__sub__:', self, other
return NotImplemented
class Left2(int):
"""
>>> print Left2(3) - Right(8)
call Left2.__sub__: 3 8
-5
"""
def __sub__(self, other):
print 'call Left2.__sub__:', self, other
return int.__sub__(self, other)
class Right(int):
def __rsub__(self, other):
print 'call Right.__rsub__:', self, other
return int.__rsub__(self, other)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment