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

Robert Smallshire report at bugs.python.org
Sat Mar 10 13:28:00 EST 2018


Robert Smallshire <rob at sixty-north.com> 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 is succinctly demonstrated by this example:

  >>> (10 ** -2).is_integer()
  False
  >>> (10 ** 2).is_integer()
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  AttributeError: 'int' object has no attribute 'is_integer'

I hear the argument about Python being harder to learn if more methods are supported on the built-in types - and perhaps float.is_integer should never have been added, but now its there, but I think Python is harder to learn and teach in the presence of these differences. Is is harder to learn "Real numbers support an is_integer() method", than it is "float supports an is_integer() method"?

I'm happy to put in the work bring my original patches up-to-date, or create a PR depending on what current process is.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue26680>
_______________________________________


More information about the Python-bugs-list mailing list