[Python-Dev] PEP 572 and assert

Guido van Rossum guido at python.org
Tue Jul 17 12:54:36 EDT 2018


On Tue, Jul 17, 2018 at 9: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.
>
> We can't make the assignment expression itself creating its own scope,
> because this will invalidate its purpose. But the problem with assert
> ccould be solved by making assert creating a new lexical scope.
>
>     assert expr, msg
>
> could be translated to
>
>     if __debug__ and not (lambda: expr)():
>         raise AssertionError(msg)
>
> instead of
>
>     if __debug__ and not expr:
>         raise AssertionError(msg)
>

I don't believe this "problem" needs to be solved.

It seems to be you are seeking an excuse to reopen the acrimonious PEP 572
discussion. Please stop.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20180717/b61ca97e/attachment.html>


More information about the Python-Dev mailing list