4 Answers
4

I see-- what you would like is to have something like a __as_number__ method you can define in TAG_Short, which would allow you to return a number which is then used in any place where a ValueError would be about to be raised. I have no idea if there is any way to do something like that, short of implementing that metafeature yourself.

What you can do is define __add__, __radd__, __mul__, __rmul__, etc (you must define every numeric method if you want your object to truly behave like a number in every situation), and have each of them return the result of doing the desired operation with what you consider to be the number representation of the TAG_Short object.

If you find yourself doing this often enough, you may consider implementing the metafeature you describe (or first looking for a stable implementation to reuse). It would be quite feasible in Python. I think it might even be as easy as a good-old-fashioned class to be inherited from (untested code follows), with something kind of like: