Commit Graph

319 Commits

Author SHA1 Message Date
Zsolt Dollenstein
d8fa8df052
Add support for walrus operator (#935)
* Parse `:=` properly
* never unwrap parenthesis around `:=`
* When checking for AST-equivalence, use `ast` instead of `typed-ast` when running on python >=3.8
* Assume code that uses `:=` is at least 3.8
2019-07-28 16:03:23 +01:00
Zsolt Dollenstein
77b6ed1b70 Hello github.com/psf! 2019-07-22 21:41:45 +01:00
Yurii Karabas
90d205d1f5 Use nullcontext in case when lock is None. Shutdown pool after code formatting. (#928) 2019-07-16 18:45:56 +01:00
Min ho Kim
f3bb22a828 Fix typo (#916) 2019-07-01 07:42:30 -07:00
Brandt Bucher
b073c9a4e9 Force parentheses between unary op and binary power. (#909) 2019-06-29 09:35:16 -07:00
Zsolt Dollenstein
7d213c6d43
Fix docstring of schedule_formatting
Fixes #914.
2019-06-28 17:31:54 +01:00
Brandt Bucher
9d9f96a7b4 Fix mypy errors. (#911) 2019-06-25 09:44:12 -07:00
Zsolt Dollenstein
8f380911e0
Pin comment to single leaf in invisible parens (#872) 2019-06-15 07:29:09 +01:00
dylanjblack
9394de150e Fix trailing comma for function with one arg (#880) (#891)
Modified maybe_remove_trailing_comma to remove trailing commas for
typedarglists (in addition to arglists), and updated line split logic
to ensure that all lines in a function definition that contain only one
arg have a trailing comma.
2019-06-14 21:49:49 -07:00
Jelle Zijlstra
1c43252aa3 fix some out-of-date docstrings; other cleanup (#865) 2019-05-26 12:09:11 +02:00
Zsolt Dollenstein
519c06a8cc
Don't introduce quotes to f-string sub-expressions on string boundaries (#871) 2019-05-26 11:58:00 +02:00
Michael Flaxman
cbe455ad66 minor performance improvement (~2% speedup in unit tests) (#858) 2019-05-21 20:02:17 -07:00
Katie McLaughlin
b85c345dbc Remove happiness of error message (#852) 2019-05-16 13:02:17 +01:00
Jelle Zijlstra
957ba24bb6
remove obviously unnecessary parentheses (#850)
Fixes #548
2019-05-15 21:11:04 -07:00
Benjamin Woodruff
448885b256
Move tokenizer config onto grammar, rename flag
Based on the feedback in
https://github.com/python/black/pull/845#issuecomment-490622711

- Remove TokenizerConfig, and add a field to Grammar instead.
- Pass the Grammar to the tokenizer.
- Rename `ASYNC_IS_RESERVED_KEYWORD` to `ASYNC_KEYWORDS` and
  `ASYNC_IS_VALID_IDENTIFIER` to `ASYNC_IDENTIFIERS`.
2019-05-09 17:59:29 +02:00
Benjamin Woodruff
f8617f975d
Add support for always tokenizing async/await as keywords
Fixes #593

I looked into this bug with @ambv and @carljm, and we reached the
conclusion was that it's not possible for the tokenizer to determine if
async/await is a keyword inside all possible generators without breaking
the grammar for older versions of Python.

Instead, we introduce a new tokenizer mode for Python 3.7+ that will
cause all async/await instances to get parsed as a reserved keyword,
which should fix async/await inside generators.
2019-05-09 17:59:29 +02:00
Łukasz Langa
2227e6b1cd
Remove spurious prints 2019-05-09 04:49:48 +02:00
Łukasz Langa
6bb90f22ed
Use to handle legacy async/await handling in assert_equivalent 2019-05-08 23:33:39 +02:00
Jason Fried
866be06646 Make --safe work for Python2.7 syntax, by using typed_ast for safe validation (#840) 2019-05-08 07:45:59 -07:00
Carl Meyer
6fdbdb4ee3
Avoid unstable formatting when comment follows escaped newline. (#839). Fixes #767. 2019-05-08 09:53:20 -04:00
Jelle Zijlstra
14cbf737df
don't run more than 61 workers on Windows (#838) 2019-05-07 13:11:20 -04:00
Jelle Zijlstra
06004cd319 Add black -c "code" (#761) 2019-05-07 09:58:59 -04:00
Jelle Zijlstra
de806405d2 Add parentheses around tuple unpack assignment (#832)
Fixes #656
2019-05-07 09:51:28 -04:00
Jelle Zijlstra
18119d3846 Remove unnecessary parens around yield (#834) 2019-05-07 09:49:50 -04:00
Jelle Zijlstra
6b994fdb8a
fix handling of comments in from imports (#829)
Fixes #671
2019-05-06 09:13:25 -04:00
Tom Christie
e6ddb68c78 Wrap loop.run_in_executor up in asyncio.ensure_future for reliable cross-platform berhavior. (#679)
Closes #494

Task completion should also remove the task from `pending`.

Only replicates on some platforms. (eg. Can replicate on Python 3.7+, with either Windows or whatever default Linux distro Travis uses.)
2019-05-05 14:58:26 -04:00
Hugo
4a953b7241 ambv/black -> python/black (#819) 2019-05-02 20:19:52 +01:00
Hugo
597a0e102c Fix B011 (#820)
Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
2019-05-02 20:09:49 +01:00
Jelle Zijlstra
cea13f4984
Split the TRAILING_COMMA feature (#763) 2019-03-25 08:22:02 -07:00
Jelle Zijlstra
ba64fc757c
redo grammar selection, add test (#765) 2019-03-16 11:35:18 -07:00
Jelle Zijlstra
b396f13761 fix incorrect call (#762) 2019-03-15 18:39:08 +01:00
Andy Freeland
d6db1c12a8 Fix print() function on Python 2 (#754)
Fixes #752
2019-03-14 16:42:54 -07:00
Łukasz Langa
026c81b834
v19.3b0 2019-03-14 18:09:10 +01:00
Jelle Zijlstra
129ebd53a6 Add back --py36 as a deprecated option (#750)
This partially reverts commit 21ab37a5d9.
2019-03-14 17:31:27 +01:00
Łukasz Langa
ca9ad698ef
Enhance the type comment patch 2019-03-14 16:26:41 +01:00
Hugo
d00eac9944 Fix PendingDeprecationWarning: Task.all_tasks() is deprecated, use asyncio.all_tasks() instead (#741) 2019-03-14 13:41:42 +01:00
Łukasz Langa
087fedb17e
Simplify the #606 patch
Thanks for the original patch to solve #509, @hauntsaninja.
2019-03-14 13:40:52 +01:00
Jelle Zijlstra
ea55ff2878
remove Python implementation-specific versions (#736) 2019-03-07 16:34:34 -08:00
Jelle Zijlstra
21ab37a5d9
remove --py36 (#724)
Fixes #703.
2019-02-24 09:15:03 -08:00
Jelle Zijlstra
f5b14b1afd
split long del statements into multiple lines (#698)
Fixes #693
2019-02-22 22:00:40 -08:00
Zsolt Dollenstein
250ba7f04b Remove numeric underscore normalization (#696) 2019-02-06 19:16:49 -08:00
Jelle Zijlstra
36d3c516d3
Add --target-version option to allow users to choose targeted Python versions (#618) 2019-02-06 18:43:50 -08:00
Jimmy Jia
1ec2470da7 chore: Fix noqa comment (#684)
Omitting the colon makes Flake8 ignore all errors, rather than the specific code.
2019-01-29 13:46:19 -08:00
Anthony Sottile
4d3107233f Atomically write cache files (#674) 2019-01-18 20:59:17 -08:00
Anthony Sottile
7546ed292c delete some dead code (#669)
dead code detected via [dead](https://github.com/asottile/dead)

- **`KEYWORDS`**: introduced (unreferenced) in e74117f172
- **`FLOW_CONTROL`**: last referenced in e9a940d69e

"clean" command:

```
dead --exclude '^(tests/data/|docs/conf.py|blib2to3/)' | grep -Ev '^(visit_.*|show|_stop_signal|lib2to3_unparse) '
```
2019-01-12 09:23:20 -08:00
Utsav Shah
024c9cab55 Add support for special comments in multiline functions (#642) 2019-01-05 11:20:12 -08:00
Tsuyoshi Hombashi
3b72ed0d48 Improve an error message when failed to load pyproject.toml (#653) 2018-12-31 05:03:31 -08:00
Peter Stensmyr
fe24a15b84 Fix multiprocessing support for Windows binary (#632)
* Fix multiprocessing support for Windows binary

The black and blackd binaries generated for Windows builds would fail on
reformatting multiple files due to a Windows-specific
multiprocessing issue. Fix by calling freeze_support() as
described in Python docs.
2018-12-14 15:01:50 +00:00
Jim Brännlund
55121195ce Add .eggs to default exclusions (#629) 2018-11-29 14:27:08 -08:00
hauntsaninja
e4e59f87a8 Improves performance on large commented logical lines (#606)
Fixes #509
2018-11-13 15:04:27 -08:00
hauntsaninja
5bc62a4a82 Fix two types to be Optional (#607) 2018-11-13 15:02:27 -08:00
Jelle Zijlstra
fbf59b60d7 remove unused variable (#604) 2018-11-13 21:23:56 +00:00
Chuck Wooters
5c2dd96a69 patch main to ensure click_patch() gets called (#572) 2018-10-29 11:10:32 +01:00
Felix Kohlgrüber
99c97c3d7f delete unused code (#588) 2018-10-29 11:09:06 +01:00
Łukasz Langa
61feadc0f8
v18.9b0 2018-09-26 13:05:49 -07:00
Łukasz Langa
7145fa325c
Remove whitespace at the beginning of the file
Fixes #399
2018-09-26 12:18:45 -07:00
Łukasz Langa
c6c8ef76a4
Fix mangling pweave and Spyder IDE special comments
Fixes #532.
2018-09-26 09:42:42 -07:00
Łukasz Langa
a4b5c085a3
Move should_explode handling to bracket_split_build_line 2018-09-26 08:53:56 -07:00
Łukasz Langa
1610fd6bc5
Add trailing comma for single as imports, too 2018-09-26 08:26:35 -07:00
Łukasz Langa
0c5c537431
Refactor left_hand_split and right_hand_split to deduplicate line building logic 2018-09-26 07:41:34 -07:00
Zsolt Dollenstein
25d24a10a4 Add trailing comma when a single import doesn't fit on a line. (#504)
Fixes #250.
2018-09-26 13:26:50 +01:00
Zsolt Dollenstein
5f9eb9e4f7 Add underscores to numeric literals with more than six digits (#529) 2018-09-26 12:32:11 +01:00
Tim Swast
2d99573b34 Add .nox directories to default exclude (#525)
[Nox](https://nox.readthedocs.io/) is similar to Tox. It creates a .nox directory that contains virtualenv for testing with different Python versions.
2018-09-25 16:25:58 +01:00
Zsolt Dollenstein
bbf38400ce Uppercase digits in hex literals (#530) 2018-09-25 16:01:56 +01:00
Łukasz Langa
41368138bb
Fix documentation build 2018-09-18 12:04:30 -07:00
Zsolt Dollenstein
a82f186787 blackd: a HTTP server for blackening (#460) 2018-09-17 10:02:25 -07:00
Zsolt Dollenstein
80500748a7
fix unstable formatting when unpacking big tuples (#514)
* fix unstable formatting when unpacking big tuples

* add changelog entry
2018-09-17 12:03:21 +01:00
Zsolt Dollenstein
08f1cdd00b
Make sure async for is not broken up to separate lines (#503)
Fixes #372.
2018-09-08 10:34:08 +01:00
Jelle Zijlstra
a37abdcbc5
change some numeric behavior (#469) 2018-08-23 11:55:29 -07:00
Jelle Zijlstra
b53cb94743 fix bracket match bug (#470)
* fix bracket match bug

* add missing test file
2018-08-23 12:52:07 +01:00
Jelle Zijlstra
8b340e2102
wrap atoms in invisible parens to split adjacent strings (#463) 2018-08-21 21:10:59 -07:00
Jelle Zijlstra
d4f0521754
fix misformatting of floats with leading zeros (#464) 2018-08-20 08:19:25 -07:00
Jelle Zijlstra
b719d85ccc
autodetect Python 3.6 on the basis of underscores (#461) 2018-08-19 21:02:06 -07:00
ceh
66b82ced50 Fix minor typos (#443) 2018-08-19 13:10:06 +01:00
Łukasz Langa
2a357b3606 Nits around numeral normalization. 2018-08-17 10:38:28 -07:00
Łukasz Langa
71bdd727a8 Put missing blank lines after return statements. 2018-08-17 10:29:19 -07:00
Łukasz Langa
ebbb98919d Make schedule_formatting logic less nested. 2018-08-17 10:17:37 -07:00
Łukasz Langa
1dbe77cd91 Simplify caching logic. 2018-08-17 10:14:10 -07:00
Jelle Zijlstra
9e15cacc67 write cache in --check mode (#453)
Fixes #448.

This diff makes us always write to the cache in normal mode, except
if the file is already in the cache, and it makes us write to the
cache in --check mode if the file is already well formatted.

I also fixed some related docstrings.

WriteBack.NO is now used only in tests.
2018-08-17 15:40:37 +01:00
Jelle Zijlstra
cc48bc56ca normalize numeric literals (#454)
Fixes #452

I ended up making a couple of other normalizations to numeric literals
too (lowercase everything, don't allow leading or trailing . in floats,
remove redundant + sign in exponent). I don't care too much about those,
so I'm happy to change the behavior there.

For reference, here is Python's grammar for numeric literals:
https://docs.python.org/3/reference/lexical_analysis.html#numeric-literals
2018-08-17 15:03:58 +01:00
Zsolt Dollenstein
e94a41f92a Look at actual parenthesis when generating ignored leafs.
Fixes #385
2018-07-22 15:30:02 +01:00
Zsolt Dollenstein
dd8bde6d2f Improve get_future_imports implementation.
Closes #389.
2018-07-02 17:49:47 +01:00
Łukasz Langa
41240e9a78 18.6b4 2018-06-21 14:25:07 -07:00
Łukasz Langa
d93e726806 Don't freeze when multiple comments directly precede # fmt: off
Fixes #371
2018-06-21 14:03:01 -07:00
Łukasz Langa
98b6c887da 18.6b3 2018-06-20 12:00:07 -07:00
Łukasz Langa
c2327c83b2 More tests for # fmt: off
Two more known limitations that I don't feel like solving now.  Probably very
low priority.
2018-06-19 23:46:58 -07:00
Łukasz Langa
048efa7476 Trivial nits 2018-06-19 23:08:10 -07:00
Łukasz Langa
2dfa69bb7f Stop Click from crashing Black on invalid environments
Fixes #277
2018-06-19 22:55:57 -07:00
Łukasz Langa
df2ae3bbe6 Use the separate pass for # fmt: off on all code
This removes the hacky exception-based handling that didn't work across
statement boundaries.

Fixes #335
2018-06-19 17:32:41 -07:00
Łukasz Langa
8a8c58252c Support # fmt: off/on pairs within brackets
Fixes #329
2018-06-18 22:37:46 -07:00
Łukasz Langa
e4340f5c3e Cache generated comments 2018-06-18 22:37:46 -07:00
Jelle Zijlstra
9db828c3de Add blank line after constants in stub file (#360)
Fixes #340
2018-06-16 11:53:45 -07:00
Neraste
42a3fe5331 Ignore symbolic links pointing outside of the root directory (#339)
Fixes #338
2018-06-13 00:07:04 -07:00
Zsolt Dollenstein
efcd039482 Fix string normalization eating all backslashes above 3 2018-06-10 09:44:41 +01:00
Łukasz Langa
d240ca25ea Make is_complex_subscript() ignore list literals
This fixes catastrophically quadratic behavior on long lists.
2018-06-09 16:04:09 -07:00
Zsolt Dollenstein
5d0a469e8e Fix string normalization sometimes producing invalid fstrings (#327) 2018-06-09 12:30:49 -07:00
Łukasz Langa
ff2e5dd6e6 18.6b2 2018-06-08 12:07:43 -07:00
Łukasz Langa
8482d38fb4 Return early from comment placement calculation on lines without comments 2018-06-08 12:00:53 -07:00
Loren Carvalho
39e9347687 Add -h as a shortcut for --help (#316) 2018-06-07 19:43:04 -07:00
Zsolt Dollenstein
7f3678885f fix handling of empty triple quoted strings (#314) 2018-06-07 11:41:34 -07:00