Skip to content

Commit

Permalink
Merge branch 'main' into mypy-0.990
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed Dec 10, 2022
2 parents 5ac9e49 + 16b98ab commit 29b41f5
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 52 deletions.
3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[flake8]
ignore = E203, E266, E501, W503
# B905 should be enabled when we drop support for 3.9
ignore = E203, E266, E501, W503, B905
# line length is intentionally set to 80 here because black uses Bugbear
# See https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length for more details
max-line-length = 80
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/diff_shades_comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Try to find pre-existing PR comment
if: steps.metadata.outputs.needs-comment == 'true'
id: find-comment
uses: peter-evans/find-comment@b657a70ff16d17651703a84bee1cb9ad9d2be2ea
uses: peter-evans/find-comment@f4499a714d59013c74a08789b48abe4b704364a0
with:
issue-number: ${{ steps.metadata.outputs.pr-number }}
comment-author: "github-actions[bot]"
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/pypi_upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ jobs:
- os: macos-11
name: macos-x86_64
macos_arch: "x86_64"
- os: macos-11
name: macos-arm64
macos_arch: "arm64"
- os: macos-11
name: macos-universal2
macos_arch: "universal2"
# Only build x86_64 wheels on macos until #3312 is fixed
# - os: macos-11
# name: macos-arm64
# macos_arch: "arm64"
# - os: macos-11
# name: macos-universal2
# macos_arch: "universal2"

steps:
- uses: actions/checkout@v3
Expand Down
58 changes: 39 additions & 19 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,12 @@

<!-- Changes that affect Black's preview style -->

- Enforce empty lines before classes and functions with sticky leading comments (#3302)
- Reformat empty and whitespace-only files as either an empty file (if no newline is
present) or as a single newline character (if a newline is present) (#3348)
- Implicitly concatenated strings used as function args are now wrapped inside
parentheses (#3307)
- Correctly handle trailing commas that are inside a line's leading non-nested parens
(#3370)
- Fix a crash in preview style with assert + parenthesized string (#3415)

### Configuration

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

- Fix incorrectly applied .gitignore rules by considering the .gitignore location and
the relative path to the target file (#3338)
- Fix incorrectly ignoring .gitignore presence when more than one source directory is
specified (#3336)

### Packaging

<!-- Changes to how Black is packaged, such as dependency requirements -->
Expand All @@ -42,10 +31,6 @@

<!-- Changes to the parser or to version autodetection -->

- Parsing support has been added for walruses inside generator expression that are
passed as function args (for example,
`any(match := my_re.match(text) for text in texts)`) (#3327).

### Performance

<!-- Changes that improve Black's performance. -->
Expand All @@ -62,14 +47,49 @@

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

- Vim plugin: Optionally allow using the system installation of Black via
`let g:black_use_virtualenv = 0`(#3309)

### Documentation

<!-- Major changes to documentation and policies. Small docs changes
don't need a changelog entry. -->

## 22.12.0

### Preview style

<!-- Changes that affect Black's preview style -->

- Enforce empty lines before classes and functions with sticky leading comments (#3302)
- Reformat empty and whitespace-only files as either an empty file (if no newline is
present) or as a single newline character (if a newline is present) (#3348)
- Implicitly concatenated strings used as function args are now wrapped inside
parentheses (#3307)
- Correctly handle trailing commas that are inside a line's leading non-nested parens
(#3370)

### Configuration

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

- Fix incorrectly applied `.gitignore` rules by considering the `.gitignore` location
and the relative path to the target file (#3338)
- Fix incorrectly ignoring `.gitignore` presence when more than one source directory is
specified (#3336)

### Parser

<!-- Changes to the parser or to version autodetection -->

- Parsing support has been added for walruses inside generator expression that are
passed as function args (for example,
`any(match := my_re.match(text) for text in texts)`) (#3327).

### Integrations

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

- Vim plugin: Optionally allow using the system installation of Black via
`let g:black_use_virtualenv = 0`(#3309)

## 22.10.0

### Highlights
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Try it out now using the [Black Playground](https://black.vercel.app). Watch the
### Installation

_Black_ can be installed by running `pip install black`. It requires Python 3.7+ to run.
If you want to format Jupyter Notebooks, install with `pip install 'black[jupyter]'`.
If you want to format Jupyter Notebooks, install with `pip install "black[jupyter]"`.

If you can't wait for the latest _hotness_ and want to install from GitHub, use:

Expand Down
2 changes: 1 addition & 1 deletion docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Also, you can try out _Black_ online for minimal fuss on the
## Installation

_Black_ can be installed by running `pip install black`. It requires Python 3.7+ to run.
If you want to format Jupyter Notebooks, install with `pip install 'black[jupyter]'`.
If you want to format Jupyter Notebooks, install with `pip install "black[jupyter]"`.

If you can't wait for the latest _hotness_ and want to install from GitHub, use:

Expand Down
2 changes: 1 addition & 1 deletion docs/integrations/source_version_control.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Use [pre-commit](https://pre-commit.com/). Once you
```yaml
repos:
- repo: https://github.com/psf/black
rev: 22.10.0
rev: 22.12.0
hooks:
- id: black
# It is recommended to specify the latest version of Python
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ Sphinx==5.3.0
# Older versions break Sphinx even though they're declared to be supported.
docutils==0.19
sphinxcontrib-programoutput==0.17
sphinx_copybutton==0.5.0
sphinx_copybutton==0.5.1
furo==2022.9.29
4 changes: 2 additions & 2 deletions docs/the_black_code_style/current_style.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,8 @@ AST of the target. There are three limited cases in which the AST does differ:
1. _Black_ cleans up leading and trailing whitespace of docstrings, re-indenting them if
needed. It's been one of the most popular user-reported features for the formatter to
fix whitespace issues with docstrings. While the result is technically an AST
difference, due to the various possibilities of forming docstrings, all realtime use
of docstrings that we're aware of sanitizes indentation and leading/trailing
difference, due to the various possibilities of forming docstrings, all real-world
uses of docstrings that we're aware of sanitize indentation and leading/trailing
whitespace anyway.

1. _Black_ manages optional parentheses for some statements. In the case of the `del`
Expand Down
2 changes: 1 addition & 1 deletion docs/usage_and_configuration/the_basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ You can check the version of _Black_ you have installed using the `--version` fl

```console
$ black --version
black, version 22.10.0
black, version 22.12.0
```

An option to require a specific version to be running is also provided.
Expand Down
2 changes: 1 addition & 1 deletion src/black/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ def get_sources(

using_default_exclude = exclude is None
exclude = re_compile_maybe_verbose(DEFAULT_EXCLUDES) if exclude is None else exclude
gitignore: Optional[PathSpec] = None
gitignore: Optional[Dict[Path, PathSpec]] = None
root_gitignore = get_gitignore(root)

for s in src:
Expand Down
25 changes: 11 additions & 14 deletions src/black/brackets.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,26 +349,23 @@ def get_leaves_inside_matching_brackets(leaves: Sequence[Leaf]) -> Set[LeafID]:
Matching brackets are included.
"""
try:
# Only track brackets from the first opening bracket to the last closing
# bracket.
# Start with the first opening bracket and ignore closing brackets before.
start_index = next(
i for i, l in enumerate(leaves) if l.type in OPENING_BRACKETS
)
end_index = next(
len(leaves) - i
for i, l in enumerate(reversed(leaves))
if l.type in CLOSING_BRACKETS
)
except StopIteration:
return set()
bracket_stack = []
ids = set()
depth = 0
for i in range(end_index, start_index - 1, -1):
for i in range(start_index, len(leaves)):
leaf = leaves[i]
if leaf.type in CLOSING_BRACKETS:
depth += 1
if depth > 0:
ids.add(id(leaf))
if leaf.type in OPENING_BRACKETS:
depth -= 1
bracket_stack.append((BRACKET[leaf.type], i))
if leaf.type in CLOSING_BRACKETS:
if bracket_stack and leaf.type == bracket_stack[-1][0]:
_, start = bracket_stack.pop()
for j in range(start, i + 1):
ids.add(id(leaves[j]))
else:
break
return ids
2 changes: 1 addition & 1 deletion src/black/handle_ipynb_magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def jupyter_dependencies_are_installed(*, verbose: bool, quiet: bool) -> bool:
if verbose or not quiet:
msg = (
"Skipping .ipynb files as Jupyter dependencies are not installed.\n"
"You can fix this by running ``pip install black[jupyter]``"
'You can fix this by running ``pip install "black[jupyter]"``'
)
out(msg)
return False
Expand Down
14 changes: 14 additions & 0 deletions tests/data/preview/trailing_commas_in_leading_parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ def refresh_token(self, device_family, refresh_token, api_key):
== long_module.long_class.long_func()["some_key"].another_func(arg1)
)

# Regression test for https://github.com/psf/black/issues/3414.
assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx(
xxxxxxxxx
).xxxxxxxxxxxxxxxxxx(), (
"xxx {xxxxxxxxx} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
)


# output

Expand Down Expand Up @@ -72,3 +79,10 @@ def refresh_token(self, device_family, refresh_token, api_key):
long_module.long_class.long_func().another_func()
== long_module.long_class.long_func()["some_key"].another_func(arg1)
)

# Regression test for https://github.com/psf/black/issues/3414.
assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx(
xxxxxxxxx
).xxxxxxxxxxxxxxxxxx(), (
"xxx {xxxxxxxxx} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
)
4 changes: 2 additions & 2 deletions tests/test_no_ipynb.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_ipynb_diff_with_no_change_single() -> None:
result = runner.invoke(main, [str(path)])
expected_output = (
"Skipping .ipynb files as Jupyter dependencies are not installed.\n"
"You can fix this by running ``pip install black[jupyter]``\n"
'You can fix this by running ``pip install "black[jupyter]"``\n'
)
assert expected_output in result.output

Expand All @@ -32,6 +32,6 @@ def test_ipynb_diff_with_no_change_dir(tmp_path: pathlib.Path) -> None:
result = runner.invoke(main, [str(tmp_path)])
expected_output = (
"Skipping .ipynb files as Jupyter dependencies are not installed.\n"
"You can fix this by running ``pip install black[jupyter]``\n"
'You can fix this by running ``pip install "black[jupyter]"``\n'
)
assert expected_output in result.output

0 comments on commit 29b41f5

Please sign in to comment.