This is very personal preference I don't feel it pythonic but... Ruby make return keywork optional so is very idiomatic (in Ruby) to have multiple onliner early return with this kind of guards at beginning of methods and a "main" case below 

For me this is just eye preference, we have eyes trained to extract what is important when reading code. There is no absolute more readable that works for everyone

IMHO return if cond is more scannable than

if cond:

Which need eye to scroll to next line

Here is an example of the use case that I'm talking about

def foo():
  if a:
  if B:
  if C:



def foo():
   return if a
   return if B
   return if C

The second is much more compact


if A: return 

Well, I'm strongly against these non-indented blocks in python

Em qui, 18 de jun de 2020 13:36, Barry Scott <> escreveu:

On 18 Jun 2020, at 13:30, Daniel. <> wrote:

I love the do_stuff if cond syntax in Ruby and in perl. It's very natural to real, much more to follow than if cond: do_stuff

I on the other hand hate that syntax and find it harder to read.

Why put the code out of sequence?

if read_this_1st: read_this_2nd()

vs. this that I think of as out of sequence order

read_this_2nd() if not read_this_1st


But still I don't think that it is enough to demand a language change.

Something near this is to have a default of none for 

A if B else None

So we can ommit the else None part, but this goes against the explicit is better than implicit 

Em qua, 17 de jun de 2020 07:42, Paul Moore <> escreveu:
On Wed, 17 Jun 2020 at 10:44, artem6191 <> wrote:
> So yeah, we can "if <expression>: return", but why not?

That's the wrong question. The correct question is "why is this
needed, and is the need sufficiently pressing to justify the change to
the language?"

You're talking about allowing "return EXPR if CONDITION" as an exact
equivalent of "if CONDITION: return EXPR". There isn't even a benefit
of "it saves a line of code", so it's very hard to see a

Python-ideas mailing list --
To unsubscribe send an email to
Message archived at
Code of Conduct:
Python-ideas mailing list --
To unsubscribe send an email to
Message archived at
Code of Conduct: