Commit Graph

1227 Commits

Author SHA1 Message Date
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
Michal Siska
78317a4cfb
Removed distutils import from autoload/black.vim (#2607) (#2610) 2021-11-15 08:51:56 -08:00
Hugo van Kemenade
3cb010ec8e
Declare support for Python 3.10 (#2562) 2021-11-14 06:37:06 -08:00
Batuhan Taskaya
147d075a4c
black/parser: support as-exprs within call args (#2608) 2021-11-14 06:04:31 -08:00
Oliver Margetts
eb9d0396cd
Allow install under pypy (#2559)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
2021-11-13 19:46:15 -08:00
Batuhan Taskaya
1e0ec543ff
black/parser: partial support for pattern matching (#2586)
Partial implementation for #2242. Only works when explicitly stated -t py310.

Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
2021-11-13 19:15:31 -08:00
Richard Si
5e191c29d4
Bump deps in Pipfile.lock (GH-2605)
Mostly because the hashes for typed-ast were valid for 1.4.2 when the
version is pinned to 1.4.3 ... pipenv is pleasant to use /s
2021-11-12 20:41:46 -05:00
Kian Meng Ang
53cabe7265
Fix typos (#2603) 2021-11-11 19:02:43 -08:00
Richard Si
0753d99519
Improve Python 2 only syntax detection (GH-2592)
* Improve Python 2 only syntax detection

First of all this fixes a mistake I made in Python 2 deprecation PR
using token.* to check for print/exec statements. Turns out that
for nodes with a type value higher than 256 its numeric type isn't
guaranteed to be constant. Using syms.* instead fixes this.

Also add support for the following cases:

    print "hello, world!"

    exec "print('hello, world!')"

    def set_position((x, y), value):
        pass

    try:
        pass
    except Exception, err:
        pass

    raise RuntimeError, "I feel like crashing today :p"

    `wow_these_really_did_exist`

    10L

* Add octal support, more test cases, and fixup long ints

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2021-11-11 20:28:48 -05:00
Richard Si
f297c4644e
primer: Hypothesis now requires Python>=3.8 (GH-2602)
looks like their project dev tooling uses some newer syntax or something
2021-11-11 17:52:13 -05:00
LordOfPolls
f80f49767c
Add a missing space in Python 2 deprecation (GH-2590)
`DEPRECATION: Python 2 support will be removed in the first stable releaseexpected in January 2022` - > `DEPRECATION: Python 2 support will be removed in the first stable release expected in January 2022`
2021-11-06 12:04:27 -04:00
Cooper Lees
64c8be01f0
Update CHANGES.md for 21.10b0 release (#2583)
* Update CHANGES.md for 21.10b0 release

* Update version in docs/usage_and_configuration/the_basics.md

* Also update docs/integrations/source_version_control.md ...
2021-10-31 17:59:39 -07:00