cpython icon indicating copy to clipboard operation
cpython copied to clipboard

gh-82017: Support as_integer_ratio() in the Fraction constructor

Open serhiy-storchaka opened this issue 1 year ago • 1 comments

Any numbers that have the as_integer_ratio() method (e.g. numpy.float128) can now be converted to a fraction.

  • Issue: gh-82017

📚 Documentation preview 📚: https://cpython-previews--120271.org.readthedocs.build/

serhiy-storchaka avatar Jun 08 '24 14:06 serhiy-storchaka

I'd welcome thoughts from @rhettinger on this particular change.

mdickinson avatar Jul 14 '24 09:07 mdickinson

Then isinstance(numerator, numbers.Number) should be replaced by not isinstance(numerator, type). We need at least exclude types, because the type has the same method as an instance.

serhiy-storchaka avatar Jul 15 '24 06:07 serhiy-storchaka

I'd welcome thoughts from @rhettinger on this particular change.

This seems reasonable to me.

I would leave off the isinstance() check and use pure duck-typing for the as_integer_ratio() method.

rhettinger avatar Jul 18 '24 01:07 rhettinger