[issue47079] Integral.denominator shouldn't return an int

2022-03-27 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
resolution:  -> not a bug
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



[issue47079] Integral.denominator shouldn't return an int

2022-03-27 Thread Sergey B Kirpichev


Sergey B Kirpichev  added the comment:

> It does not satisfy your assumptions in msg416056.

Yes, but does it fits to assumptions of the numbers module?  To be fair, there 
is even no requirement, that numerator/denominator are Integral instances 
(#25619 address also this).

BTW, it seems, the numpy integer types break my guess that numerator and 
denominator must have same types (I doubt that anyone uses numbers.Integral 
defaults, there are no tests for them in the CPython itself):
>>> a = numpy.int8(2); a
2
>>> type(a)

>>> type(a.numerator)

>>> type(a.denominator)

>>> type(a + a.denominator)

>>> type(a.denominator + a)

>>> type(a + a)


If this is an expected behaviour for Integral types - feel free to close the 
bugreport.  Looks odd for me, however.

--

___
Python tracker 

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



[issue47079] Integral.denominator shouldn't return an int

2022-03-27 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

It does not satisfy your assumptions in msg416056. So you have either correct 
your assumptions, or change the implementation of __add__, or change the 
implementation of denominator in your code.

--

___
Python tracker 

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



[issue47079] Integral.denominator shouldn't return an int

2022-03-26 Thread Sergey B Kirpichev


Sergey B Kirpichev  added the comment:

> Integral.__add__ is an abstract method, so it is a problem of your 
> implementation.

But such an implementation does satisfy all assumptions of the Integral abc, 
correct?

--

___
Python tracker 

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



[issue47079] Integral.denominator shouldn't return an int

2022-03-26 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Integral.__add__ is an abstract method, so it is a problem of your 
implementation.

--

___
Python tracker 

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



[issue47079] Integral.denominator shouldn't return an int

2022-03-26 Thread Sergey B Kirpichev


Sergey B Kirpichev  added the comment:

> The module documentation should not contain all historical reasons of every 
> design decision.

Sure.  But, for example, there should be an explanation of why 
foo+foo.denominator could produce an error for a valid implementation of the 
Integral abc.  Such interoperability is not assumed by the docs, according to 
provided examples 
(https://docs.python.org/3/library/numbers.html#implementing-the-arithmetic-operations).

> One of reasons is that type(self) not always have a constructor with 
> compatible interface.

I hardly can imagine a constructor for the Integral type, which doesn't accept 
a python integer as an argument.

--

___
Python tracker 

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



[issue47079] Integral.denominator shouldn't return an int

2022-03-26 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

The module documentation should not contain all historical reasons of every 
design decision. If you are interesting why something was done in one way or 
another, do your research.

One of reasons is that type(self) not always have a constructor with compatible 
interface. So it may work for your integer-like type, but in general case.

--

___
Python tracker 

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



[issue47079] Integral.denominator shouldn't return an int

2022-03-26 Thread Sergey B Kirpichev


Sergey B Kirpichev  added the comment:

> There is no "why".

Why not?  Apparently, this is a documentation error, at least.  (And I doubt 
there are tests for default methods.)

> If you are interesting "why", try to search old archives for the history of 
> creating that module.

Thanks.  Sorry, I'll try harder.  So far I've found nothing to explain me why 
the Integral.denominator must be an 'int'.

--

___
Python tracker 

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



[issue47079] Integral.denominator shouldn't return an int

2022-03-26 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

There is no "why". There is a fact that there is no such constrain. Adding a 
new constrain may break existing code. If you want to add a constrain, add it 
in you code.

If you are interesting "why", try to search old archives for the history of 
creating that module. Maybe you will find something. Maybe you will need to dip 
deeper, in discussions about abstract classes and protocols.

--

___
Python tracker 

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



[issue47079] Integral.denominator shouldn't return an int

2022-03-26 Thread Sergey B Kirpichev


Sergey B Kirpichev  added the comment:

> There is no such constrain.

Why not?  Any example where it does make sense to have different types for 
numerator and denominator?

--

___
Python tracker 

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



[issue47079] Integral.denominator shouldn't return an int

2022-03-26 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

There is no such constrain. And no default implementation in this module 
depends on the constructor. It is important, the constructor is not the part of 
interfaces.

If you want to return the same type in denominator, just override it in your 
class.

--

___
Python tracker 

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



[issue47079] Integral.denominator shouldn't return an int

2022-03-26 Thread Sergey B Kirpichev


Sergey B Kirpichev  added the comment:

> How would it work for bool or IntEnum?

Neither subclass the Integral abc.

The constraint (for which I care about) is: numerator/denominator should have 
same types.  The default implementation, which I propose: it's the same type as 
the given Integral implementation.

--

___
Python tracker 

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



[issue47079] Integral.denominator shouldn't return an int

2022-03-25 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

How would it work for bool or IntEnum?

--
nosy: +lemburg, mark.dickinson, stutzbach

___
Python tracker 

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



[issue47079] Integral.denominator shouldn't return an int

2022-03-25 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

Raymond and Serhiy, you were the last two active devs to touch numbers.py.

--
nosy: +rhettinger, serhiy.storchaka, terry.reedy

___
Python tracker 

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



[issue47079] Integral.denominator shouldn't return an int

2022-03-21 Thread Sergey B Kirpichev


Change by Sergey B Kirpichev :


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

___
Python tracker 

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



[issue47079] Integral.denominator shouldn't return an int

2022-03-20 Thread Sergey B Kirpichev


Sergey B Kirpichev  added the comment:

> self(1) instead

or, rather, type(self)(1)

--

___
Python tracker 

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



[issue47079] Integral.denominator shouldn't return an int

2022-03-20 Thread Sergey B Kirpichev


New submission from Sergey B Kirpichev :

As the __int__() method is required, I believe it can return self(1) instead.

Also, probably +self normalization could be avoided in the Integral.numerator().

--
components: Library (Lib)
messages: 415660
nosy: Sergey.Kirpichev
priority: normal
severity: normal
status: open
title: Integral.denominator shouldn't return an int
type: behavior
versions: Python 3.11

___
Python tracker 

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