This line:
Rational(self.num, self.denom) < Rational(right.num, right.denom)
… is calling the __lt__
method again, leading to an infinite recursion. Try a different approach, assuming that we're using Python 3.x (or in Python 2.x, that from __future__ import division
was executed beforehand), this should work:
self.num/self.denom < right.num/right.denom