A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2011-April/111039.html below:

[Python-Dev] the role of assert in the standard library ?

[Python-Dev] the role of assert in the standard library ? [Python-Dev] the role of assert in the standard library ?Barry Warsaw barry at python.org
Thu Apr 28 16:37:33 CEST 2011
On Apr 28, 2011, at 04:34 AM, Terry Reedy wrote:

>On 4/28/2011 3:54 AM, Tarek Ziadé wrote:
>> Hello
>>
>> I removed some assert calls in distutils some time ago because the
>> package was not behaving correctly when people were using Python with
>> the --optimize flag. In other words, assert became a full part of the
>> code logic and removing them via -O was changing the behavior.
>>
>> In my opinion assert should be avoided completely anywhere else than
>> in the tests. If this is a wrong statement, please let me know why :)

>My understanding is that assert can be used in production code but only to
>catch logic errors by testing supposed invariants or postconditions. It
>should not be used to test usage errors, including preconditions. In other
>words, assert presence or absence should not affect behavior unless the code
>has a bug.

I would agree.  Use asserts for "this can't possibly happen <wink>"
conditions.

-Barry
-------------- 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/20110428/58c85c34/attachment.pgp>
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4