[Python-ideas] pep8 clarification, conditional top-level class/function leading newlines

Dima Tisnek dimaqq at gmail.com
Sat Mar 2 14:53:15 CET 2013

I'm trying to figure out how to space following code according to pep-8:

    import x

    class A:
        def foo(self):
            # magic using x
except ImportError:
    import y
    # different magic, using y

typical conditions are try/except and if/elif/else, though I can
imagine a true hacker to wrap top-level definitions in with x,
possibly even for/else, while/else as well ;-)

PEP-8 states to separate top-level class and functions by 2 blank
lines and methods in a class by 1 blank line. This case falls into the
crack, it's neither strictly top-level, nor a sub-level.

option1: semantical, 2 lines before conditional top-levels

option2: legalist, 1 line before any indented top-level

pep8 tool only accepts option2

I think I would prefer option1; or explicitly leave it up user, then I
can call option1 pep-8 compliant and someone else call option2 pep-8
compliant as well.

What do you think or prefer?
Perhaps this was discussed ages ago and I can't find the traces?

Thanks, d.

More information about the Python-ideas mailing list