On Thu, Apr 12, 2018 at 7:21 PM, Kirill Balunov <kirillbalu...@gmail.com> wrote: > > I gain readability! I don't see any reason to use it in other contexts... > Because it makes the code unreadable and difficult to perceive while giving > not so much benefit. I may be wrong, but so far I have not seen a single > example that at least slightly changed my mind.
This is, in effect, your entire argument for permitting assignments only in certain contexts. "I can't think of any useful reason for doing this, so we shouldn't do it". But that means making the language grammar more complicated (both in the technical sense of the parser's definitions, and in the colloquial sense of how you'd explain Python to a new programmer), because there are these magic constructs that can be used anywhere in an expression, but ONLY if that expression is inside an if or while statement. You lose the ability to refactor your code simply to satisfy an arbitrary restriction to appease someone's feeling of "it can't be useful anywhere else". There are basically two clean ways to do this: 1) Create actual syntax as part of the while statement, in the same way that the 'with EXPR as NAME:' statement does. This means you cannot put any additional operators after the 'as NAME' part. It's as much a part of the statement's syntax as the word 'in' is in a for loop. 2) Make this a feature of expressions in general. Then they can be used anywhere that an expression can be. I've gone for option 2. If you want to push for option 1, go ahead, but it's a nerfed solution just because you personally cannot think of any good use for this. ChrisA _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/