I really don't get what you hope for. The 'raise' statement already exists in Python. I don't need a different way to spell that. So does 'if'.
On Sat, Sep 11, 2021, 2:37 PM Juancarlo Añez <apal...@gmail.com> wrote: > David, > > It seems I didn't state clearly enough my original statement, which is > that software will *_always_ *fail, even because of faulty hardware > components, or cosmic rays. > > For software to be resilient, it must assert it's expected state. > > But that doesn't have to be with the *assert* statement, perhaps less so > when the Python tradition is that those go away with just a "-O". > > I won't vouch for an *"invariant"* statement, because that's probably too > much to ask for. > > So I'll just use *"if"* to assert more invariants in the code I write. > > Cheers, > > On Sat, Sep 11, 2021 at 2:05 PM David Mertz, Ph.D. <david.me...@gmail.com> > wrote: > >> On Sat, Sep 11, 2021 at 9:20 AM Juancarlo Añez <apal...@gmail.com> wrote: >> >>> I'm happy about dropping the DBC theme and rebooting to make *assert* easier >>> to use so it gets used more. >>> >> >> I agree with Steven, Marc-Andé, and others in seeing "using assertions >> more" as an anti-goal. >> >> This isn't to say that a given program should have fewer—nor more—lines >> that start with `assert`. Rather, assertions should be use to ASSERT >> conditions that should NEVER be violated. They are NOT to check whether >> user input is bad. Nor whether a disk is unreliable. Nor whether a >> computation takes too long. Nor whether a value is outside of a useful >> range. Nor any of the other things that regular exception handling is well >> designed for. >> >> If for some reason you find yourself completely unable to write "if not >> (condition_to_check): ..." for mysterious reasons, you could use assert >> this way (but don't): >> >> >>> try: >> ... assert 2+2==5, "Bad arithmetic" >> ... except AssertionError: >> ... print("Configuring stuff to log problem") >> ... raise >> ... >> Configuring stuff to log problem >> Traceback (most recent call last): >> File "<ipython-input-3-2a9bdbc65744>", line 2, in <module> >> assert 2+2 == 5, "Bad arithmetic" >> AssertionError: Bad arithmetic >> >> But again, that's bad code for the same reason your proposal would be bad >> code. Assertions have the entire purpose of being possible to disable, and >> to express conditions a programmer believes are *necessarily true*. >> >> >> -- >> Keeping medicines from the bloodstreams of the sick; food >> from the bellies of the hungry; books from the hands of the >> uneducated; technology from the underdeveloped; and putting >> advocates of freedom in prisons. Intellectual property is >> to the 21st century what the slave trade was to the 16th. >> > > > -- > Juancarlo *Añez* >
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/K3III7PNMM7AVKNIE7HS24Y2OMJ72L4L/ Code of Conduct: http://python.org/psf/codeofconduct/