[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2020-10-06 Thread Raymond Hettinger
Raymond Hettinger added the comment: No worries Robert. It's all part of the process :-) If it's okay with you. I would like to revert the incorrectly applied PR and then you can build a fresh, clean patch. Does that work for you? -- ___

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2020-10-06 Thread Guido van Rossum
Change by Guido van Rossum : -- assignee: gvanrossum -> rhettinger nosy: -gvanrossum ___ Python tracker ___ ___ Python-bugs-list

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2020-10-06 Thread Robert Smallshire
Robert Smallshire added the comment: First, I would like to apologise for the confusion I have inadvertently caused. I didn't see Raymond's question and Guido's clear response here about not modifying the numeric tower, as it came _long_ after activity had moved to GitHub, and code had been

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2020-10-06 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- priority: normal -> release blocker ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2020-10-06 Thread Mark Dickinson
Change by Mark Dickinson : -- nosy: -mark.dickinson ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2020-10-05 Thread Raymond Hettinger
Raymond Hettinger added the comment: > I would have assumed that it's only making a promise that it > registers all the methods and properties marked *abstract* in > the ABC. Do you have references to back up the stronger statement? The isn't some weird or incidental promise. It is the

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2020-10-05 Thread Mark Dickinson
Mark Dickinson added the comment: [Guido] > Possibly at some point in the future we can switch to using typing.Protocol > [...] Yes, I think there's an interesting wider problem here, that typing.Protocol might be the answer to. For numbers and collections.abc in the std. lib., I'm happy

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2020-10-05 Thread Mark Dickinson
Mark Dickinson added the comment: Ok, so we need to either (a) revert PR 6121 and then re-do the changes, without the changes to numbers.py, or (b) make a second PR to undo the numbers.py changes. I think there's (calendar) time available for option (b), but I'm not going to have bandwidth

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2020-10-05 Thread Mark Dickinson
Mark Dickinson added the comment: > When a concrete class registers with an ABC, it is making a promise that it > implements everything in the ABC. Ah, interesting. I would have assumed that it's only making a promise that it registers all the methods and properties marked *abstract* in the

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2020-10-04 Thread Guido van Rossum
Guido van Rossum added the comment: Possibly at some point in the future we can switch to using typing.Protocol, which requires neither registration nor explicit subclassing (it's like Hashable). This makes it easy for user code to define custom protocols as needed. So if you need something

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2020-10-04 Thread Raymond Hettinger
Raymond Hettinger added the comment: > How so? When a concrete class registers with an ABC, it is making a promise that it implements everything in the ABC so that client code can count on all the methods being present. That is the raison d'etre for abstract base classes. In general, we

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2020-10-04 Thread Mark Dickinson
Mark Dickinson added the comment: > That still amounts to making it a requirement for all numeric classes How so? I don't follow the reasoning here. -- ___ Python tracker

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2020-10-04 Thread Raymond Hettinger
Raymond Hettinger added the comment: > it was added as a concrete method, That still amounts to making it a requirement for all numeric classes, even ones that predate this patch. So existing classes that are registered will no longer comply with the ABC. In general, it's hard to add

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2020-10-04 Thread Mark Dickinson
Mark Dickinson added the comment: I interpreted "in the numeric tower" as meaning declared as an abstract method that all those registering with the class would have to implement. As you point out in msg350173, that would be problematic - adding new methods to published interfaces is pretty

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2020-10-03 Thread Raymond Hettinger
Raymond Hettinger added the comment: Mark, why did this get merged with is_integer() still in the numeric tower? I thought we had agreed not to do that. -- ___ Python tracker

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2020-10-01 Thread Mark Dickinson
Mark Dickinson added the comment: New changeset 58a7da9e125422323f79c4ee95ac5549989d8162 by Robert Smallshire in branch 'master': bpo-26680: Incorporate is_integer in all built-in and standard library numeric types (GH-6121)

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2019-08-22 Thread Guido van Rossum
Guido van Rossum added the comment: It should not go on the numeric tower. -- --Guido (mobile) -- ___ Python tracker ___ ___

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2019-08-22 Thread Raymond Hettinger
Raymond Hettinger added the comment: Guido, when you approved this did you intend for the numeric tower to be amended as well? We elected not to do so for as_integer_ratio() and the same choice should be made here (because it's hard to add methods to ABCs without breaking existing user

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2019-08-22 Thread Raymond Hettinger
Change by Raymond Hettinger : -- resolution: rejected -> versions: +Python 3.9 -Python 3.8 ___ Python tracker ___ ___

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2019-08-22 Thread Robert Smallshire
Robert Smallshire added the comment: > * no forward movement for a year and half For most of that year and a half my pull-request was sitting in Github awaiting review by two core devs, of which you Raymond, were one. I don't like to hassle

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2019-08-22 Thread Raymond Hettinger
Raymond Hettinger added the comment: Marking this as closed: * no forward movement for a year and half * opposition from multiple core devs Feel free to revive this if you truly think this is needed and want to get the debate going again. Also, expanding the numeric tower is always going

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-15 Thread Christian Heimes
Christian Heimes added the comment: /me bets his money on Stefan and Tim -- ___ Python tracker ___

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-15 Thread Tim Peters
Tim Peters added the comment: If you want to deprecate the method, bring that up on python-dev or python-ideas. It's inappropriate on the issue tracker (unless, e.g., you open a new issue with a patch to rip it out of the language). It's also inappropriate to keep on

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-15 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I am proposing to deprecate float.is_integer() and remove it in 3.10. After deprecating float.as_integer() we shouldn't bother about adding int.is_integer(). If this method is necessary in implementing various math libraries

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-15 Thread Tim Peters
Tim Peters added the comment: Serhiy, nobody is proposing to add float.as_integer(). It already exists: >>> (3.1).is_integer() False I already allowed I don't have a feel for how _generally_ useful it is, but you have at least my and Stefan's word for that the functionality

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-15 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I do not see a point in adding a function that will never be used correctly. -- ___ Python tracker

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-15 Thread Tim Peters
Tim Peters added the comment: [Raymond] > The OPs notion of "absurd" behavior implies a rule that > all float methods should be available for ints. That > would suggest the is_integer, hex, fromhex, and > as_integer_ratio would all need to propagate to the > other types as

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-15 Thread Facundo Batista
Change by Facundo Batista : -- nosy: -facundobatista ___ Python tracker ___ ___

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-15 Thread Robert Smallshire
Robert Smallshire added the comment: Serhiy, you asked for use cases, not uses. The former can exist without the latter. Use cases for is_integer() include all existing uses of x == int(x), or other less obvious means of detecting integer values. Folks try to use

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-15 Thread Stefan Krah
Change by Stefan Krah : -- nosy: -skrah ___ Python tracker ___ ___ Python-bugs-list

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-15 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: If float.is_integer() is useful in numerical code please give me few examples. I don't take your argument about mpd_as_integer() in the Decimal class. Decimal has a lot of methods which makes sense for Decimal. >>>

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-15 Thread Stefan Krah
Stefan Krah added the comment: libmpdec is an example of numerical code. I don't think anyone but you has argued that is_integer() is useless in numerical code. Whether it is float or decimal doesn't matter. I get the API-bloat argument, but I'm completely surprised

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-15 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: mpd_as_integer() is used internally in the Decimal class. Do you have use cases for it outside of the Decimal class? And the question was about using float.is_integer(). I have not found *any* sane example on GitHub. The most

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-15 Thread Stefan Krah
Stefan Krah added the comment: In effect: "!(Py_IS_FINITE(dx) && dx == floor(dx))" I don't understand why Robert is questioned so much. mpd_as_integer() (or rather the optimized version _mpd_isint() is used all over the place inside libmpdec's own numeric code.

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-15 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: math.factorial() doesn't use float.is_integer(). -- ___ Python tracker ___

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-15 Thread Robert Smallshire
Robert Smallshire added the comment: Python in effect contains an example itself. The math.factorial(x) function contains what is in-effect an is_integer() check as a guard. -- ___ Python tracker

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-15 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: The use case of is_integer() still is not clear. Could you give examples of the correct use of this method in real projects? -- ___ Python tracker

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-15 Thread Robert Smallshire
Change by Robert Smallshire : -- pull_requests: +5885 stage: needs patch -> patch review ___ Python tracker ___

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-12 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: As for StackOverflow links provided by Robert, it looks to me that float.is_integer() is always used improperly. If keep this method it would be worth to warn against improper use of it. Bad: (x/5).is_integer() Good:

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-12 Thread Robert Smallshire
Robert Smallshire added the comment: Thank you Raymond. I'll work up a PR shortly. -- ___ Python tracker ___

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-12 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I would rather deprecate float.is_integer() if it looks as a magnet of bad code. -- ___ Python tracker

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-12 Thread Raymond Hettinger
Raymond Hettinger added the comment: Robert, would you please update you patch and submit it to Github as a pull request. It is looking like this will likely go forward after all. -- stage: patch review -> needs patch

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-12 Thread Stefan Krah
Stefan Krah added the comment: I agree with Mark's mailing list statements: There is no ambiguity for decimal, given that the existing predicates ignore the context. -- ___ Python tracker

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-12 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: What is the use case of float.is_integer() at all? I haven't found its usages in large projects on GitHub. Only in playing examples where it is (mis)used in cases like (x/5).is_integer() (x % 5 == 0 is better) or

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-12 Thread Mark Dickinson
Mark Dickinson added the comment: Ongoing discussion here: https://mail.python.org/pipermail/python-dev/2018-March/152358.html -- ___ Python tracker

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-12 Thread Raymond Hettinger
Change by Raymond Hettinger : -- versions: +Python 3.8 -Python 3.6 ___ Python tracker ___

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-12 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: float.is_integer() was added 6f34109384f3a78d5f4f8bdd418a89caca19631e (unfortunately no issue number for looking at the discussion preceded it). I don't know reasons. The same changeset added implementations of

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-12 Thread Robert Smallshire
Robert Smallshire added the comment: Apologies for the email splurge. That's the first and last time I'll use the email interface to bugs.python.org. -- ___ Python tracker

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-12 Thread Robert Smallshire
Robert Smallshire added the comment: To respond to Raymond's points: 1) Nobody is suggesting that every float method should also be available on int. Clearly some methods on float are not applicable to int. 2) Taken narrowly, you're right that is_integer() does nothing

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-12 Thread Mark Dickinson
Mark Dickinson added the comment: One quibble with Raymond's response: > 2) Your use case is trivially solved in a portable, trivial, and readable > > way: > >a == int(a) For Decimal, I'd recommend using `a == a.to_integral_value()` instead. Using `a == int(a)`

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-10 Thread Raymond Hettinger
Raymond Hettinger added the comment: Sorry Robert, but I object to this going forward. 1) We do not and should not require that every float() method also be in int(): >>> set(dir(float)) - set(dir(int)) {'fromhex', 'hex', 'is_integer',

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2018-03-10 Thread Robert Smallshire
Robert Smallshire added the comment: I've recently run into this issue impeding duck-typing between int and float again, when used in conjunction the int.__pow__, which may variously return an int or float depending on the value - not the type - of the arguments. This

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2016-04-05 Thread Robert Smallshire
Robert Smallshire added the comment: Thanks Stefan for the illuminating example. I knew I shouldn't have strayed off-topic. -- ___ Python tracker ___

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2016-04-05 Thread Stefan Krah
Stefan Krah added the comment: On Tue, Apr 05, 2016 at 02:20:19PM +, Robert Smallshire wrote: > >> Were float to inherit from Rational, rather than Real ... > > > This would break the Liskov substitution principle. > > How so? Rational extends Real with only numerator, denominator and >

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2016-04-05 Thread Robert Smallshire
Robert Smallshire added the comment: >> Were float to inherit from Rational, rather than Real ... > This would break the Liskov substitution principle. How so? Rational extends Real with only numerator, denominator and __float__. Isn't the existence of float.as_integer_ratio demonstration

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2016-04-05 Thread Stefan Krah
Stefan Krah added the comment: On Tue, Apr 05, 2016 at 01:10:25PM +, Robert Smallshire wrote: > Were float to inherit from Rational, rather than Real ... This would break the Liskov substitution principle. -- ___ Python tracker

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2016-04-05 Thread Robert Smallshire
Robert Smallshire added the comment: Java makes no claim to have a numeric tower. Amongst the dynamic languages I surveyed Matlab (isinteger), Javascript ES6 (isInteger), PHP (is_integer), R (is.integer), TCL (is entier), and as we have seen Scheme (integer?) all have methods for testing for

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2016-04-04 Thread Raymond Hettinger
Raymond Hettinger added the comment: * For most users, this will just be noise (even the existing float method is rarely used). It is unimportant enough that Python existed without it for a very long time and it is unimportant enough that it didn't arise during the lengthy process of

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2016-04-04 Thread Stefan Krah
Stefan Krah added the comment: I agree that Robert's "absurdity" argument was unfortunate and could be reversed: Many people would consider an (10).is_integer() method absurd. I'm also only moderately interested in OOP or classification in general, but we *do* have a numeric tower modeled

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2016-04-04 Thread Robert Smallshire
Robert Smallshire added the comment: To be clear, I'm not arguing that is_integer is in the same category as hex and fromhex; is_integer is a mathematical property of the number, whereas hex and from hex are representational. Nobody expects interoperability of string representations of the

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2016-04-04 Thread Raymond Hettinger
Raymond Hettinger added the comment: FWIW, I think the reasoning in http://bugs.python.org/issue1093 applies here as well. The need is insufficient to warrant inclusion in the numeric tower and propagation to types like int and Fraction. -- ___

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2016-04-04 Thread Raymond Hettinger
Raymond Hettinger added the comment: > the functions are so simple and self-explanatory > that API-complexity does not really increase. It increases complexity because it will show-up everywhere including places where it makes little sense. One place is int objects where its meaning and

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2016-04-03 Thread Stefan Krah
Stefan Krah added the comment: I've been thinking about this, and I'm +1 for the change now. These structural typing issues for numbers come up regularly (see also msg257088), and the functions are so simple and self-explanatory that API-complexity does not really increase. In general, I

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2016-04-01 Thread Robert Smallshire
Robert Smallshire added the comment: As for whether the shortcut float.is_integer(x) was needed, it has different behavior to x==int(x) when x is either NaN or an infinity. We must even deal with two different exception types OverflowError or ValueError respectively for these two values on

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2016-04-01 Thread Stefan Krah
Stefan Krah added the comment: is_integer() is very important for writing new functions. libmpdec has it and it's used a lot inside mpdecimal.c. In this case though I assume Robert needs it for duck typing. -- ___ Python tracker

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2016-03-31 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Agree with Raymond. float.is_integer(x) is more efficient than x==int(x), but is this method used anywhere at all? It was added as a part of issue2224. -- nosy: +christian.heimes, serhiy.storchaka ___ Python

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2016-03-31 Thread Raymond Hettinger
Raymond Hettinger added the comment: One other thought: the name is_integer() is inconsistent with the nomenclature in numbers.py. Had this been included at the outset, its name would have been is_integral(). -- ___ Python tracker

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2016-03-31 Thread Raymond Hettinger
Raymond Hettinger added the comment: -0 I question whether we ever needed a short-cut for x==int(x). Adding this to the numeric tower would cause it to propagate broadly including the int type. To me, this seems like feature creep resulting in language bloat. The decimal module has been

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2016-03-31 Thread SilentGhost
Changes by SilentGhost : -- components: +Extension Modules nosy: +facundobatista, mark.dickinson, rhettinger, skrah stage: -> patch review versions: +Python 3.6 ___ Python tracker

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2016-03-31 Thread Robert Smallshire
Robert Smallshire added the comment: Adding the second patch file. -- Added file: http://bugs.python.org/file42336/is_integer_decimal.patch ___ Python tracker

[issue26680] Incorporating float.is_integer into the numeric tower and Decimal

2016-03-31 Thread Robert Smallshire
New submission from Robert Smallshire: When the useful float.is_integer method was added the opportunity was missed to incorporate this method into the numeric tower defined in numbers.py. This increased the API distance between different number types, making them less substitutable than