Skip to content

Commit

Permalink
Merge branch 'main' into async-new-line
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja committed Jan 2, 2024
2 parents fad3df2 + fe33761 commit 5b84510
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repos:
additional_dependencies: *version_check_dependencies

- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort

Expand All @@ -39,7 +39,7 @@ repos:
exclude: ^src/blib2to3/

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.1
rev: v1.8.0
hooks:
- id: mypy
exclude: ^docs/conf.py
Expand All @@ -58,13 +58,13 @@ repos:
- hypothesmith

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.3
rev: v4.0.0-alpha.8
hooks:
- id: prettier
exclude: \.github/workflows/diff_shades\.yml

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
- Fix bug where spaces were not added around parenthesized walruses in subscripts,
unlike other binary operators (#4109)
- Remove empty lines before docstrings in async functions (#4132)
- Address a missing case in the change to allow empty lines at the beginning of all
blocks, except immediately before a docstring (#4130)

### Configuration

Expand Down
5 changes: 4 additions & 1 deletion src/black/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,10 @@ def _maybe_empty_lines_for_class_or_def( # noqa: C901
if self.previous_line.depth < current_line.depth and (
self.previous_line.is_class or self.previous_line.is_def
):
return 0, 0
if self.mode.is_pyi or not Preview.allow_empty_first_line_in_block:
return 0, 0
else:
return 1 if user_had_newline else 0, 0

comment_to_add_newlines: Optional[LinesBlock] = None
if (
Expand Down
1 change: 1 addition & 0 deletions tests/data/cases/class_blank_parentheses.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def test_func(self):


class ClassWithEmptyFunc(object):

def func_with_blank_parentheses():
return 5

Expand Down
19 changes: 19 additions & 0 deletions tests/data/cases/preview_allow_empty_first_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ async def async_fn():

"""Docstring."""


def top_level(
a: int,
b: str,
) -> Whatever[Generic, Something]:

def nested(x: int) -> int:
pass

# output

def foo():
Expand Down Expand Up @@ -134,6 +143,7 @@ def quux():


class Cls:

def method(self):

pass
Expand All @@ -146,3 +156,12 @@ async def async_fn():
@decorated
async def async_fn():
"""Docstring."""


def top_level(
a: int,
b: str,
) -> Whatever[Generic, Something]:

def nested(x: int) -> int:
pass
1 change: 1 addition & 0 deletions tests/data/cases/preview_form_feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def bar(a=1, b: bool = False):


class Baz:

def __init__(self):
pass

Expand Down

0 comments on commit 5b84510

Please sign in to comment.