[Python-Dev] (#19562) Asserts in Python stdlib code (datetime.py)

Barry Warsaw barry at python.org
Mon Nov 18 03:50:37 CET 2013

On Nov 17, 2013, at 11:05 PM, Maciej Fijalkowski wrote:

>My problem with -O and -OO is that their arguments are very circular.
>Indeed, I understand the need why you would want in certain and
>limited cases to remove both docstrings and asserts. So some options
>for doing so are ok. But a lot of arguments I see are along the lines
>of "don't use asserts because -O removes them". If the option was
>named --remove-asserts, noone would care, but people care since -O is
>documented as "do optimizations" and people *assume* this is what it
>does (makes code faster) and as unintended consequence removes

The reason I want to split them is more because I'd like an option to remove
docstrings but not asserts.  As others have also said, I use asserts for
conditions that can't possibly happen (or so I think).  E.g. using an
if/elif on an enumeration where the else should never be hit.  Or saying that
after some calculation, this variable can never be None.  In a sense,
assertions are executable documentation about the state of behavior at a
particular line of code.  If an assert ever *does* get triggered, it means you
didn't understand what you wrote.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-dev/attachments/20131117/8dc29336/attachment.sig>

More information about the Python-Dev mailing list