[Python-ideas] PEP 485: A Function for testing approximate equality

Guido van Rossum guido at python.org
Tue Jan 27 23:00:17 CET 2015


On Tue, Jan 27, 2015 at 1:18 PM, Chris Barker <chris.barker at noaa.gov> wrote:

> On Tue, Jan 27, 2015 at 10:37 AM, Guido van Rossum <guido at python.org>
> wrote:
>
I think my reasoning comes down to the same rule I often use to decide
>> whether we need one function or two -- if in every use case you always know
>> whether you need version A or version B, then it's better to have two
>> functions rather than a single one with a flag to request A or B.
>>
>> And isn't it the case that whenever you are comparing to zero, you *know*
>> that you are comparing to zero, and you *must* specify an absolute
>> tolerance (otherwise it's not a use case at all)?
>>
>
> I really appreciate this API design approach, and in this case I started
> out with that idea. But I think this is likely to be used where you need to
> test a bunch of values with single function/set of parameters. In
> TestCase.assertIsCloseTo, as well as home grown loops and comprehensions.
>

I assume you mean assertNotAlmostEqual
<https://hg.python.org/cpython/file/94d8524086bd/Lib/unittest/case.py#l525>.
This is actually the same misguided two-for-one design. You *must* specify
exactly one of delta or places, and the code takes a different path. Also,
it looks like both are actually absolute tolerance. So what argument are
you making here?

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


More information about the Python-ideas mailing list