Skip to content

Commit

Permalink
Merge branch 'psf:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
TomFryers committed Mar 11, 2022
2 parents a79d394 + 71e71e5 commit d223a97
Show file tree
Hide file tree
Showing 22 changed files with 106 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Grep CHANGES.md for PR number
if: contains(github.event.pull_request.labels.*.name, 'skip news') != true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/diff_shades.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ jobs:

steps:
- name: Checkout this repository (full clone)
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-python@v2
- uses: actions/setup-python@v3

- name: Install diff-shades and support dependencies
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/diff_shades_comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
comment:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v3

- name: Install support dependencies
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up latest Python
uses: actions/setup-python@v2
uses: actions/setup-python@v3

- name: Install dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/fuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v3

- name: Install dependencies
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pypi_upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v3

- name: Install latest pip, build, twine
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ jobs:
os: [ubuntu-latest, macOS-latest, windows-latest]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Coveralls finished
uses: AndreMiras/coveralls-python-action@v20201129
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/upload_binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ jobs:
executable_mime: "application/x-mach-binary"

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up latest Python
uses: actions/setup-python@v2
uses: actions/setup-python@v3
with:
python-version: "*"

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/uvloop_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ jobs:
os: [ubuntu-latest, macOS-latest]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v3

- name: Install latest pip
run: |
Expand Down
11 changes: 10 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- Do not format `__pypackages__` directories by default (#2836)
- Add support for specifying stable version with `--required-version` (#2832).
- Avoid crashing when the user has no homedir (#2814)
- Avoid crashing when md5 is not available (#2905)

### Documentation

Expand All @@ -37,6 +38,8 @@

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

- Move test to disable plugin in Vim/Neovim, which speeds up loading (#2896)

### Output

<!-- Changes to Black's terminal output and error messages -->
Expand All @@ -47,9 +50,15 @@

<!-- Changes to how Black is packaged, such as dependency requirements -->

- On Python 3.11 and newer, use the standard library's `tomllib` instead of `tomli`
(#2903)

### Parser

<!-- Changes to the parser or to version autodetection -->
- Black can now parse starred expressions in the target of `for` and `async for`
statements, e.g `for item in *items_1, *items_2: pass` (#2879).

- Fix handling of directory junctions on Windows (#2904)

### Performance

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ section for details). If you're feeling confident, use `--fast`.

_Black_ is a PEP 8 compliant opinionated formatter. _Black_ reformats entire files in
place. Style configuration options are deliberately limited and rarely added. It doesn't
take previous formatting into account (see [Pragmatism](#pragmatism) for exceptions).
take previous formatting into account (see
[Pragmatism](https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#pragmatism)
for exceptions).

Our documentation covers the current _Black_ code style, but planned changes to it are
also documented. They're both worth taking a look:
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ myst-parser==0.16.1
Sphinx==4.4.0
sphinxcontrib-programoutput==0.17
sphinx_copybutton==0.5.0
furo==2022.2.14.1
furo==2022.3.4
8 changes: 4 additions & 4 deletions plugin/black.vim
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
" 1.2:
" - use autoload script

if exists("g:load_black")
finish
endif

if v:version < 700 || !has('python3')
func! __BLACK_MISSING()
echo "The black.vim plugin requires vim7.0+ with Python 3.6 support."
Expand All @@ -25,10 +29,6 @@ if v:version < 700 || !has('python3')
finish
endif

if exists("g:load_black")
finish
endif

let g:load_black = "py1.0"
if !exists("g:black_virtualenv")
if has("nvim")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def find_python_files(base: Path) -> List[Path]:
install_requires=[
"click>=8.0.0",
"platformdirs>=2",
"tomli>=1.1.0",
"tomli>=1.1.0; python_version < '3.11'",
"typed-ast>=1.4.2; python_version < '3.8' and implementation_name == 'cpython'",
"pathspec>=0.9.0",
"dataclasses>=0.6; python_version < '3.7'",
Expand Down
29 changes: 16 additions & 13 deletions src/black/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
from mypy_extensions import mypyc_attr
from pathspec import PathSpec
from pathspec.patterns.gitwildmatch import GitWildMatchPatternError
import tomli

if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib

from black.output import err
from black.report import Report
Expand Down Expand Up @@ -99,10 +103,10 @@ def parse_pyproject_toml(path_config: str) -> Dict[str, Any]:
"""
Parse a pyproject toml file, pulling out relevant parts for Black
If parsing fails, will raise a tomli.TOMLDecodeError
If parsing fails, will raise a tomllib.TOMLDecodeError
"""
with open(path_config, "rb") as f:
pyproject_toml = tomli.load(f)
pyproject_toml = tomllib.load(f)
config = pyproject_toml.get("tool", {}).get("black", {})
return {k.replace("--", "").replace("-", "_"): v for k, v in config.items()}

Expand Down Expand Up @@ -155,23 +159,22 @@ def normalize_path_maybe_ignore(
"""
try:
abspath = path if path.is_absolute() else Path.cwd() / path
normalized_path = abspath.resolve().relative_to(root).as_posix()
except OSError as e:
if report:
report.path_ignored(path, f"cannot be read because {e}")
return None

except ValueError:
if path.is_symlink():
normalized_path = abspath.resolve()
try:
root_relative_path = normalized_path.relative_to(root).as_posix()
except ValueError:
if report:
report.path_ignored(
path, f"is a symbolic link that points outside {root}"
)
return None

raise
except OSError as e:
if report:
report.path_ignored(path, f"cannot be read because {e}")
return None

return normalized_path
return root_relative_path


def path_is_excluded(
Expand Down
4 changes: 2 additions & 2 deletions src/black/mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
chosen by the user.
"""

from hashlib import md5
from hashlib import sha256
import sys

from dataclasses import dataclass, field
Expand Down Expand Up @@ -182,6 +182,6 @@ def get_cache_key(self) -> str:
str(int(self.magic_trailing_comma)),
str(int(self.experimental_string_processing)),
str(int(self.preview)),
md5((",".join(sorted(self.python_cell_magics))).encode()).hexdigest(),
sha256((",".join(sorted(self.python_cell_magics))).encode()).hexdigest(),
]
return ".".join(parts)
2 changes: 1 addition & 1 deletion src/blib2to3/Grammar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef
async_stmt: ASYNC (funcdef | with_stmt | for_stmt)
if_stmt: 'if' namedexpr_test ':' suite ('elif' namedexpr_test ':' suite)* ['else' ':' suite]
while_stmt: 'while' namedexpr_test ':' suite ['else' ':' suite]
for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
for_stmt: 'for' exprlist 'in' testlist_star_expr ':' suite ['else' ':' suite]
try_stmt: ('try' ':' suite
((except_clause ':' suite)+
['else' ':' suite]
Expand Down
27 changes: 27 additions & 0 deletions tests/data/starred_for_target.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
for x in *a, *b:
print(x)

for x in a, b, *c:
print(x)

for x in *a, b, c:
print(x)

for x in *a, b, *c:
print(x)

async for x in *a, *b:
print(x)

async for x in *a, b, *c:
print(x)

async for x in a, b, *c:
print(x)

async for x in (
*loooooooooooooooooooooong,
very,
*loooooooooooooooooooooooooooooooooooooooooooooooong,
):
print(x)
Loading

0 comments on commit d223a97

Please sign in to comment.