Pablo Galindo Salgado <pablog...@gmail.com> added the comment:

I don't think the examples you mention is proof of inconsistent behaviour:

> * list expressions do have their scope and do not overwrite local variables

comprehensions have their own scope in Python 3 and this is documented. General 
blocks (like normal loops, exceptions, with statements...etc don't have their 
own scope).

* with statement does overwrite the variable value but makes it available even 
after with block 

Yeah, but with statements do not have the problem of needing to break reference 
cycles in the exception names, so this does not apply. The same for any other 
"target" variable such as loop assignment (for x in ...).

* except overwrites variable value, but then the value gets cleaned and no 
longer accessible.

This is a consequence of the fact that when you do 'as varname' you are 
voluntary overwriting the previous value, therefore loosing whatever was there 
before. The semantics here are that the variable is not accessible outside the 
except block, which is unique to except blocks but this is needed to avoid 
circular references.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40728>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to