Movatterモバイル変換


[0]ホーム

URL:


[Python-ideas] add a always turn on "assert"

语言破碎处mlet_it_bew at 126.com
Tue Feb 28 21:44:22 EST 2017


"assert" is good, but it is used as a guard frequently.We can make such usage legal by adding a new syntax:    assert bool_expr, ExceptionType, Truesuggest reasons:1) even "__debug__" turn off, assert is working    assertion as guard.2) to avoid boilerplate code    I write code like this:        if pred(....) or pred(....):            raise ValueError('pred(....) or pred(....)')    Simplifed:        assert pred(...), ValueError, True        # the above line will be printed when error.        # I need not to copy the condition!3) future: "assert bool_expr, ET, False"    To aid static tool, like Proof System.    Better document.        For complicate algorithm,        I actually add a invariant outline comment        above every statement.-------------- next part --------------An HTML attachment was scrubbed...URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170301/0283f80b/attachment-0001.html>


More information about the Python-ideasmailing list

[8]ページ先頭

©2009-2026 Movatter.jp