[Python-Dev] Symmetry arguments for API expansion (original) (raw)

Guido van Rossum guido at python.org
Wed Mar 21 12:12:14 EDT 2018


Thank you! As you may or may not have noticed in a different thread, we're going through a small existential crisis regarding the usefulness of is_integer() -- Serhiy believes it is not useful (and even an attractive nuisance) and should be deprecated. OTOH the existence of dec_mpd_isinteger() seems to validate to me that it actually exposes useful functionality (and every Python feature can be abused, so that alone should not be a strong argument for deprecation).

On Wed, Mar 21, 2018 at 1:33 AM, Robert Smallshire <rob at sixty-north.com> wrote:

As requested on the bug tracker, I've submitted a pull request for isinteger() support on the other numeric types. https://github.com/python/cpython/pull/6121

These are the tactics I used to implement it: - float: isinteger() already exists, so no changes - int: return True - Real: return x == int(x). Although Real doesn't explicitly support conversation to int with int, it does support conversion to int with trunc. The int constructor falls back to using trunc. - Rational (also inherited by Fraction): return x.denominator == 1 as Rational requires that all numbers must be represented in lowest form. - Integral: return True - Decimal: expose the existing decmpdisinteger C function to Python as isinteger()


Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/ guido%40python.org

-- --Guido van Rossum (python.org/~guido) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20180321/38be76b3/attachment.html>



More information about the Python-Dev mailing list