annoying doctest problem

Mark Lawrence breamoreboy at yahoo.co.uk
Mon Jan 12 15:59:49 CET 2015


On 12/01/2015 13:00, Steven D'Aprano wrote:
> Skip Montanaro wrote:
>
>> ISTR that when Tim Peters first implemented first, the typical way you
>> were expected to get tests into a doc string was to copy from an
>> interactive session, which would not have this problem.
>
> I believe that is still documented as the way to generate doctests.
>
>> Also, to Steven's comment about fussiness, it isn't so much that it's
>> fussy. It's more that it's dumb. I just does a simple string comparison of
>> the expected and actual outputs. It would be impossible for doctest to
>> know whether the expected output was something like repr or str output,
>> and thus safe to exchange single for double (don't forget to escape other
>> embedded quotes!), or was some sort of user-generated string, perhaps
>> intended to be
>> text in  another programming language which has different quoting rules
>> than Python. Therefore, fussy (or dumb) is exactly what you want.
>
> I didn't mean to give the impression that doctest was wrong to be fussy, or
> dumb if you prefer. I think it's exactly the right behaviour.
>

If doctest is dumb then that's clearly down to the author.  Perhaps we 
should refer him or her to the Zen of Python so they don't repeat the 
mistake with future design decisions?

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence




More information about the Python-list mailing list