[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] PEP 572 and assert

On Wed, Jul 18, 2018 at 2:24 AM, Serhiy Storchaka <storchaka at gmail.com> wrote:
> 17.07.18 18:48, Guido van Rossum ????:
>> On Tue, Jul 17, 2018 at 8:28 AM, Serhiy Storchaka <storchaka at gmail.com
>> <mailto:storchaka at gmail.com>> wrote:
>>     Should not the assert statement introduce an implicit lexical scope
>>     for preventing leaking variables?
>> I don't see why. As Chris said, side effects in asserts are nothing new
>> and this PEP is not the one to do something about it.
> This side effect is new. No other expressions that can be used in asserts
> leaked local variables before. The only exception is list comprehensions in
> Python 2, and this was fixed in Python 3.

There are plenty of expressions that have side effects, though.
Creating local variables is just one type of side effect. If
assertions are being misused, that is the fault of people writing bad
assertions, not of assignment expressions, dict.setdefault(),
subprocess.call(), or any other operation.

Point of interest: You're basically asking for statement-local
assignment, which was one of PEP 572's earliest forms. It received
even more backlash than the current version did. The wheel turns and
the same spoke comes up...