Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty line handling when formatting typing stubs #1646

Merged
merged 2 commits into from Sep 10, 2020

Commits on Aug 29, 2020

  1. Fix empty line handling when formatting typing stubs

    Black used to erroneously remove all empty lines between non-function
    code and decorators when formatting typing stubs. Now a single empty
    line is enforced.
    
    I chose for putting empty lines around decorated classes that have empty
    bodies since removing empty lines around such classes would cause a
    formatting issue that seems to be impossible to fix.
    
    For example:
    
    ```
    class A: ...
    @some_decorator
    class B: ...
    class C: ...
    class D: ...
    
    @some_other_decorator
    def foo(): -> None: ...
    ```
    
    It is easy to enforce no empty lines between class A, B, and C.
    Just return 0, 0 for a line that is a decorator and precedes an stub
    class. Fortunately before this commit, empty lines after that class
    would be removed already.
    
    Now let's look at the empty line between class D and function foo. In
    this case, there should be an empty line there since it's class code next
    to function code. The problem is that when deciding to add X empty lines
    before a decorator, you can't tell whether it's before a class or a
    function. If the decorator is before a function, then an empty line
    is needed, while no empty lines are needed when the decorator is
    before a class.
    
    So even though I personally prefer no empty lines around decorated
    classes, I had to go the other way surrounding decorated classes with
    empty lines.
    ichard26 committed Aug 29, 2020
    Copy the full SHA
    6d3b722 View commit details
    Browse the repository at this point in the history

Commits on Sep 3, 2020

  1. Copy the full SHA
    50d1b3b View commit details
    Browse the repository at this point in the history