[Python-ideas] An Alternate Suite Delineation Syntax For Python? (was Re: [Python-Dev] [PATCH] Adding braces to __future__)

Masklinn masklinn at masklinn.net
Sat Dec 10 12:50:08 CET 2011

On 2011-12-10, at 12:32 , Paul Moore wrote:
> - The code is pretty ugly, and certainly an attractive nuisance for
> obfuscated code, but I can't think of a better syntax
There are always the possibilities of keeping the colon as a start
token and using an other un-matched token as an end.

An other possibility (with some precedent in generator comprehensions)
would be to declare current statements to be expressions (and define
their expressive semantics) and surround them with parens for
disambiguation purposes when necessary.

> - Given that it effectively replaces lambdas and if expressions, it
> partly violates OOWTDI
For lambdas, as far as I can tell `def` would still require `return`,
it is pretty common for languages to provide a shorter form for
single-expression bodies. Of course, this could also be resolved by
converting defs to implicit returns and removing `lambda` altogether.
This change, however, would break a lot of code.

> - and it does so in a way that could encourage
> people to still propose try or with expressions ("they are as common
> as conditionals, so why not?")
Considering these are both included in Nick's proposal (which is a
general transformation on existing statements, not a special-cased
expressive form of some), I don't think that is a valid objection:

On 2011-12-10, at 06:06 , Nick Coghlan wrote:
> Some examples:
>  Try expressions:
>    x = {: try {: y.hello} except AttributeError {: "world!"}}
>  With expressions:
>    data = {: with open(fname) as f {: f.read()}}

More information about the Python-ideas mailing list