Skip to content

Inconsistent spacing around top level functions #647

@zmwangx

Description

@zmwangx

Operating system: macOS 10.14.2
Python version: 3.7.1
Black version: 18.9b0
Does also happen on master: yes


I have a bit of OS-specific code that looks like this (when formatted by black):

import os

if os.name == "posix":
    import termios

    def foo():
        pass


elif os.name == "nt":
    try:
        import msvcrt

        def foo():
            pass

    except ImportError:

        def foo():
            pass


else:

    def foo():
        pass


other_code()

Note now foo has two empty lines below it most of the time (including in if..elif..else), except in the try block of a try..except.

Is this intentional? Seems to me there's no need to waste an extra line when the function definition is in any block; one empty line should be enough.

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: empty linesWasting vertical space efficiently.S: acceptedThe changes in this design / enhancement issue have been accepted and can be implementedT: styleWhat do we want Blackened code to look like?T: user supportOP looking for assistance or answers to a question

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions