[issue27975] math.isnan(int) and math.isinf(int) should not raise OverflowError

Tim Peters report at bugs.python.org
Tue Sep 6 14:18:24 EDT 2016


Tim Peters added the comment:

The only sane way to do things "like this" is to allow types to define their own special methods (like `__isnan__()`), in which case the math module defers to such methods when they exist.  For example, this is how `math.ceil(Fraction)` works, by deferring to `Fraction.__ceil__()`.  The math module itself knows nothing else about what `ceil(Fraction)` could possibly mean.  All it knows is "if the type has __ceil__ use that, else convert to float first".

I'm also -1 on adding masses of if/else if/else if/.../else constructs to the math module to build in knowledge of the builtin numeric types.  Do it "right" or not at all.

I'd just be -0 on adding masses of new __isnan__, __isinf__, ..., special methods.  They're just not useful enough often enough.

----------
nosy: +tim.peters

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27975>
_______________________________________


More information about the Python-bugs-list mailing list