Message 86339 - Python tracker (original) (raw)
Hmm. That patch isn't quite right, in at least two respects
- if the single-argument constructor is using LBYL (i.e., an explicit isinstance(x, Rational), then the two-argument constructor should too.
- the zero-division check should come after the type check; that is, Rational(1, 0j) should raise TypeError rather than ZeroDivisionError.
Here's an updated version, that also makes the default second argument None rather than 1 and uses an 'is None' instead of '== 1' to determine number of arguments; this means that Fraction(3, 1.0) is no longer valid.