# PEP 3141: \_\_ratio\_\_ instead of numerator/denominator

**URL:** <https://discuss.python.org/t/pep-3141-ratio-instead-of-numerator-denominator/2037>\
**Category:** Ideas\
**Created:** [July 25, 2019, 10:17pm UTC](https://discuss.python.org/t/pep-3141-ratio-instead-of-numerator-denominator/2037 "2019-07-25T22:17:07Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![jdemeyer](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jdemeyer/32/454_2.png) [@jdemeyer](https://discuss.python.org/u/jdemeyer)\
**Post date:** [July 26, 2019, 9:05pm UTC](https://discuss.python.org/t/pep-3141-ratio-instead-of-numerator-denominator/2037/4 "2019-07-26T21:05:37Z")

</div>

> [@steven.daprano](#):
>
> Does denominator need to be a method in SageMath? Why couldn’t they have  
> used a property?

That doesn’t really matter. Maybe SageMath could have used a property, but they didn’t. It’s just a choice, there is nothing wrong with a method.

> [@steven.daprano](#):
>
> Does the same problem apply to numerator?

Yes.

> [@steven.daprano](#):
>
> they should just deprecate the  
> current behaviour and use a property.

I don’t see how to do that technically. What kind of object would `q.denominator` then be?

> [@steven.daprano](#):
>
> Unless you are planning to add a pair of builtins denominator() and  
> numerator(), I don’t think we should change the API to use dunders  
> instead of regular attributes.

OK, so let’s add such functions to the `numbers` module.

> [@steven.daprano](#):
>
> How would you solve changing the Rational API without breaking people’s  
> code?

The function `numbers.denominator()` could try ` __denominator__ ` and `denominator`.

> [@pf\_moore](#):
>
> What’s not obvious from this proposal is why this has suddenly become an issue for SageMath now

No particular reason: somebody posted it as a bug report, that’s all. Personally, I don’t think that PEP 3141 matters that much. But given that SageMath has a rational numbers class, it seems like it should support PEP 3141 but it cannot.

> [@pf\_moore](#):
>
> some of which might well involve changes to SageMath, of course

Sure, as long as it won’t involve massively breaking backwards compatibility.

---

_[View the full topic](https://discuss.python.org/t/pep-3141-ratio-instead-of-numerator-denominator/2037)._
