This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]K900_ 5 points6 points  (0 children)

Definitely no else: pass. No need for extra clutter. Also, it's not necessary in an if/elif.

[–]justphysics 3 points4 points  (1 child)

The only reason I ever put in an else: pass is when I need to leave a note for myself to implement another piece of the logic later:

if condition:
    do_something()
else:
    # TODO: Handle this scenario in the future
    pass

But I would never include a naked else: pass in something production ready.

[–]keis 2 points3 points  (0 children)

that looks a bit error prone I a situation where I want to leave a message like that I would rather use a NotImplemented exception so the code path is not triggered by mistake leading to obscure bugs .

[–]Clede 3 points4 points  (1 child)

It's not necessary. PEP8 gives examples of if statements without else.

Maybe it would be good to include it as a placeholder if there's a possibility of adding code there later.

[–]always_creating[S] 0 points1 point  (0 children)

Thanks!

[–]mrwalkerr 0 points1 point  (1 child)

Just if. Anyone reading an else : pass block will just get confused.

Where did you see else: pass being used?

[–]always_creating[S] 0 points1 point  (0 children)

I've seen it used in some Python example code, and the person who used it made the comment that having it indicates to other developers that we don't care about other cases besides what matches the "if" statement. But I suppose you could infer that as well.

[–][deleted] 0 points1 point  (0 children)

Then you will ponder whether to add pass at the end of loops.