Commit Graph

1188 Commits

Author SHA1 Message Date
Batuhan Taskaya
b97ec62368
Imply 3.8+ when annotated assigments used with unparenthesized tuples (#2708) 2021-12-17 13:43:14 -08:00
Mike Taves
61fe8418cc
Use 'python -m build' to build wheel and source distributions (#2701) 2021-12-15 19:35:01 -08:00
Batuhan Taskaya
dc90d4951f
Unpacking on flow constructs (return/yield) now implies 3.8+ (#2700) 2021-12-15 16:17:33 -08:00
dependabot[bot]
f10ce0c942
Bump pre-commit/action from 2.0.2 to 2.0.3 (GH-2695)
Bumps [pre-commit/action](https://github.com/pre-commit/action) from 2.0.2 to 2.0.3.
- [Release notes](https://github.com/pre-commit/action/releases)
- [Commits](https://github.com/pre-commit/action/compare/v2.0.2...v2.0.3)

---
updated-dependencies:
- dependency-name: pre-commit/action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-12-15 18:55:26 -05:00
dependabot[bot]
e9f520c16a
Bump myst-parser from 0.15.2 to 0.16.0 in /docs (GH-2696)
Bumps [myst-parser](https://github.com/executablebooks/MyST-Parser) from 0.15.2 to 0.16.0.
- [Release notes](https://github.com/executablebooks/MyST-Parser/releases)
- [Changelog](https://github.com/executablebooks/MyST-Parser/blob/master/CHANGELOG.md)
- [Commits](https://github.com/executablebooks/MyST-Parser/compare/v0.15.2...v0.16.0)

---
updated-dependencies:
- dependency-name: myst-parser
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-12-15 18:26:01 -05:00
Richard Si
3501cefb09
Include underlying error when AST safety check parsing fails (#2693) 2021-12-14 18:21:28 -08:00
aru
93701d249e
use valid package-ecosystem key (#2694) 2021-12-14 18:21:15 -08:00
Richard Si
72fbacd996
chore: dump docs deps and pre-commit hooks (#2676) 2021-12-14 17:25:47 -08:00
Richard Si
3083f4470b
Don't colour diff headers white, only bold (GH-2691)
So people with light themed terminals can still read 'em.
2021-12-14 19:32:14 -05:00
Batuhan Taskaya
ab86513710
from __future__ import annotations now implies 3.7+ (#2690) 2021-12-14 15:22:56 -08:00
Batuhan Taskaya
1c6b3a3a6f
Support as-expressions on dict items (GH-2686) 2021-12-12 16:10:22 -05:00
Jelle Zijlstra
e7ddf524b0
Show details when a regex fails to compile (GH-2678) 2021-12-07 22:13:05 -05:00
Jelle Zijlstra
085efac037
no longer expect changes on pyanalyze (#2674)
https://github.com/quora/pyanalyze/pull/316
2021-12-05 15:47:53 -08:00
Richard Si
f1d4e742c9
Prepare for release 21.12b0 (GH-2673)
Let's do this!
2021-12-05 16:39:34 -05:00
Batuhan Taskaya
28ab82aab0
perf: drop the initial stack copy (#2670)
Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
2021-12-05 13:03:48 -08:00
Richard Si
d9eee31ec8
blib2to3 can raise TokenError and IndentationError too (#2671) 2021-12-05 08:53:58 -08:00
Jelle Zijlstra
9424e795bf
Reorganize changelog (#2669)
I believe it would be useful to split up the long list of changes a bit more.

Specific changes:
- Removed the entry for new flake8 plugins; this is purely internal and not of interest to users
- Put regex in the packaging section
- New section for Jupyter Notebook
- New section for Python 3.10, mostly match/case stuff
2021-12-04 15:57:40 -08:00
Jelle Zijlstra
dc8cdda8fd
tell users to use -t py310 (#2668) 2021-12-04 15:30:23 -08:00
Tanvi Moharir
f52cb0fe37
Don't let TokenError bubble up from lib2to3_parse (GH-2343)
error: cannot format <string>: ('EOF in multi-line statement', (2, 0))
   
 ▲ before ▼ after

error: cannot format <string>: Cannot parse: 2:0: EOF in multi-line statement

Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
2021-12-04 15:21:26 -05:00
Batuhan Taskaya
136930fccb
Make star-expression spacing consistent in match/case (#2667) 2021-12-03 06:49:33 -08:00
Jelle Zijlstra
bd9d52b52d
Remove regex dependency (GH-2663)
We were no longer using it since GH-2644 and GH-2654. This should hopefully
make using Black easier to use as there's one less compiled dependency.
The core team also doesn't have to deal with the surprisingly frequent fires
the regex packaging setup goes through.

Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
2021-12-02 17:35:02 -05:00
Batuhan Taskaya
20d7ae0676
Ensure match/case are recognized as statements (#2665) 2021-12-02 09:58:22 -08:00
Richard Si
b0c2bcc953
Treat functions/classes in blocks as if they're nested (GH-2472)
* Treat functions/classes in blocks as if they're nested

One curveball is that we still want two preceding newlines before blocks
that are probably logically disconnected. In other words:

    if condition:

        def foo():
            return "hi"
                             # <- aside: this is the goal of this commit
    else:

        def foo():
            return "cya"
                             # <- the two newlines spacing here should stay
                             #    since this probably isn't related
    with open("db.json", encoding="utf-8") as f:
        data = f.read()

Unfortunately that means we have to special case specific clause types
instead of just being able to just for a colon leaf. The hack used here
is to check whether we're adding preceding newlines for a standalone or
dependent clause. "Standalone" being a clause that doesn't need another
clause to be valid (eg. if) and vice versa.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2021-12-01 18:05:59 -05:00
Jelle Zijlstra
8485191448
slightly better example link (#2617)
Since we also need to update two places in the docs
2021-12-01 13:47:33 -08:00
Shantanu
f1813e31b6
Fix determination of f-string expression spans (#2654)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2021-12-01 09:52:24 -08:00
Jelle Zijlstra
0f7cf9187f
fix error message for match (#2649)
Fixes #2648.

Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
2021-11-30 18:39:39 -08:00
Jelle Zijlstra
5e2bb528e0
Reduce usage of regex (#2644)
This removes all but one usage of the `regex` dependency. Tricky bits included:
- A bug in test_black.py where we were incorrectly using a character range. Fix also submitted separately in #2643.
- `tokenize.py` was the original use case for regex (#1047). The important bit is that we rely on `\w` to match anything valid in an identifier, and `re` fails to match a few characters as part of identifiers. My solution is to instead match all characters *except* those we know to mean something else in Python: whitespace and ASCII punctuation. This will make Black able to parse some invalid Python programs, like those that contain non-ASCII punctuation in the place of an identifier, but that seems fine to me.
- One import of `regex` remains, in `trans.py`. We use a recursive regex to parse f-strings, and only `regex` supports that. I haven't thought of a better fix there (except maybe writing a manual parser), so I'm leaving that for now.

My goal is to remove the `regex` dependency to reduce the risk of breakage due to dependencies and make life easier for users on platforms without wheels.
2021-11-30 18:01:36 -08:00
Batuhan Taskaya
b336b390d0
Fix line generation for match match: / case case: (GH-2661) 2021-11-30 15:56:38 -05:00
Jelle Zijlstra
ebd3e391da
add FAQ entry about undetected syntax errors (#2645)
This came up in #2644.
2021-11-30 12:34:45 -08:00
Jameel Al-Aziz
e151686c6f
Remove hidden import from PyInstaller build (#2657)
The recent 2021.4 release of pyinstaller-hooks-contrib now contains a
built-in hook for platformdirs. Manually specifying the hidden import
arg should no longer be needed.
2021-11-30 08:20:27 -08:00
Batuhan Taskaya
8cdac18a04
Allow top-level starred expression on match (#2659)
Fixes #2647
2021-11-30 07:52:25 -08:00
Daniel Sparing
a066a2bc8b
Return NothingChanged if non-Python cell magic is detected, to avoid tokenize error (#2630)
Fixes https://github.com/psf/black/issues/2627 , a non-Python cell magic such as `%%writeline` can legitimately contain "incorrect" indentation, however this causes `tokenize-rt` to return an error. To avoid this, `validate_cell` should early detect cell magics (just like it detects `TransformerManager` transformations).

Test added too, in the shape of a "badly indented" `%%writefile` within `test_non_python_magics`.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Marco Edward Gorelli <marcogorelli@protonmail.com>
2021-11-29 15:07:35 -08:00
danieleades
a18ee4018f
add more flake8 lints (#2653) 2021-11-28 18:20:52 -08:00
Marco Edward Gorelli
72a84d4099
add missing f-string (#2650) 2021-11-26 18:53:16 -08:00
Marco Edward Gorelli
e0253080b0
Assignment to env var in Jupyter Notebook doesn't round-trip (#2642)
closes #2641
2021-11-26 08:14:57 -08:00
Jelle Zijlstra
17e42cb94b
fix regex (#2643) 2021-11-25 18:34:19 -08:00
Wael Nasreddine
db2715441a
README: Add KeepTruckin to the list of orgs (GH-2638)
At KT, we used Black to format all Python code in our Mono-repo.

Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
2021-11-25 20:09:47 -05:00
Batuhan Taskaya
dfa45cec9e
grammar: accept open sequences on match subject (GH-2639)
* grammar: accept open sequences on match subject
* give an example about the fixed match subject
2021-11-24 20:21:36 -05:00
Ash
40759445c9
Change cfg to ini for text highlighting (#2632) 2021-11-21 07:02:08 -08:00
Matthew D. Scholefield
05954c0950
Fix process pool fallback on Python 3.10 (GH-2631)
In Python 3.10 the exception generated by creating a process pool on
a Python build that doesn't support this is now `NotImplementedError`

Commit history before merge:

* Fix process pool fallback on Python 3.10
* Update CHANGES.md
* Update CHANGES.md

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2021-11-20 14:25:30 -05:00
Richard Si
9a73bb86db
Fix mypyc compat issue w/ AST safety check (GH-2628)
I can't wait for when we drop Python 2 support FWIW :)
2021-11-18 22:20:44 -05:00
Jelle Zijlstra
19f6aa8208
prepare release 2021.11b1 (#2622) 2021-11-17 19:51:49 -08:00
Rowan Seymour
ecf8c74481
Bump regex dependency to 2021.4.4 to fix import of Pattern class (#2621)
Fixes #2620
2021-11-17 19:46:28 -08:00
Jelle Zijlstra
d0b04d9f21
prepare release 21.11b0 (#2616) 2021-11-16 18:30:19 -08:00
Jelle Zijlstra
7dacdbe6dc
fix vim plugin (#2615) 2021-11-16 18:22:32 -08:00
Richard Si
0d1b957d40
Fix 3.10's supported features (#2614) 2021-11-15 21:07:25 -08:00
Richard Si
117891878e
Implementing mypyc support pt. 2 (#2431) 2021-11-15 20:24:16 -08:00
Jelle Zijlstra
1d7260050d
vim: Parse skip_magic_trailing_comma from pyproject.toml (#2613)
Co-authored-by: Kyle Kovacs <kkovacs@diconfiberoptics.com>
2021-11-15 19:03:47 -08:00
pszlazak
1d7163957a
Docker image usage description (#2412)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2021-11-15 18:47:21 -08:00
Batuhan Taskaya
d7b091e762
black/parser: optimize deepcopying nodes (#2611)
The implementation of the new backtracking logic depends heavily on deepcopying the current state of the parser before seeing one of the new keywords, which by default is an very expensive operations. On my system, formatting these 3 files takes 1.3 seconds.

```
 $ touch tests/data/pattern_matching_*; time python -m black -tpy310 tests/data/pattern_matching_*             19ms
All done!  🍰 
3 files left unchanged.
python -m black -tpy310 tests/data/pattern_matching_*  2,09s user 0,04s system 157% cpu 1,357 total
```

which can be optimized 3X if we integrate the existing copying logic (`clone`) to the deepcopy system;
```
 $ touch tests/data/pattern_matching_*; time python -m black -tpy310 tests/data/pattern_matching_*              1ms
All done!  🍰 
3 files left unchanged.
python -m black -tpy310 tests/data/pattern_matching_*  0,66s user 0,02s system 147% cpu 0,464 total
```

This still might have some potential, but that would be way trickier than this initial patch.
2021-11-15 18:38:40 -08:00