Ian Kelly <ian.g.ke...@gmail.com>:

> Although to be honest I'd rather use something like "raise
> RuntimeError('Unreachable code reached')" than "assert False" here. If
> the expectation is that the code will never be executed, then there's
> no reason to ever optimize it out.

Asserts have nothing to do with them being optimized out. Asserts are
communication.

Apart from idiomatic style, there is no difference between

    # never reached

    assert False

    raise RuntimeError('Unreachable code reached')

    1 / 0

    print("Hello world")

since, after all, that line is never reached!

Out of these variants, I find

    assert False

to be the most tasteful. It is concise, to the point and provided by the
core language. If it didn't exist, I'd have to resort to one of the
other alternatives.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to