[issue37500] 3.8.0b2 no longer optimizes away "if 0:" ?

Pablo Galindo Salgado report at bugs.python.org
Fri Jul 5 17:45:51 EDT 2019


Pablo Galindo Salgado <pablogsal at gmail.com> added the comment:

> CPython has acted the current way for about 15 years (since 2.4 was released), and this is the first time anyone has raised an objection.

Although I tend to agree with your words, I have to insist that correctness in the reference implementation is very important, is not just a "pragmatic" thing. For example, under this argument, we could say that it does not matter if

def f():
  if 0:
    yield

should be or not a generator. But that changes things massively. It happens that it will always be a generator due to how we check for that property, but under this argument is ok if it is undefined.

This also makes the thing even more confusing as there are some syntax consequences of unreachable code, but no others. (Like the bytecode for that yield will be gone!!. Is impossible to know if that is a generator or not from the bytecode).

I have seen many people confused already and it makes very difficult to guess what are the consequences of code that is unreachable at runtime. For these reasons I think consistency is key.

I agree that the way this is done is not ideal, but we could not find a better way to do this :(

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37500>
_______________________________________


More information about the Python-bugs-list mailing list