New dedent symbol !;

Hi. I request a DEDENT symbol like !; so we can make one line programs.

To indent you write ;

To dedent you write !;

Example program:

    assert False
except AssertionError:

Current one line code is not possible:

try:print("Test");assert False
except AssertionError:print("Except")

After new symbol:

try:print("Test");assert False!;except AssertionError:print("Except")

That would allow people to write ugly, dense, and less readable code.
The first, sixth, and seventh lines of The Zen of Python want the opposite.


Why would it be a good thing to allow oneliners like that?
Also it’s really hard to understand in your example where the blocks start and end.


That can be said for the ; symbol too but this is already implemented in the language.


Do you find that ; is used anywhere outside of python -c 'import X; do something quick with X' contexts? I never encounter it elsewhere.

Once you start needing code blocks, one-liners seem counter-productive. In any case, ; has a clear enough meaning from essentially all other languages, which aids its readability. !; does not. There is also already a proposal for !: PEP 638 – Syntactic Macros |

This doesn’t seem likely to gain any traction.


The proposal should be ; followed by as many !s as needed. That aside, it is pretty fundamental to Python’s visual design that suite keywords must be the first word on a line.

While I agree with your assessment, I don’t think quoting the zen is helpful. It’s a nice poem but any good arguments against or for an idea should not need it as a source :slight_smile:


It is perhaps a great idea for a new programming language.


This proposal seems to be isomorphic to various other alternatives to
indentation that have appeared from time to tme.

To find out what the Python developers think about such things, execute

from future import braces

It’s a 14-year-old Easter Egg

It’s a bit older than that :slight_smile:

Yes, 24 years!

1 Like

IIRC, the Python IRC channel on FreeNode had (is it still operational?) a bot that would take one-liner input and re-indent it and upload it to a pastebin site. Its convention was to interpret additional consecutive semicolons as dedents after the first.


I have an alternative: use parentheses.

Make lparen after : start a block without significant whitespace and the matching rparen close it. Within this block, multiple consecutive statements must be separated by semicolons and any colon must be followed by lparen.

for i in range(10): (if i % 3: (print(“.”)) else: (print(“*”))

Technically, after a colon there is an ambiguity between a block containing a single statement expression and a statement expression consisting of a parenthesized expression. But it doesn’t really matter because they are effectively the same.

In python significant whitespace is already disabled inside parentheses and expressions can span multiple lines. This extends it to statements, too. Assuming this idea is deemed worth implementing, think this is a better syntax for it.

This would be a breaking change. Currently,

for i in range(10): (x for x in "foo")

is a valid, if useless, loop that repeatedly defines and discards a generator expression. Under your proposal, it would become a syntax error, equivalent to

for i in range(10):
    x for x in "foo"

Yes, I am aware of this and I should have pointed it out.