[Python-Dev] Symmetry arguments for API expansion (original) (raw)
Robert Smallshire rob at sixty-north.com
Wed Mar 21 04:33:25 EDT 2018
- Previous message (by thread): [Python-Dev] Symmetry arguments for API expansion
- Next message (by thread): [Python-Dev] Symmetry arguments for API expansion
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
As requested on the bug tracker, I've submitted a pull request for is_integer() support on the other numeric types. https://github.com/python/cpython/pull/6121
These are the tactics I used to implement it:
float: is_integer() 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 dec_mpd_isinteger C function to Python as is_integer() -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20180321/620a07de/attachment.html>
- Previous message (by thread): [Python-Dev] Symmetry arguments for API expansion
- Next message (by thread): [Python-Dev] Symmetry arguments for API expansion
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]