[Python-ideas] Dart-like method cascading operator in Python
Chris Angelico
rosuav at gmail.com
Thu Nov 21 15:19:57 CET 2013
On Fri, Nov 22, 2013 at 1:08 AM, Perešíni Peter <ppershing at gmail.com> wrote:
> Agree, this example is extra bad and unreadable. If we want cascading (and
> especially nested cascading), I would force cascading operator to be the
> first token on a new (and indented) line as in my examples
In that case, why have a separate cascade operator?
o = MyObject()
.set(x)
.set(y)
There is one problem with this syntax, though (whether it's a separate
operator or not): it makes parsing a little harder. The previous
statement looks complete, and then there's an indented block. Trying
to type this at the interactive interpreter will be awkward - there'll
need to be a way to tell it "Hey, there's more coming, don't finish
yet" even though there's nothing on that opening line that tells it
so. Would it be worth putting a colon at the end, as per if/while/etc?
o = MyObject():
.set(x)
.set(y)
The same considerations apply to editors that auto-indent, too; making
it clear that there's more to come is, imho, a Good Thing.
ChrisA
More information about the Python-ideas
mailing list