Skip to content

Commit

Permalink
Merge branch 'main' into feat/parens_in_getitem
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed May 25, 2023
2 parents 5901e52 + cd02c28 commit 25d98d5
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/diff_shades_comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ jobs:
- name: Try to find pre-existing PR comment
if: steps.metadata.outputs.needs-comment == 'true'
id: find-comment
uses: peter-evans/find-comment@034abe94d3191f9c89d870519735beae326f2bdb
uses: peter-evans/find-comment@a54c31d7fa095754bfef525c0c8e5e5674c4b4b1
with:
issue-number: ${{ steps.metadata.outputs.pr-number }}
comment-author: "github-actions[bot]"
body-includes: "diff-shades"

- name: Create or update PR comment
if: steps.metadata.outputs.needs-comment == 'true'
uses: peter-evans/create-or-update-comment@67dcc547d311b736a8e6c5c236542148a47adc3d
uses: peter-evans/create-or-update-comment@ca08ebd5dc95aa0cd97021e9708fcd6b87138c9b
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ steps.metadata.outputs.pr-number }}
Expand Down
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
- Implicitly concatenated strings used as function args are no longer wrapped inside
parentheses (#3640)
- Redundant parenthesis are removed from `__getitem__`/`__setitem__` calls (#3680)
- Remove blank lines between a class definition and its docstring (#3692)

### Configuration

<!-- Changes to how Black can be configured -->

- `.pytest_cache`, `.ruff_cache` and `.vscode` are now excluded by default (#3691)

### Packaging

<!-- Changes to how Black is packaged, such as dependency requirements -->
Expand All @@ -46,6 +49,8 @@

<!-- For example, Docker, GitHub Actions, pre-commit, editors -->

- Update GitHub Action to display black output in the job summary (#3688)

### Documentation

<!-- Major changes to documentation and policies. Small docs changes
Expand Down
7 changes: 4 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ branding:
runs:
using: composite
steps:
- run: |
- name: black
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
python $GITHUB_ACTION_PATH/action/main.py
python $GITHUB_ACTION_PATH/action/main.py | tee -a $GITHUB_STEP_SUMMARY
else
python3 $GITHUB_ACTION_PATH/action/main.py
python3 $GITHUB_ACTION_PATH/action/main.py | tee -a $GITHUB_STEP_SUMMARY
fi
env:
# TODO: Remove once https://github.com/actions/runner/issues/665 is fixed.
Expand Down
20 changes: 15 additions & 5 deletions action/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
describe_name = line[len("describe-name: ") :].rstrip()
break
if not describe_name:
print("::error::Failed to detect action version.", flush=True)
print("::error::Failed to detect action version.", file=sys.stderr, flush=True)
sys.exit(1)
# expected format is one of:
# - 23.1.0
Expand All @@ -53,15 +53,25 @@
)
if pip_proc.returncode:
print(pip_proc.stdout)
print("::error::Failed to install Black.", flush=True)
print("::error::Failed to install Black.", file=sys.stderr, flush=True)
sys.exit(pip_proc.returncode)


base_cmd = [str(ENV_BIN / "black")]
if BLACK_ARGS:
# TODO: remove after a while since this is deprecated in favour of SRC + OPTIONS.
proc = run([*base_cmd, *shlex.split(BLACK_ARGS)])
proc = run(
[*base_cmd, *shlex.split(BLACK_ARGS)],
stdout=PIPE,
stderr=STDOUT,
encoding="utf-8",
)
else:
proc = run([*base_cmd, *shlex.split(OPTIONS), *shlex.split(SRC)])

proc = run(
[*base_cmd, *shlex.split(OPTIONS), *shlex.split(SRC)],
stdout=PIPE,
stderr=STDOUT,
encoding="utf-8",
)
print(proc.stdout)
sys.exit(proc.returncode)
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Sphinx==6.1.3
docutils==0.19
sphinxcontrib-programoutput==0.17
sphinx_copybutton==0.5.2
furo==2023.3.27
furo==2023.5.20
2 changes: 1 addition & 1 deletion src/black/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DEFAULT_LINE_LENGTH = 88
DEFAULT_EXCLUDES = r"/(\.direnv|\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|venv|\.svn|\.ipynb_checkpoints|_build|buck-out|build|dist|__pypackages__)/" # noqa: B950
DEFAULT_EXCLUDES = r"/(\.direnv|\.eggs|\.git|\.hg|\.ipynb_checkpoints|\.mypy_cache|\.nox|\.pytest_cache|\.ruff_cache|\.tox|\.svn|\.venv|\.vscode|__pypackages__|_build|buck-out|build|dist|venv)/" # noqa: B950
DEFAULT_INCLUDES = r"(\.pyi?|\.ipynb)$"
STDIN_PLACEHOLDER = "__BLACK_STDIN_FILENAME__"
2 changes: 2 additions & 0 deletions src/black/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,8 @@ def _maybe_empty_lines(self, current_line: Line) -> Tuple[int, int]:
and self.previous_line.is_class
and current_line.is_triple_quoted_string
):
if Preview.no_blank_line_before_class_docstring in current_line.mode:
return 0, 1
return before, 1

if self.previous_line and self.previous_line.opens_block:
Expand Down
1 change: 1 addition & 0 deletions src/black/mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class Preview(Enum):
hex_codes_in_unicode_sequences = auto()
improved_async_statements_handling = auto()
multiline_string_handling = auto()
no_blank_line_before_class_docstring = auto()
prefer_splitting_right_hand_side_of_assignments = auto()
# NOTE: string_processing requires wrap_long_dict_values_in_parens
# for https://github.com/psf/black/issues/3117 to be fixed.
Expand Down
3 changes: 1 addition & 2 deletions src/blib2to3/pgen2/pgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class PgenGrammar(grammar.Grammar):


class ParserGenerator(object):

filename: Path
stream: IO[Text]
generator: Iterator[GoodTokenInfo]
Expand All @@ -39,7 +38,7 @@ class ParserGenerator(object):
def __init__(self, filename: Path, stream: Optional[IO[Text]] = None) -> None:
close_stream = None
if stream is None:
stream = open(filename)
stream = open(filename, encoding="utf-8")
close_stream = stream.close
self.filename = filename
self.stream = stream
Expand Down
58 changes: 58 additions & 0 deletions tests/data/preview/no_blank_line_before_docstring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
def line_before_docstring():

"""Please move me up"""


class LineBeforeDocstring:

"""Please move me up"""


class EvenIfThereIsAMethodAfter:

"""I'm the docstring"""
def method(self):
pass


class TwoLinesBeforeDocstring:


"""I want to be treated the same as if I were closer"""


class MultilineDocstringsAsWell:

"""I'm so far
and on so many lines...
"""


# output


def line_before_docstring():
"""Please move me up"""


class LineBeforeDocstring:
"""Please move me up"""


class EvenIfThereIsAMethodAfter:
"""I'm the docstring"""

def method(self):
pass


class TwoLinesBeforeDocstring:
"""I want to be treated the same as if I were closer"""


class MultilineDocstringsAsWell:
"""I'm so far
and on so many lines...
"""

0 comments on commit 25d98d5

Please sign in to comment.