Skip to content

Instantly share code, notes, and snippets.

@unutbu
Created October 29, 2018 18:20
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 unutbu/2be784436f1495015b16b0c6eb5f21f1 to your computer and use it in GitHub Desktop.
Save unutbu/2be784436f1495015b16b0c6eb5f21f1 to your computer and use it in GitHub Desktop.
class MyInt(int):
def __add__(self, other):
print('__add__({}, {})'.format(self, other))
return MyInt(other+self)
def __radd__(self, other):
print('__radd__({}, {})'.format(self, other))
return MyInt(int(self)+other)
c = MyInt(5)
p = 1
print(type(p+c))
print('-'*80)
print(type(c+p))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment