This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pablogsal
Recipients Mark.Shannon, christian.heimes, oleksandr.suvorov, pablogsal
Date 2020-05-22.20:17:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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.
Date User Action Args
2020-05-22 20:17:04pablogsalsetrecipients: + pablogsal, christian.heimes, Mark.Shannon, oleksandr.suvorov
2020-05-22 20:17:03pablogsalsetmessageid: <>
2020-05-22 20:17:03pablogsallinkissue40728 messages
2020-05-22 20:17:03pablogsalcreate