[issue37822] Add math.as_integer_ratio()

2019-08-12 Thread Jeroen Demeyer


Jeroen Demeyer  added the comment:

Aren't you worried about using the non-special non-reserved attributes like 
"as_integer_ratio"? That's the reason why I proposed a dunder name "__ratio__" 
instead of "as_integer_ratio".

In my opinion, it was a mistake in PEP 3141 to use non-reserved names like 
"numerator" and "denominator" because they might already be used by existing 
classes with a different meaning (this is precisely what happened with 
SageMath).

It's an honest question. If you say, "we thought about it and think it's just 
fine to use as_integer_ratio()", just say so and that's fine for me.

--
nosy: +jdemeyer

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37822] Add math.as_integer_ratio()

2019-08-11 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Guido decided to stick with the current approach of adding as_integer_ratio() 
as needed to concrete classes.  It is an optional API for user classes that 
register as numbers.Rational().  

See https://bugs.python.org/msg349404

--
resolution:  -> rejected
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37822] Add math.as_integer_ratio()

2019-08-11 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

-1 for having this spill into the math module.   We're already started down a 
different path; otherwise, there would have been no need to add the 
as_integer_ratio method to int/bool.  That was done so that 
x.as_integer_ratio() would work for all the concrete classes where it made 
sense.  Right now, the only concrete class that is missing the method is 
Fractions.  Adding it there is trivial and it doesn't garbage-up the math 
module with a pass-through function.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37822] Add math.as_integer_ratio()

2019-08-11 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
keywords: +patch
pull_requests: +14938
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/15210

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37822] Add math.as_integer_ratio()

2019-08-11 Thread Serhiy Storchaka


New submission from Serhiy Storchaka :

There are two interfaces to represent a number as a ratio. The numbers.Rational 
interface has two properties: numerator and denominator. float and Decimal do 
not support this interface, but they provide method as_integer_ratio() which 
return a 2-tuple (numerator, denominator).

I propose to add math.as_integer_ratio() which unites both interfaces: uses the 
as_integer_ratio() method if it is defined, and uses the numerator and 
denominator properties otherwise. It will help in applications that work with 
exact numbers (e.g. modules fractions and statistics).

--
components: Library (Lib)
messages: 349390
nosy: mark.dickinson, rhettinger, serhiy.storchaka, stutzbach
priority: normal
severity: normal
status: open
title: Add math.as_integer_ratio()
type: enhancement
versions: Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com