On Wed, Jul 4, 2018 at 11:04 AM Steven D'Aprano <st...@pearwood.info> wrote: > Did you actually mean arbitrary simple statements? > > if import math; mylist.sort(); print("WTF am I reading?"); True: > pass
Yes. To quote PEP 572: "This is a tool, and it is up to the programmer to use it where it makes sense, and not use it where superior constructs can be used." > A more reasonable suggestion would be to only allow *assignments*, not > arbitrary simple statements. But that's another special case: I don't agree that it is more reasonable, for exactly the reasons you describe it to be surprising. > with one or more semicolon-separated statements between the "if" and the > condition: > > if statement; statement; condition: > > If we stick to the rule that semicolons separate statements, that means > we have: > > > if statement # SyntaxError > statement # okay > condition: # SyntaxError > > > If we don't want that, we need a new rule to treat semicolons > differently inside if statements that they're treated elsewhere. Yes. This is analogous to complaining that [1, 2, 3] should be a syntax error because clearly this is a tuple with three elements: "[1", "2", and "3]". In as far as it's a new parsing rule, it is a "special case" indeed. > If we applied this rule "allow statements separated by semicolons" > everywhere, we'd get this: [snip] Nobody said anything about allowing semicolon-delimited statements in arbitrary places in the grammar. -- Devin _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com