Skip to content

Commit

Permalink
Merge branch 'main' into jephron/conditional-expression-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra authored Dec 29, 2022
2 parents d876179 + 0abe85e commit 2fecc15
Show file tree
Hide file tree
Showing 16 changed files with 514 additions and 101 deletions.
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@f4499a714d59013c74a08789b48abe4b704364a0
uses: peter-evans/find-comment@81e2da3af01c92f83cb927cf3ace0e085617c556
with:
issue-number: ${{ steps.metadata.outputs.pr-number }}
comment-author: "github-actions[bot]"
Expand Down
15 changes: 14 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,26 @@ jobs:
tags: pyfound/black:latest,pyfound/black:${{ env.GIT_TAG }}

- name: Build and push latest_release tag
if: ${{ github.event_name == 'release' && github.event.action == 'published' }}
if:
${{ github.event_name == 'release' && github.event.action == 'published' &&
!github.event.release.prerelease }}
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: pyfound/black:latest_release

- name: Build and push latest_prerelease tag
if:
${{ github.event_name == 'release' && github.event.action == 'published' &&
github.event.release.prerelease }}
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: pyfound/black:latest_prerelease

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
2 changes: 1 addition & 1 deletion .github/workflows/pypi_upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
- uses: actions/checkout@v3

- name: Build wheels via cibuildwheel
uses: pypa/cibuildwheel@v2.11.3
uses: pypa/cibuildwheel@v2.11.4
env:
CIBW_ARCHS_MACOS: "${{ matrix.macos_arch }}"

Expand Down
13 changes: 13 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,23 @@
<!-- Changes that affect Black's preview style -->

- Add parentheses around `if`-`else` expressions (#2278)
- Improve the performance on large expressions that contain many strings (#3467)
- Fix a crash in preview style with assert + parenthesized string (#3415)
- Fix crashes in preview style with walrus operators used in function return annotations
and except clauses (#3423)
- Fix a crash in preview advanced string processing where mixed implicitly concatenated
regular and f-strings start with an empty span (#3463)
- Fix a crash in preview advanced string processing where a standalone comment is placed
before a dict's value (#3469)
- Fix an issue where extra empty lines are added when a decorator has `# fmt: skip`
applied or there is a standalone comment between decorators (#3470)
- Do not put the closing quotes in a docstring on a separate line, even if the line is
too long (#3430)
- Long values in dict literals are now wrapped in parentheses; correspondingly
unnecessary parentheses around short values in dict literals are now removed; long
string lambda values are now wrapped in parentheses (#3440)
- Exclude string type annotations from improved string processing; fix crash when the
return type annotation is stringified and spans across multiple lines (#3462)

### Configuration

Expand Down Expand Up @@ -64,12 +73,16 @@
<!-- For example, Docker, GitHub Actions, pre-commit, editors -->

- Move 3.11 CI to normal flow now all dependencies support 3.11 (#3446)
- Docker: Add new `latest_prerelease` tag automation to follow latest black alpha
release on docker images (#3465)

### Documentation

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

- Expand `vim-plug` installation instructions to offer more explicit options (#3468)

## 22.12.0

### Preview style
Expand Down
2 changes: 1 addition & 1 deletion docs/contributing/issue_triage.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The lifecycle of a bug report or user support issue typically goes something lik
1. _the issue is waiting for triage_
2. **identified** - has been marked with a type label and other relevant labels, more
details or a functional reproduction may be still needed (and therefore should be
marked with `S: needs repro` or `S: awaiting reponse`)
marked with `S: needs repro` or `S: awaiting response`)
3. **confirmed** - the issue can reproduced and necessary details have been provided
4. **discussion** - initial triage has been done and now the general details on how the
issue should be best resolved are being hashed out
Expand Down
49 changes: 46 additions & 3 deletions docs/integrations/editors.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,51 @@ Configuration:
- `g:black_fast` (defaults to `0`)
- `g:black_linelength` (defaults to `88`)
- `g:black_skip_string_normalization` (defaults to `0`)
- `g:black_skip_magic_trailing_comma` (defaults to `0`)
- `g:black_virtualenv` (defaults to `~/.vim/black` or `~/.local/share/nvim/black`)
- `g:black_use_virtualenv` (defaults to `1`)
- `g:black_target_version` (defaults to `""`)
- `g:black_quiet` (defaults to `0`)
- `g:black_preview` (defaults to `0`)

#### Installation

This plugin **requires Vim 7.0+ built with Python 3.7+ support**. It needs Python 3.7 to
be able to run _Black_ inside the Vim process which is much faster than calling an
external command.

##### `vim-plug`

To install with [vim-plug](https://github.com/junegunn/vim-plug):

_Black_'s `stable` branch tracks official version updates, and can be used to simply
follow the most recent stable version.

```
Plug 'psf/black', { 'branch': 'stable' }
```
Another option which is a bit more explicit and offers more control is to use
`vim-plug`'s `tag` option with a shell wildcard. This will resolve to the latest tag
which matches the given pattern.
The following matches all stable versions (see the
[Release Process](../contributing/release_process.md) section for documentation of
version scheme used by Black):
```
Plug 'psf/black', { 'tag': '*.*.*' }
```
and the following demonstrates pinning to a specific year's stable style (2022 in this
case):
```
Plug 'psf/black', { 'tag': '22.*.*' }
```
##### Vundle
or with [Vundle](https://github.com/VundleVim/Vundle.vim):
```
Expand All @@ -134,6 +169,14 @@ $ cd ~/.vim/bundle/black
$ git checkout origin/stable -b stable
```

##### Arch Linux

On Arch Linux, the plugin is shipped with the
[`python-black`](https://archlinux.org/packages/community/any/python-black/) package, so
you can start using it in Vim after install with no additional setup.

##### Vim 8 Native Plugin Management

or you can copy the plugin files from
[plugin/black.vim](https://github.com/psf/black/blob/stable/plugin/black.vim) and
[autoload/black.vim](https://github.com/psf/black/blob/stable/autoload/black.vim).
Expand All @@ -148,9 +191,7 @@ curl https://raw.githubusercontent.com/psf/black/stable/autoload/black.vim -o ~/
Let me know if this requires any changes to work with Vim 8's builtin `packadd`, or
Pathogen, and so on.

This plugin **requires Vim 7.0+ built with Python 3.7+ support**. It needs Python 3.7 to
be able to run _Black_ inside the Vim process which is much faster than calling an
external command.
#### Usage

On first run, the plugin creates its own virtualenv using the right Python version and
automatically installs _Black_. You can upgrade it later by calling `:BlackUpgrade` and
Expand Down Expand Up @@ -187,6 +228,8 @@ To run _Black_ on a key press (e.g. F9 below), add this:
nnoremap <F9> :Black<CR>
```

#### Troubleshooting

**How to get Vim with Python 3.6?** On Ubuntu 17.10 Vim comes with Python 3.6 by
default. On macOS with Homebrew run: `brew install vim`. When building Vim from source,
use: `./configure --enable-python3interp=yes`. There's many guides online how to do
Expand Down
5 changes: 5 additions & 0 deletions docs/usage_and_configuration/black_docker_image.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ _Black_ images with the following tags are available:
- `latest_release` - tag created when a new version of _Black_ is released.\
ℹ Recommended for users who want to use released versions of _Black_. It maps to [the latest release](https://github.com/psf/black/releases/latest)
of _Black_.
- `latest_prerelease` - tag created when a new alpha (prerelease) version of _Black_ is
released.\
ℹ Recommended for users who want to preview or test alpha versions of _Black_. Note that
the most recent release may be newer than any prerelease, because no prereleases are created
before most releases.
- `latest` - tag used for the newest image of _Black_.\
ℹ Recommended for users who always want to use the latest version of _Black_, even before
it is released.
Expand Down
16 changes: 13 additions & 3 deletions src/black/brackets.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ def mark(self, leaf: Leaf) -> None:
within brackets a given leaf is. 0 means there are no enclosing brackets
that started on this line.
If a leaf is itself a closing bracket, it receives an `opening_bracket`
field that it forms a pair with. This is a one-directional link to
avoid reference cycles.
If a leaf is itself a closing bracket and there is a matching opening
bracket earlier, it receives an `opening_bracket` field with which it forms a
pair. This is a one-directional link to avoid reference cycles. Closing
bracket without opening happens on lines continued from previous
breaks, e.g. `) -> "ReturnType":` as part of a funcdef where we place
the return type annotation on its own line of the previous closing RPAR.
If a leaf is a delimiter (a token on which Black can split the line if
needed) and it's on depth 0, its `id()` is stored in the tracker's
Expand All @@ -91,6 +94,13 @@ def mark(self, leaf: Leaf) -> None:
if leaf.type == token.COMMENT:
return

if (
self.depth == 0
and leaf.type in CLOSING_BRACKETS
and (self.depth, leaf.type) not in self.bracket_match
):
return

self.maybe_decrement_after_for_loop_variable(leaf)
self.maybe_decrement_after_lambda_arguments(leaf)
if leaf.type in CLOSING_BRACKETS:
Expand Down
3 changes: 2 additions & 1 deletion src/black/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,8 @@ def maybe_empty_lines(self, current_line: Line) -> LinesBlock:
and (self.semantic_leading_comment is None or before)
):
self.semantic_leading_comment = block
elif not current_line.is_decorator:
# `or before` means this decorator already has an empty line before
elif not current_line.is_decorator or before:
self.semantic_leading_comment = None

self.previous_line = current_line
Expand Down
12 changes: 12 additions & 0 deletions src/black/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,3 +848,15 @@ def is_string_token(nl: NL) -> TypeGuard[Leaf]:

def is_number_token(nl: NL) -> TypeGuard[Leaf]:
return nl.type == token.NUMBER


def is_part_of_annotation(leaf: Leaf) -> bool:
"""Returns whether this leaf is part of type annotations."""
ancestor = leaf.parent
while ancestor is not None:
if ancestor.prev_sibling and ancestor.prev_sibling.type == token.RARROW:
return True
if ancestor.parent and ancestor.parent.type == syms.tname:
return True
ancestor = ancestor.parent
return False
Loading

0 comments on commit 2fecc15

Please sign in to comment.