Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # works
- class TFloatObject(TObject):
- ...
- def add(self, other):
- assert(isinstance(other, TObject))
- if isinstance(other, TIntObject):
- return TFloatObject(self.val + other.val)
- elif isinstance(other, TFloatObject):
- return TFloatObject(self.val + other.val)
- else:
- raise Exception("Incompatibe types")
- # fails
- class TFloatObject(TObject):
- ...
- def add(self, other):
- assert(isinstance(other, TObject))
- if isinstance(other, TIntObject) or isinstance(other, TFloatObject):
- return TFloatObject(self.val + other.val)
- else:
- raise Exception("Incompatibe types")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement