]> git.madduck.net Git - etc/vim.git/blob - README.md

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Update README.md to include appropriate command to install Vim with Python 3 on macOS...
[etc/vim.git] / README.md
1 ![Black Logo](https://raw.githubusercontent.com/psf/black/master/docs/_static/logo2-readme.png)
2
3 <h2 align="center">The Uncompromising Code Formatter</h2>
4
5 <p align="center">
6 <a href="https://travis-ci.com/psf/black"><img alt="Build Status" src="https://travis-ci.com/psf/black.svg?branch=master"></a>
7 <a href="https://github.com/psf/black/actions"><img alt="Actions Status" src="https://github.com/psf/black/workflows/Test/badge.svg"></a>
8 <a href="https://black.readthedocs.io/en/stable/?badge=stable"><img alt="Documentation Status" src="https://readthedocs.org/projects/black/badge/?version=stable"></a>
9 <a href="https://coveralls.io/github/psf/black?branch=master"><img alt="Coverage Status" src="https://coveralls.io/repos/github/psf/black/badge.svg?branch=master"></a>
10 <a href="https://github.com/psf/black/blob/master/LICENSE"><img alt="License: MIT" src="https://black.readthedocs.io/en/stable/_static/license.svg"></a>
11 <a href="https://pypi.org/project/black/"><img alt="PyPI" src="https://img.shields.io/pypi/v/black"></a>
12 <a href="https://pepy.tech/project/black"><img alt="Downloads" src="https://pepy.tech/badge/black"></a>
13 <a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
14 </p>
15
16 > “Any color you like.”
17
18 _Black_ is the uncompromising Python code formatter. By using it, you agree to cede
19 control over minutiae of hand-formatting. In return, _Black_ gives you speed,
20 determinism, and freedom from `pycodestyle` nagging about formatting. You will save time
21 and mental energy for more important matters.
22
23 Blackened code looks the same regardless of the project you're reading. Formatting
24 becomes transparent after a while and you can focus on the content instead.
25
26 _Black_ makes code review faster by producing the smallest diffs possible.
27
28 Try it out now using the [Black Playground](https://black.now.sh). Watch the
29 [PyCon 2019 talk](https://youtu.be/esZLCuWs_2Y) to learn more.
30
31 ---
32
33 _Contents:_ **[Installation and usage](#installation-and-usage)** |
34 **[Code style](#the-black-code-style)** | **[pyproject.toml](#pyprojecttoml)** |
35 **[Editor integration](#editor-integration)** | **[blackd](#blackd)** |
36 **[Version control integration](#version-control-integration)** |
37 **[Ignoring unmodified files](#ignoring-unmodified-files)** | **[Used by](#used-by)** |
38 **[Testimonials](#testimonials)** | **[Show your style](#show-your-style)** |
39 **[Contributing](#contributing-to-black)** | **[Change Log](#change-log)** |
40 **[Authors](#authors)**
41
42 ---
43
44 ## Installation and usage
45
46 ### Installation
47
48 _Black_ can be installed by running `pip install black`. It requires Python 3.6.0+ to
49 run but you can reformat Python 2 code with it, too.
50
51 ### Usage
52
53 To get started right away with sensible defaults:
54
55 ```
56 black {source_file_or_directory}
57 ```
58
59 ### Command line options
60
61 _Black_ doesn't provide many options. You can list them by running `black --help`:
62
63 ```text
64 black [OPTIONS] [SRC]...
65
66 Options:
67   -c, --code TEXT                 Format the code passed in as a string.
68   -l, --line-length INTEGER       How many characters per line to allow.
69                                   [default: 88]
70   -t, --target-version [py27|py33|py34|py35|py36|py37|py38]
71                                   Python versions that should be supported by
72                                   Black's output. [default: per-file auto-
73                                   detection]
74   --py36                          Allow using Python 3.6-only syntax on all
75                                   input files.  This will put trailing commas
76                                   in function signatures and calls also after
77                                   *args and **kwargs. Deprecated; use
78                                   --target-version instead. [default: per-file
79                                   auto-detection]
80   --pyi                           Format all input files like typing stubs
81                                   regardless of file extension (useful when
82                                   piping source on standard input).
83   -S, --skip-string-normalization
84                                   Don't normalize string quotes or prefixes.
85   --check                         Don't write the files back, just return the
86                                   status.  Return code 0 means nothing would
87                                   change.  Return code 1 means some files
88                                   would be reformatted.  Return code 123 means
89                                   there was an internal error.
90   --diff                          Don't write the files back, just output a
91                                   diff for each file on stdout.
92   --fast / --safe                 If --fast given, skip temporary sanity
93                                   checks. [default: --safe]
94   --include TEXT                  A regular expression that matches files and
95                                   directories that should be included on
96                                   recursive searches.  An empty value means
97                                   all files are included regardless of the
98                                   name.  Use forward slashes for directories
99                                   on all platforms (Windows, too).  Exclusions
100                                   are calculated first, inclusions later.
101                                   [default: \.pyi?$]
102   --exclude TEXT                  A regular expression that matches files and
103                                   directories that should be excluded on
104                                   recursive searches.  An empty value means no
105                                   paths are excluded. Use forward slashes for
106                                   directories on all platforms (Windows, too).
107                                   Exclusions are calculated first, inclusions
108                                   later.  [default: /(\.eggs|\.git|\.hg|\.mypy
109                                   _cache|\.nox|\.tox|\.venv|_build|buck-
110                                   out|build|dist)/]
111   -q, --quiet                     Don't emit non-error messages to stderr.
112                                   Errors are still emitted, silence those with
113                                   2>/dev/null.
114   -v, --verbose                   Also emit messages to stderr about files
115                                   that were not changed or were ignored due to
116                                   --exclude=.
117   --version                       Show the version and exit.
118   --config PATH                   Read configuration from PATH.
119   -h, --help                      Show this message and exit.
120 ```
121
122 _Black_ is a well-behaved Unix-style command-line tool:
123
124 - it does nothing if no sources are passed to it;
125 - it will read from standard input and write to standard output if `-` is used as the
126   filename;
127 - it only outputs messages to users on standard error;
128 - exits with code 0 unless an internal error occurred (or `--check` was used).
129
130 ### NOTE: This is a beta product
131
132 _Black_ is already [successfully used](#used-by) by many projects, small and big. It
133 also sports a decent test suite. However, it is still very new. Things will probably be
134 wonky for a while. This is made explicit by the "Beta" trove classifier, as well as by
135 the "b" in the version number. What this means for you is that **until the formatter
136 becomes stable, you should expect some formatting to change in the future**. That being
137 said, no drastic stylistic changes are planned, mostly responses to bug reports.
138
139 Also, as a temporary safety measure, _Black_ will check that the reformatted code still
140 produces a valid AST that is equivalent to the original. This slows it down. If you're
141 feeling confident, use `--fast`.
142
143 ## The _Black_ code style
144
145 _Black_ reformats entire files in place. It is not configurable. It doesn't take
146 previous formatting into account. It doesn't reformat blocks that start with
147 `# fmt: off` and end with `# fmt: on`. `# fmt: on/off` have to be on the same level of
148 indentation. It also recognizes [YAPF](https://github.com/google/yapf)'s block comments
149 to the same effect, as a courtesy for straddling code.
150
151 ### How _Black_ wraps lines
152
153 _Black_ ignores previous formatting and applies uniform horizontal and vertical
154 whitespace to your code. The rules for horizontal whitespace can be summarized as: do
155 whatever makes `pycodestyle` happy. The coding style used by _Black_ can be viewed as a
156 strict subset of PEP 8.
157
158 As for vertical whitespace, _Black_ tries to render one full expression or simple
159 statement per line. If this fits the allotted line length, great.
160
161 ```py3
162 # in:
163
164 j = [1,
165      2,
166      3
167 ]
168
169 # out:
170
171 j = [1, 2, 3]
172 ```
173
174 If not, _Black_ will look at the contents of the first outer matching brackets and put
175 that in a separate indented line.
176
177 ```py3
178 # in:
179
180 ImportantClass.important_method(exc, limit, lookup_lines, capture_locals, extra_argument)
181
182 # out:
183
184 ImportantClass.important_method(
185     exc, limit, lookup_lines, capture_locals, extra_argument
186 )
187 ```
188
189 If that still doesn't fit the bill, it will decompose the internal expression further
190 using the same rule, indenting matching brackets every time. If the contents of the
191 matching brackets pair are comma-separated (like an argument list, or a dict literal,
192 and so on) then _Black_ will first try to keep them on the same line with the matching
193 brackets. If that doesn't work, it will put all of them in separate lines.
194
195 ```py3
196 # in:
197
198 def very_important_function(template: str, *variables, file: os.PathLike, engine: str, header: bool = True, debug: bool = False):
199     """Applies `variables` to the `template` and writes to `file`."""
200     with open(file, 'w') as f:
201         ...
202
203 # out:
204
205 def very_important_function(
206     template: str,
207     *variables,
208     file: os.PathLike,
209     engine: str,
210     header: bool = True,
211     debug: bool = False,
212 ):
213     """Applies `variables` to the `template` and writes to `file`."""
214     with open(file, "w") as f:
215         ...
216 ```
217
218 You might have noticed that closing brackets are always dedented and that a trailing
219 comma is always added. Such formatting produces smaller diffs; when you add or remove an
220 element, it's always just one line. Also, having the closing bracket dedented provides a
221 clear delimiter between two distinct sections of the code that otherwise share the same
222 indentation level (like the arguments list and the docstring in the example above).
223
224 If a data structure literal (tuple, list, set, dict) or a line of "from" imports cannot
225 fit in the allotted length, it's always split into one element per line. This minimizes
226 diffs as well as enables readers of code to find which commit introduced a particular
227 entry. This also makes _Black_ compatible with [isort](https://pypi.org/p/isort/) with
228 the following configuration.
229
230 <details>
231 <summary>A compatible `.isort.cfg`</summary>
232
233 ```
234 [settings]
235 multi_line_output=3
236 include_trailing_comma=True
237 force_grid_wrap=0
238 use_parentheses=True
239 line_length=88
240 ```
241
242 The equivalent command line is:
243
244 ```
245 $ isort --multi-line=3 --trailing-comma --force-grid-wrap=0 --use-parentheses --line-width=88 [ file.py ]
246 ```
247
248 </details>
249
250 ### Line length
251
252 You probably noticed the peculiar default line length. _Black_ defaults to 88 characters
253 per line, which happens to be 10% over 80. This number was found to produce
254 significantly shorter files than sticking with 80 (the most popular), or even 79 (used
255 by the standard library). In general,
256 [90-ish seems like the wise choice](https://youtu.be/wf-BqAjZb8M?t=260).
257
258 If you're paid by the line of code you write, you can pass `--line-length` with a lower
259 number. _Black_ will try to respect that. However, sometimes it won't be able to without
260 breaking other rules. In those rare cases, auto-formatted code will exceed your allotted
261 limit.
262
263 You can also increase it, but remember that people with sight disabilities find it
264 harder to work with line lengths exceeding 100 characters. It also adversely affects
265 side-by-side diff review on typical screen resolutions. Long lines also make it harder
266 to present code neatly in documentation or talk slides.
267
268 If you're using Flake8, you can bump `max-line-length` to 88 and forget about it.
269 Alternatively, use [Bugbear](https://github.com/PyCQA/flake8-bugbear)'s B950 warning
270 instead of E501 and keep the max line length at 80 which you are probably already using.
271 You'd do it like this:
272
273 ```ini
274 [flake8]
275 max-line-length = 80
276 ...
277 select = C,E,F,W,B,B950
278 ignore = E203, E501, W503
279 ```
280
281 You'll find _Black_'s own .flake8 config file is configured like this. Explanation of
282 why W503 and E203 are disabled can be found further in this documentation. And if you're
283 curious about the reasoning behind B950,
284 [Bugbear's documentation](https://github.com/PyCQA/flake8-bugbear#opinionated-warnings)
285 explains it. The tl;dr is "it's like highway speed limits, we won't bother you if you
286 overdo it by a few km/h".
287
288 **If you're looking for a minimal, black-compatible flake8 configuration:**
289
290 ```ini
291 [flake8]
292 max-line-length = 88
293 extend-ignore = E203
294 ```
295
296 ### Empty lines
297
298 _Black_ avoids spurious vertical whitespace. This is in the spirit of PEP 8 which says
299 that in-function vertical whitespace should only be used sparingly.
300
301 _Black_ will allow single empty lines inside functions, and single and double empty
302 lines on module level left by the original editors, except when they're within
303 parenthesized expressions. Since such expressions are always reformatted to fit minimal
304 space, this whitespace is lost.
305
306 It will also insert proper spacing before and after function definitions. It's one line
307 before and after inner functions and two lines before and after module-level functions
308 and classes. _Black_ will not put empty lines between function/class definitions and
309 standalone comments that immediately precede the given function/class.
310
311 _Black_ will enforce single empty lines between a class-level docstring and the first
312 following field or method. This conforms to
313 [PEP 257](https://www.python.org/dev/peps/pep-0257/#multi-line-docstrings).
314
315 _Black_ won't insert empty lines after function docstrings unless that empty line is
316 required due to an inner function starting immediately after.
317
318 ### Trailing commas
319
320 _Black_ will add trailing commas to expressions that are split by comma where each
321 element is on its own line. This includes function signatures.
322
323 Unnecessary trailing commas are removed if an expression fits in one line. This makes it
324 1% more likely that your line won't exceed the allotted line length limit. Moreover, in
325 this scenario, if you added another argument to your call, you'd probably fit it in the
326 same line anyway. That doesn't make diffs any larger.
327
328 One exception to removing trailing commas is tuple expressions with just one element. In
329 this case _Black_ won't touch the single trailing comma as this would unexpectedly
330 change the underlying data type. Note that this is also the case when commas are used
331 while indexing. This is a tuple in disguise: `numpy_array[3, ]`.
332
333 One exception to adding trailing commas is function signatures containing `*`, `*args`,
334 or `**kwargs`. In this case a trailing comma is only safe to use on Python 3.6. _Black_
335 will detect if your file is already 3.6+ only and use trailing commas in this situation.
336 If you wonder how it knows, it looks for f-strings and existing use of trailing commas
337 in function signatures that have stars in them. In other words, if you'd like a trailing
338 comma in this situation and _Black_ didn't recognize it was safe to do so, put it there
339 manually and _Black_ will keep it.
340
341 ### Strings
342
343 _Black_ prefers double quotes (`"` and `"""`) over single quotes (`'` and `'''`). It
344 will replace the latter with the former as long as it does not result in more backslash
345 escapes than before.
346
347 _Black_ also standardizes string prefixes, making them always lowercase. On top of that,
348 if your code is already Python 3.6+ only or it's using the `unicode_literals` future
349 import, _Black_ will remove `u` from the string prefix as it is meaningless in those
350 scenarios.
351
352 The main reason to standardize on a single form of quotes is aesthetics. Having one kind
353 of quotes everywhere reduces reader distraction. It will also enable a future version of
354 _Black_ to merge consecutive string literals that ended up on the same line (see
355 [#26](https://github.com/psf/black/issues/26) for details).
356
357 Why settle on double quotes? They anticipate apostrophes in English text. They match the
358 docstring standard described in
359 [PEP 257](https://www.python.org/dev/peps/pep-0257/#what-is-a-docstring). An empty
360 string in double quotes (`""`) is impossible to confuse with a one double-quote
361 regardless of fonts and syntax highlighting used. On top of this, double quotes for
362 strings are consistent with C which Python interacts a lot with.
363
364 On certain keyboard layouts like US English, typing single quotes is a bit easier than
365 double quotes. The latter requires use of the Shift key. My recommendation here is to
366 keep using whatever is faster to type and let _Black_ handle the transformation.
367
368 If you are adopting _Black_ in a large project with pre-existing string conventions
369 (like the popular
370 ["single quotes for data, double quotes for human-readable strings"](https://stackoverflow.com/a/56190)),
371 you can pass `--skip-string-normalization` on the command line. This is meant as an
372 adoption helper, avoid using this for new projects.
373
374 ### Numeric literals
375
376 _Black_ standardizes most numeric literals to use lowercase letters for the syntactic
377 parts and uppercase letters for the digits themselves: `0xAB` instead of `0XAB` and
378 `1e10` instead of `1E10`. Python 2 long literals are styled as `2L` instead of `2l` to
379 avoid confusion between `l` and `1`.
380
381 ### Line breaks & binary operators
382
383 _Black_ will break a line before a binary operator when splitting a block of code over
384 multiple lines. This is so that _Black_ is compliant with the recent changes in the
385 [PEP 8](https://www.python.org/dev/peps/pep-0008/#should-a-line-break-before-or-after-a-binary-operator)
386 style guide, which emphasizes that this approach improves readability.
387
388 This behaviour may raise `W503 line break before binary operator` warnings in style
389 guide enforcement tools like Flake8. Since `W503` is not PEP 8 compliant, you should
390 tell Flake8 to ignore these warnings.
391
392 ### Slices
393
394 PEP 8
395 [recommends](https://www.python.org/dev/peps/pep-0008/#whitespace-in-expressions-and-statements)
396 to treat `:` in slices as a binary operator with the lowest priority, and to leave an
397 equal amount of space on either side, except if a parameter is omitted (e.g.
398 `ham[1 + 1 :]`). It also states that for extended slices, both `:` operators have to
399 have the same amount of spacing, except if a parameter is omitted (`ham[1 + 1 ::]`).
400 _Black_ enforces these rules consistently.
401
402 This behaviour may raise `E203 whitespace before ':'` warnings in style guide
403 enforcement tools like Flake8. Since `E203` is not PEP 8 compliant, you should tell
404 Flake8 to ignore these warnings.
405
406 ### Parentheses
407
408 Some parentheses are optional in the Python grammar. Any expression can be wrapped in a
409 pair of parentheses to form an atom. There are a few interesting cases:
410
411 - `if (...):`
412 - `while (...):`
413 - `for (...) in (...):`
414 - `assert (...), (...)`
415 - `from X import (...)`
416 - assignments like:
417   - `target = (...)`
418   - `target: type = (...)`
419   - `some, *un, packing = (...)`
420   - `augmented += (...)`
421
422 In those cases, parentheses are removed when the entire statement fits in one line, or
423 if the inner expression doesn't have any delimiters to further split on. If there is
424 only a single delimiter and the expression starts or ends with a bracket, the
425 parenthesis can also be successfully omitted since the existing bracket pair will
426 organize the expression neatly anyway. Otherwise, the parentheses are added.
427
428 Please note that _Black_ does not add or remove any additional nested parentheses that
429 you might want to have for clarity or further code organization. For example those
430 parentheses are not going to be removed:
431
432 ```py3
433 return not (this or that)
434 decision = (maybe.this() and values > 0) or (maybe.that() and values < 0)
435 ```
436
437 ### Call chains
438
439 Some popular APIs, like ORMs, use call chaining. This API style is known as a
440 [fluent interface](https://en.wikipedia.org/wiki/Fluent_interface). _Black_ formats
441 those by treating dots that follow a call or an indexing operation like a very low
442 priority delimiter. It's easier to show the behavior than to explain it. Look at the
443 example:
444
445 ```py3
446 def example(session):
447     result = (
448         session.query(models.Customer.id)
449         .filter(
450             models.Customer.account_id == account_id,
451             models.Customer.email == email_address,
452         )
453         .order_by(models.Customer.id.asc())
454         .all()
455     )
456 ```
457
458 ### Typing stub files
459
460 PEP 484 describes the syntax for type hints in Python. One of the use cases for typing
461 is providing type annotations for modules which cannot contain them directly (they might
462 be written in C, or they might be third-party, or their implementation may be overly
463 dynamic, and so on).
464
465 To solve this,
466 [stub files with the `.pyi` file extension](https://www.python.org/dev/peps/pep-0484/#stub-files)
467 can be used to describe typing information for an external module. Those stub files omit
468 the implementation of classes and functions they describe, instead they only contain the
469 structure of the file (listing globals, functions, and classes with their members). The
470 recommended code style for those files is more terse than PEP 8:
471
472 - prefer `...` on the same line as the class/function signature;
473 - avoid vertical whitespace between consecutive module-level functions, names, or
474   methods and fields within a single class;
475 - use a single blank line between top-level class definitions, or none if the classes
476   are very small.
477
478 _Black_ enforces the above rules. There are additional guidelines for formatting `.pyi`
479 file that are not enforced yet but might be in a future version of the formatter:
480
481 - all function bodies should be empty (contain `...` instead of the body);
482 - do not use docstrings;
483 - prefer `...` over `pass`;
484 - for arguments with a default, use `...` instead of the actual default;
485 - avoid using string literals in type annotations, stub files support forward references
486   natively (like Python 3.7 code with `from __future__ import annotations`);
487 - use variable annotations instead of type comments, even for stubs that target older
488   versions of Python;
489 - for arguments that default to `None`, use `Optional[]` explicitly;
490 - use `float` instead of `Union[int, float]`.
491
492 ## pyproject.toml
493
494 _Black_ is able to read project-specific default values for its command line options
495 from a `pyproject.toml` file. This is especially useful for specifying custom
496 `--include` and `--exclude` patterns for your project.
497
498 **Pro-tip**: If you're asking yourself "Do I need to configure anything?" the answer is
499 "No". _Black_ is all about sensible defaults.
500
501 ### What on Earth is a `pyproject.toml` file?
502
503 [PEP 518](https://www.python.org/dev/peps/pep-0518/) defines `pyproject.toml` as a
504 configuration file to store build system requirements for Python projects. With the help
505 of tools like [Poetry](https://poetry.eustace.io/) or
506 [Flit](https://flit.readthedocs.io/en/latest/) it can fully replace the need for
507 `setup.py` and `setup.cfg` files.
508
509 ### Where _Black_ looks for the file
510
511 By default _Black_ looks for `pyproject.toml` starting from the common base directory of
512 all files and directories passed on the command line. If it's not there, it looks in
513 parent directories. It stops looking when it finds the file, or a `.git` directory, or a
514 `.hg` directory, or the root of the file system, whichever comes first.
515
516 If you're formatting standard input, _Black_ will look for configuration starting from
517 the current working directory.
518
519 You can also explicitly specify the path to a particular file that you want with
520 `--config`. In this situation _Black_ will not look for any other file.
521
522 If you're running with `--verbose`, you will see a blue message if a file was found and
523 used.
524
525 Please note `blackd` will not use `pyproject.toml` configuration.
526
527 ### Configuration format
528
529 As the file extension suggests, `pyproject.toml` is a
530 [TOML](https://github.com/toml-lang/toml) file. It contains separate sections for
531 different tools. _Black_ is using the `[tool.black]` section. The option keys are the
532 same as long names of options on the command line.
533
534 Note that you have to use single-quoted strings in TOML for regular expressions. It's
535 the equivalent of r-strings in Python. Multiline strings are treated as verbose regular
536 expressions by Black. Use `[ ]` to denote a significant space character.
537
538 <details>
539 <summary>Example `pyproject.toml`</summary>
540
541 ```toml
542 [tool.black]
543 line-length = 88
544 target-version = ['py37']
545 include = '\.pyi?$'
546 exclude = '''
547
548 (
549   /(
550       \.eggs         # exclude a few common directories in the
551     | \.git          # root of the project
552     | \.hg
553     | \.mypy_cache
554     | \.tox
555     | \.venv
556     | _build
557     | buck-out
558     | build
559     | dist
560   )/
561   | foo.py           # also separately exclude a file named foo.py in
562                      # the root of the project
563 )
564 '''
565 ```
566
567 </details>
568
569 ### Lookup hierarchy
570
571 Command-line options have defaults that you can see in `--help`. A `pyproject.toml` can
572 override those defaults. Finally, options provided by the user on the command line
573 override both.
574
575 _Black_ will only ever use one `pyproject.toml` file during an entire run. It doesn't
576 look for multiple files, and doesn't compose configuration from different levels of the
577 file hierarchy.
578
579 ## Editor integration
580
581 ### Emacs
582
583 Use [proofit404/blacken](https://github.com/proofit404/blacken) or
584 [Elpy](https://github.com/jorgenschaefer/elpy).
585
586 ### PyCharm/IntelliJ IDEA
587
588 1. Install `black`.
589
590 ```console
591 $ pip install black
592 ```
593
594 2. Locate your `black` installation folder.
595
596 On macOS / Linux / BSD:
597
598 ```console
599 $ which black
600 /usr/local/bin/black  # possible location
601 ```
602
603 On Windows:
604
605 ```console
606 $ where black
607 %LocalAppData%\Programs\Python\Python36-32\Scripts\black.exe  # possible location
608 ```
609
610 3. Open External tools in PyCharm/IntelliJ IDEA
611
612 On macOS:
613
614 `PyCharm -> Preferences -> Tools -> External Tools`
615
616 On Windows / Linux / BSD:
617
618 `File -> Settings -> Tools -> External Tools`
619
620 4. Click the + icon to add a new external tool with the following values:
621
622    - Name: Black
623    - Description: Black is the uncompromising Python code formatter.
624    - Program: <install_location_from_step_2>
625    - Arguments: `"$FilePath$"`
626
627 5. Format the currently opened file by selecting `Tools -> External Tools -> black`.
628
629    - Alternatively, you can set a keyboard shortcut by navigating to
630      `Preferences or Settings -> Keymap -> External Tools -> External Tools - Black`.
631
632 6. Optionally, run _Black_ on every file save:
633
634    1. Make sure you have the
635       [File Watcher](https://plugins.jetbrains.com/plugin/7177-file-watchers) plugin
636       installed.
637    2. Go to `Preferences or Settings -> Tools -> File Watchers` and click `+` to add a
638       new watcher:
639       - Name: Black
640       - File type: Python
641       - Scope: Project Files
642       - Program: <install_location_from_step_2>
643       - Arguments: `$FilePath$`
644       - Output paths to refresh: `$FilePath$`
645       - Working directory: `$ProjectFileDir$`
646
647    - Uncheck "Auto-save edited files to trigger the watcher"
648
649 ### Wing IDE
650
651 Wing supports black via the OS Commands tool, as explained in the Wing documentation on
652 [pep8 formatting](https://wingware.com/doc/edit/pep8). The detailed procedure is:
653
654 1. Install `black`.
655
656 ```console
657 $ pip install black
658 ```
659
660 2. Make sure it runs from the command line, e.g.
661
662 ```console
663 $ black --help
664 ```
665
666 3. In Wing IDE, activate the **OS Commands** panel and define the command **black** to
667    execute black on the currently selected file:
668
669 - Use the Tools -> OS Commands menu selection
670 - click on **+** in **OS Commands** -> New: Command line..
671   - Title: black
672   - Command Line: black %s
673   - I/O Encoding: Use Default
674   - Key Binding: F1
675   - [x] Raise OS Commands when executed
676   - [x] Auto-save files before execution
677   - [x] Line mode
678
679 4. Select a file in the editor and press **F1** , or whatever key binding you selected
680    in step 3, to reformat the file.
681
682 ### Vim
683
684 Commands and shortcuts:
685
686 - `:Black` to format the entire file (ranges not supported);
687 - `:BlackUpgrade` to upgrade _Black_ inside the virtualenv;
688 - `:BlackVersion` to get the current version of _Black_ inside the virtualenv.
689
690 Configuration:
691
692 - `g:black_fast` (defaults to `0`)
693 - `g:black_linelength` (defaults to `88`)
694 - `g:black_skip_string_normalization` (defaults to `0`)
695 - `g:black_virtualenv` (defaults to `~/.vim/black` or `~/.local/share/nvim/black`)
696
697 To install with [vim-plug](https://github.com/junegunn/vim-plug):
698
699 ```
700 Plug 'psf/black'
701 ```
702
703 or with [Vundle](https://github.com/VundleVim/Vundle.vim):
704
705 ```
706 Plugin 'psf/black'
707 ```
708
709 or you can copy the plugin from
710 [plugin/black.vim](https://github.com/psf/black/tree/master/plugin/black.vim).
711
712 ```
713 mkdir -p ~/.vim/pack/python/start/black/plugin
714 curl https://raw.githubusercontent.com/psf/black/master/plugin/black.vim -o ~/.vim/pack/python/start/black/plugin/black.vim
715 ```
716
717 Let me know if this requires any changes to work with Vim 8's builtin `packadd`, or
718 Pathogen, and so on.
719
720 This plugin **requires Vim 7.0+ built with Python 3.6+ support**. It needs Python 3.6 to
721 be able to run _Black_ inside the Vim process which is much faster than calling an
722 external command.
723
724 On first run, the plugin creates its own virtualenv using the right Python version and
725 automatically installs _Black_. You can upgrade it later by calling `:BlackUpgrade` and
726 restarting Vim.
727
728 If you need to do anything special to make your virtualenv work and install _Black_ (for
729 example you want to run a version from master), create a virtualenv manually and point
730 `g:black_virtualenv` to it. The plugin will use it.
731
732 To run _Black_ on save, add the following line to `.vimrc` or `init.vim`:
733
734 ```
735 autocmd BufWritePre *.py execute ':Black'
736 ```
737
738 To run _Black_ on a key press (e.g. F9 below), add this:
739
740 ```
741 nnoremap <F9> :Black<CR>
742 ```
743
744 **How to get Vim with Python 3.6?** On Ubuntu 17.10 Vim comes with Python 3.6 by
745 default. On macOS with Homebrew run: `brew install vim`. When building Vim from source,
746 use: `./configure --enable-python3interp=yes`. There's many guides online how to do
747 this.
748
749 ### Visual Studio Code
750
751 Use the
752 [Python extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python)
753 ([instructions](https://code.visualstudio.com/docs/python/editing#_formatting)).
754
755 ### SublimeText 3
756
757 Use [sublack plugin](https://github.com/jgirardet/sublack).
758
759 ### Jupyter Notebook Magic
760
761 Use [blackcellmagic](https://github.com/csurfer/blackcellmagic).
762
763 ### Python Language Server
764
765 If your editor supports the [Language Server Protocol](https://langserver.org/) (Atom,
766 Sublime Text, Visual Studio Code and many more), you can use the
767 [Python Language Server](https://github.com/palantir/python-language-server) with the
768 [pyls-black](https://github.com/rupert/pyls-black) plugin.
769
770 ### Atom/Nuclide
771
772 Use [python-black](https://atom.io/packages/python-black).
773
774 ### Kakoune
775
776 Add the following hook to your kakrc, then run black with `:format`.
777
778 ```
779 hook global WinSetOption filetype=python %{
780     set-option window formatcmd 'black -q  -'
781 }
782 ```
783
784 ### Thonny
785
786 Use [Thonny-black-code-format](https://github.com/Franccisco/thonny-black-code-format).
787
788 ### Other editors
789
790 Other editors will require external contributions.
791
792 Patches welcome! ✨ 🍰 ✨
793
794 Any tool that can pipe code through _Black_ using its stdio mode (just
795 [use `-` as the file name](https://www.tldp.org/LDP/abs/html/special-chars.html#DASHREF2)).
796 The formatted code will be returned on stdout (unless `--check` was passed). _Black_
797 will still emit messages on stderr but that shouldn't affect your use case.
798
799 This can be used for example with PyCharm's or IntelliJ's
800 [File Watchers](https://www.jetbrains.com/help/pycharm/file-watchers.html).
801
802 ## blackd
803
804 `blackd` is a small HTTP server that exposes _Black_'s functionality over a simple
805 protocol. The main benefit of using it is to avoid paying the cost of starting up a new
806 _Black_ process every time you want to blacken a file.
807
808 ### Usage
809
810 `blackd` is not packaged alongside _Black_ by default because it has additional
811 dependencies. You will need to do `pip install black[d]` to install it.
812
813 You can start the server on the default port, binding only to the local interface by
814 running `blackd`. You will see a single line mentioning the server's version, and the
815 host and port it's listening on. `blackd` will then print an access log similar to most
816 web servers on standard output, merged with any exception traces caused by invalid
817 formatting requests.
818
819 `blackd` provides even less options than _Black_. You can see them by running
820 `blackd --help`:
821
822 ```text
823 Usage: blackd [OPTIONS]
824
825 Options:
826   --bind-host TEXT                Address to bind the server to.
827   --bind-port INTEGER             Port to listen on
828   --version                       Show the version and exit.
829   -h, --help                      Show this message and exit.
830 ```
831
832 There is no official blackd client tool (yet!). You can test that blackd is working
833 using `curl`:
834
835 ```
836 blackd --bind-port 9090 &  # or let blackd choose a port
837 curl -s -XPOST "localhost:9090" -d "print('valid')"
838 ```
839
840 ### Protocol
841
842 `blackd` only accepts `POST` requests at the `/` path. The body of the request should
843 contain the python source code to be formatted, encoded according to the `charset` field
844 in the `Content-Type` request header. If no `charset` is specified, `blackd` assumes
845 `UTF-8`.
846
847 There are a few HTTP headers that control how the source is formatted. These correspond
848 to command line flags for _Black_. There is one exception to this: `X-Protocol-Version`
849 which if present, should have the value `1`, otherwise the request is rejected with
850 `HTTP 501` (Not Implemented).
851
852 The headers controlling how code is formatted are:
853
854 - `X-Line-Length`: corresponds to the `--line-length` command line flag.
855 - `X-Skip-String-Normalization`: corresponds to the `--skip-string-normalization`
856   command line flag. If present and its value is not the empty string, no string
857   normalization will be performed.
858 - `X-Fast-Or-Safe`: if set to `fast`, `blackd` will act as _Black_ does when passed the
859   `--fast` command line flag.
860 - `X-Python-Variant`: if set to `pyi`, `blackd` will act as _Black_ does when passed the
861   `--pyi` command line flag. Otherwise, its value must correspond to a Python version or
862   a set of comma-separated Python versions, optionally prefixed with `py`. For example,
863   to request code that is compatible with Python 3.5 and 3.6, set the header to
864   `py3.5,py3.6`.
865 - `X-Diff`: corresponds to the `--diff` command line flag. If present, a diff of the
866   formats will be output.
867
868 If any of these headers are set to invalid values, `blackd` returns a `HTTP 400` error
869 response, mentioning the name of the problematic header in the message body.
870
871 Apart from the above, `blackd` can produce the following response codes:
872
873 - `HTTP 204`: If the input is already well-formatted. The response body is empty.
874 - `HTTP 200`: If formatting was needed on the input. The response body contains the
875   blackened Python code, and the `Content-Type` header is set accordingly.
876 - `HTTP 400`: If the input contains a syntax error. Details of the error are returned in
877   the response body.
878 - `HTTP 500`: If there was any kind of error while trying to format the input. The
879   response body contains a textual representation of the error.
880
881 The response headers include a `X-Black-Version` header containing the version of
882 _Black_.
883
884 ## Version control integration
885
886 Use [pre-commit](https://pre-commit.com/). Once you
887 [have it installed](https://pre-commit.com/#install), add this to the
888 `.pre-commit-config.yaml` in your repository:
889
890 ```yaml
891 repos:
892   - repo: https://github.com/psf/black
893     rev: stable
894     hooks:
895       - id: black
896         language_version: python3.6
897 ```
898
899 Then run `pre-commit install` and you're ready to go.
900
901 Avoid using `args` in the hook. Instead, store necessary configuration in
902 `pyproject.toml` so that editors and command-line usage of Black all behave consistently
903 for your project. See _Black_'s own
904 [pyproject.toml](https://github.com/psf/black/blob/master/pyproject.toml) for an
905 example.
906
907 If you're already using Python 3.7, switch the `language_version` accordingly. Finally,
908 `stable` is a tag that is pinned to the latest release on PyPI. If you'd rather run on
909 master, this is also an option.
910
911 ## Ignoring unmodified files
912
913 _Black_ remembers files it has already formatted, unless the `--diff` flag is used or
914 code is passed via standard input. This information is stored per-user. The exact
915 location of the file depends on the _Black_ version and the system on which _Black_ is
916 run. The file is non-portable. The standard location on common operating systems is:
917
918 - Windows:
919   `C:\\Users\<username>\AppData\Local\black\black\Cache\<version>\cache.<line-length>.<file-mode>.pickle`
920 - macOS:
921   `/Users/<username>/Library/Caches/black/<version>/cache.<line-length>.<file-mode>.pickle`
922 - Linux:
923   `/home/<username>/.cache/black/<version>/cache.<line-length>.<file-mode>.pickle`
924
925 `file-mode` is an int flag that determines whether the file was formatted as 3.6+ only,
926 as .pyi, and whether string normalization was omitted.
927
928 To override the location of these files on macOS or Linux, set the environment variable
929 `XDG_CACHE_HOME` to your preferred location. For example, if you want to put the cache
930 in the directory you're running _Black_ from, set `XDG_CACHE_HOME=.cache`. _Black_ will
931 then write the above files to `.cache/black/<version>/`.
932
933 ## Used by
934
935 The following notable open-source projects trust _Black_ with enforcing a consistent
936 code style: pytest, tox, Pyramid, Django Channels, Hypothesis, attrs, SQLAlchemy,
937 Poetry, PyPA applications (Warehouse, Pipenv, virtualenv), pandas, Pillow, every Datadog
938 Agent Integration, Home Assistant.
939
940 Are we missing anyone? Let us know.
941
942 ## Testimonials
943
944 **Dusty Phillips**,
945 [writer](https://smile.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=dusty+phillips):
946
947 > _Black_ is opinionated so you don't have to be.
948
949 **Hynek Schlawack**, [creator of `attrs`](https://www.attrs.org/), core developer of
950 Twisted and CPython:
951
952 > An auto-formatter that doesn't suck is all I want for Xmas!
953
954 **Carl Meyer**, [Django](https://www.djangoproject.com/) core developer:
955
956 > At least the name is good.
957
958 **Kenneth Reitz**, creator of [`requests`](http://python-requests.org/) and
959 [`pipenv`](https://docs.pipenv.org/):
960
961 > This vastly improves the formatting of our code. Thanks a ton!
962
963 ## Show your style
964
965 Use the badge in your project's README.md:
966
967 ```markdown
968 [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
969 ```
970
971 Using the badge in README.rst:
972
973 ```
974 .. image:: https://img.shields.io/badge/code%20style-black-000000.svg
975     :target: https://github.com/psf/black
976 ```
977
978 Looks like this:
979 [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
980
981 ## License
982
983 MIT
984
985 ## Contributing to _Black_
986
987 In terms of inspiration, _Black_ is about as configurable as _gofmt_. This is
988 deliberate.
989
990 Bug reports and fixes are always welcome! However, before you suggest a new feature or
991 configuration knob, ask yourself why you want it. If it enables better integration with
992 some workflow, fixes an inconsistency, speeds things up, and so on - go for it! On the
993 other hand, if your answer is "because I don't like a particular formatting" then you're
994 not ready to embrace _Black_ yet. Such changes are unlikely to get accepted. You can
995 still try but prepare to be disappointed.
996
997 More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
998
999 ## Change Log
1000
1001 ### 19.10b0
1002
1003 - added support for PEP 572 assignment expressions (#711)
1004
1005 - added support for PEP 570 positional-only arguments (#943)
1006
1007 - added support for async generators (#593)
1008
1009 - added support for pre-splitting collections by putting an explicit trailing comma
1010   inside (#826)
1011
1012 - added `black -c` as a way to format code passed from the command line (#761)
1013
1014 - --safe now works with Python 2 code (#840)
1015
1016 - fixed grammar selection for Python 2-specific code (#765)
1017
1018 - fixed feature detection for trailing commas in function definitions and call sites
1019   (#763)
1020
1021 - `# fmt: off`/`# fmt: on` comment pairs placed multiple times within the same block of
1022   code now behave correctly (#1005)
1023
1024 - _Black_ no longer crashes on Windows machines with more than 61 cores (#838)
1025
1026 - _Black_ no longer crashes on standalone comments prepended with a backslash (#767)
1027
1028 - _Black_ no longer crashes on `from` ... `import` blocks with comments (#829)
1029
1030 - _Black_ no longer crashes on Python 3.7 on some platform configurations (#494)
1031
1032 - _Black_ no longer fails on comments in from-imports (#671)
1033
1034 - _Black_ no longer fails when the file starts with a backslash (#922)
1035
1036 - _Black_ no longer merges regular comments with type comments (#1027)
1037
1038 - _Black_ no longer splits long lines that contain type comments (#997)
1039
1040 - removed unnecessary parentheses around `yield` expressions (#834)
1041
1042 - added parentheses around long tuples in unpacking assignments (#832)
1043
1044 - added parentheses around complex powers when they are prefixed by a unary operator
1045   (#646)
1046
1047 - fixed bug that led _Black_ format some code with a line length target of 1 (#762)
1048
1049 - _Black_ no longer introduces quotes in f-string subexpressions on string boundaries
1050   (#863)
1051
1052 - if _Black_ puts parenthesis around a single expression, it moves comments to the
1053   wrapped expression instead of after the brackets (#872)
1054
1055 - `blackd` now returns the version of _Black_ in the response headers (#1013)
1056
1057 - `blackd` can now output the diff of formats on source code when the `X-Diff` header is
1058   provided (#969)
1059
1060 ### 19.3b0
1061
1062 - new option `--target-version` to control which Python versions _Black_-formatted code
1063   should target (#618)
1064
1065 - deprecated `--py36` (use `--target-version=py36` instead) (#724)
1066
1067 - _Black_ no longer normalizes numeric literals to include `_` separators (#696)
1068
1069 - long `del` statements are now split into multiple lines (#698)
1070
1071 - type comments are no longer mangled in function signatures
1072
1073 - improved performance of formatting deeply nested data structures (#509)
1074
1075 - _Black_ now properly formats multiple files in parallel on Windows (#632)
1076
1077 - _Black_ now creates cache files atomically which allows it to be used in parallel
1078   pipelines (like `xargs -P8`) (#673)
1079
1080 - _Black_ now correctly indents comments in files that were previously formatted with
1081   tabs (#262)
1082
1083 - `blackd` now supports CORS (#622)
1084
1085 ### 18.9b0
1086
1087 - numeric literals are now formatted by _Black_ (#452, #461, #464, #469):
1088
1089   - numeric literals are normalized to include `_` separators on Python 3.6+ code
1090
1091   - added `--skip-numeric-underscore-normalization` to disable the above behavior and
1092     leave numeric underscores as they were in the input
1093
1094   - code with `_` in numeric literals is recognized as Python 3.6+
1095
1096   - most letters in numeric literals are lowercased (e.g., in `1e10`, `0x01`)
1097
1098   - hexadecimal digits are always uppercased (e.g. `0xBADC0DE`)
1099
1100 - added `blackd`, see [its documentation](#blackd) for more info (#349)
1101
1102 - adjacent string literals are now correctly split into multiple lines (#463)
1103
1104 - trailing comma is now added to single imports that don't fit on a line (#250)
1105
1106 - cache is now populated when `--check` is successful for a file which speeds up
1107   consecutive checks of properly formatted unmodified files (#448)
1108
1109 - whitespace at the beginning of the file is now removed (#399)
1110
1111 - fixed mangling [pweave](http://mpastell.com/pweave/) and
1112   [Spyder IDE](https://pythonhosted.org/spyder/) special comments (#532)
1113
1114 - fixed unstable formatting when unpacking big tuples (#267)
1115
1116 - fixed parsing of `__future__` imports with renames (#389)
1117
1118 - fixed scope of `# fmt: off` when directly preceding `yield` and other nodes (#385)
1119
1120 - fixed formatting of lambda expressions with default arguments (#468)
1121
1122 - fixed `async for` statements: _Black_ no longer breaks them into separate lines (#372)
1123
1124 - note: the Vim plugin stopped registering `,=` as a default chord as it turned out to
1125   be a bad idea (#415)
1126
1127 ### 18.6b4
1128
1129 - hotfix: don't freeze when multiple comments directly precede `# fmt: off` (#371)
1130
1131 ### 18.6b3
1132
1133 - typing stub files (`.pyi`) now have blank lines added after constants (#340)
1134
1135 - `# fmt: off` and `# fmt: on` are now much more dependable:
1136
1137   - they now work also within bracket pairs (#329)
1138
1139   - they now correctly work across function/class boundaries (#335)
1140
1141   - they now work when an indentation block starts with empty lines or misaligned
1142     comments (#334)
1143
1144 - made Click not fail on invalid environments; note that Click is right but the
1145   likelihood we'll need to access non-ASCII file paths when dealing with Python source
1146   code is low (#277)
1147
1148 - fixed improper formatting of f-strings with quotes inside interpolated expressions
1149   (#322)
1150
1151 - fixed unnecessary slowdown when long list literals where found in a file
1152
1153 - fixed unnecessary slowdown on AST nodes with very many siblings
1154
1155 - fixed cannibalizing backslashes during string normalization
1156
1157 - fixed a crash due to symbolic links pointing outside of the project directory (#338)
1158
1159 ### 18.6b2
1160
1161 - added `--config` (#65)
1162
1163 - added `-h` equivalent to `--help` (#316)
1164
1165 - fixed improper unmodified file caching when `-S` was used
1166
1167 - fixed extra space in string unpacking (#305)
1168
1169 - fixed formatting of empty triple quoted strings (#313)
1170
1171 - fixed unnecessary slowdown in comment placement calculation on lines without comments
1172
1173 ### 18.6b1
1174
1175 - hotfix: don't output human-facing information on stdout (#299)
1176
1177 - hotfix: don't output cake emoji on non-zero return code (#300)
1178
1179 ### 18.6b0
1180
1181 - added `--include` and `--exclude` (#270)
1182
1183 - added `--skip-string-normalization` (#118)
1184
1185 - added `--verbose` (#283)
1186
1187 - the header output in `--diff` now actually conforms to the unified diff spec
1188
1189 - fixed long trivial assignments being wrapped in unnecessary parentheses (#273)
1190
1191 - fixed unnecessary parentheses when a line contained multiline strings (#232)
1192
1193 - fixed stdin handling not working correctly if an old version of Click was used (#276)
1194
1195 - _Black_ now preserves line endings when formatting a file in place (#258)
1196
1197 ### 18.5b1
1198
1199 - added `--pyi` (#249)
1200
1201 - added `--py36` (#249)
1202
1203 - Python grammar pickle caches are stored with the formatting caches, making _Black_
1204   work in environments where site-packages is not user-writable (#192)
1205
1206 - _Black_ now enforces a PEP 257 empty line after a class-level docstring (and/or
1207   fields) and the first method
1208
1209 - fixed invalid code produced when standalone comments were present in a trailer that
1210   was omitted from line splitting on a large expression (#237)
1211
1212 - fixed optional parentheses being removed within `# fmt: off` sections (#224)
1213
1214 - fixed invalid code produced when stars in very long imports were incorrectly wrapped
1215   in optional parentheses (#234)
1216
1217 - fixed unstable formatting when inline comments were moved around in a trailer that was
1218   omitted from line splitting on a large expression (#238)
1219
1220 - fixed extra empty line between a class declaration and the first method if no class
1221   docstring or fields are present (#219)
1222
1223 - fixed extra empty line between a function signature and an inner function or inner
1224   class (#196)
1225
1226 ### 18.5b0
1227
1228 - call chains are now formatted according to the
1229   [fluent interfaces](https://en.wikipedia.org/wiki/Fluent_interface) style (#67)
1230
1231 - data structure literals (tuples, lists, dictionaries, and sets) are now also always
1232   exploded like imports when they don't fit in a single line (#152)
1233
1234 - slices are now formatted according to PEP 8 (#178)
1235
1236 - parentheses are now also managed automatically on the right-hand side of assignments
1237   and return statements (#140)
1238
1239 - math operators now use their respective priorities for delimiting multiline
1240   expressions (#148)
1241
1242 - optional parentheses are now omitted on expressions that start or end with a bracket
1243   and only contain a single operator (#177)
1244
1245 - empty parentheses in a class definition are now removed (#145, #180)
1246
1247 - string prefixes are now standardized to lowercase and `u` is removed on Python 3.6+
1248   only code and Python 2.7+ code with the `unicode_literals` future import (#188, #198,
1249   #199)
1250
1251 - typing stub files (`.pyi`) are now formatted in a style that is consistent with PEP
1252   484 (#207, #210)
1253
1254 - progress when reformatting many files is now reported incrementally
1255
1256 - fixed trailers (content with brackets) being unnecessarily exploded into their own
1257   lines after a dedented closing bracket (#119)
1258
1259 - fixed an invalid trailing comma sometimes left in imports (#185)
1260
1261 - fixed non-deterministic formatting when multiple pairs of removable parentheses were
1262   used (#183)
1263
1264 - fixed multiline strings being unnecessarily wrapped in optional parentheses in long
1265   assignments (#215)
1266
1267 - fixed not splitting long from-imports with only a single name
1268
1269 - fixed Python 3.6+ file discovery by also looking at function calls with unpacking.
1270   This fixed non-deterministic formatting if trailing commas where used both in function
1271   signatures with stars and function calls with stars but the former would be
1272   reformatted to a single line.
1273
1274 - fixed crash on dealing with optional parentheses (#193)
1275
1276 - fixed "is", "is not", "in", and "not in" not considered operators for splitting
1277   purposes
1278
1279 - fixed crash when dead symlinks where encountered
1280
1281 ### 18.4a4
1282
1283 - don't populate the cache on `--check` (#175)
1284
1285 ### 18.4a3
1286
1287 - added a "cache"; files already reformatted that haven't changed on disk won't be
1288   reformatted again (#109)
1289
1290 - `--check` and `--diff` are no longer mutually exclusive (#149)
1291
1292 - generalized star expression handling, including double stars; this fixes
1293   multiplication making expressions "unsafe" for trailing commas (#132)
1294
1295 - _Black_ no longer enforces putting empty lines behind control flow statements (#90)
1296
1297 - _Black_ now splits imports like "Mode 3 + trailing comma" of isort (#127)
1298
1299 - fixed comment indentation when a standalone comment closes a block (#16, #32)
1300
1301 - fixed standalone comments receiving extra empty lines if immediately preceding a
1302   class, def, or decorator (#56, #154)
1303
1304 - fixed `--diff` not showing entire path (#130)
1305
1306 - fixed parsing of complex expressions after star and double stars in function calls
1307   (#2)
1308
1309 - fixed invalid splitting on comma in lambda arguments (#133)
1310
1311 - fixed missing splits of ternary expressions (#141)
1312
1313 ### 18.4a2
1314
1315 - fixed parsing of unaligned standalone comments (#99, #112)
1316
1317 - fixed placement of dictionary unpacking inside dictionary literals (#111)
1318
1319 - Vim plugin now works on Windows, too
1320
1321 - fixed unstable formatting when encountering unnecessarily escaped quotes in a string
1322   (#120)
1323
1324 ### 18.4a1
1325
1326 - added `--quiet` (#78)
1327
1328 - added automatic parentheses management (#4)
1329
1330 - added [pre-commit](https://pre-commit.com) integration (#103, #104)
1331
1332 - fixed reporting on `--check` with multiple files (#101, #102)
1333
1334 - fixed removing backslash escapes from raw strings (#100, #105)
1335
1336 ### 18.4a0
1337
1338 - added `--diff` (#87)
1339
1340 - add line breaks before all delimiters, except in cases like commas, to better comply
1341   with PEP 8 (#73)
1342
1343 - standardize string literals to use double quotes (almost) everywhere (#75)
1344
1345 - fixed handling of standalone comments within nested bracketed expressions; _Black_
1346   will no longer produce super long lines or put all standalone comments at the end of
1347   the expression (#22)
1348
1349 - fixed 18.3a4 regression: don't crash and burn on empty lines with trailing whitespace
1350   (#80)
1351
1352 - fixed 18.3a4 regression: `# yapf: disable` usage as trailing comment would cause
1353   _Black_ to not emit the rest of the file (#95)
1354
1355 - when CTRL+C is pressed while formatting many files, _Black_ no longer freaks out with
1356   a flurry of asyncio-related exceptions
1357
1358 - only allow up to two empty lines on module level and only single empty lines within
1359   functions (#74)
1360
1361 ### 18.3a4
1362
1363 - `# fmt: off` and `# fmt: on` are implemented (#5)
1364
1365 - automatic detection of deprecated Python 2 forms of print statements and exec
1366   statements in the formatted file (#49)
1367
1368 - use proper spaces for complex expressions in default values of typed function
1369   arguments (#60)
1370
1371 - only return exit code 1 when --check is used (#50)
1372
1373 - don't remove single trailing commas from square bracket indexing (#59)
1374
1375 - don't omit whitespace if the previous factor leaf wasn't a math operator (#55)
1376
1377 - omit extra space in kwarg unpacking if it's the first argument (#46)
1378
1379 - omit extra space in
1380   [Sphinx auto-attribute comments](http://www.sphinx-doc.org/en/stable/ext/autodoc.html#directive-autoattribute)
1381   (#68)
1382
1383 ### 18.3a3
1384
1385 - don't remove single empty lines outside of bracketed expressions (#19)
1386
1387 - added ability to pipe formatting from stdin to stdin (#25)
1388
1389 - restored ability to format code with legacy usage of `async` as a name (#20, #42)
1390
1391 - even better handling of numpy-style array indexing (#33, again)
1392
1393 ### 18.3a2
1394
1395 - changed positioning of binary operators to occur at beginning of lines instead of at
1396   the end, following
1397   [a recent change to PEP 8](https://github.com/python/peps/commit/c59c4376ad233a62ca4b3a6060c81368bd21e85b)
1398   (#21)
1399
1400 - ignore empty bracket pairs while splitting. This avoids very weirdly looking
1401   formattings (#34, #35)
1402
1403 - remove a trailing comma if there is a single argument to a call
1404
1405 - if top level functions were separated by a comment, don't put four empty lines after
1406   the upper function
1407
1408 - fixed unstable formatting of newlines with imports
1409
1410 - fixed unintentional folding of post scriptum standalone comments into last statement
1411   if it was a simple statement (#18, #28)
1412
1413 - fixed missing space in numpy-style array indexing (#33)
1414
1415 - fixed spurious space after star-based unary expressions (#31)
1416
1417 ### 18.3a1
1418
1419 - added `--check`
1420
1421 - only put trailing commas in function signatures and calls if it's safe to do so. If
1422   the file is Python 3.6+ it's always safe, otherwise only safe if there are no `*args`
1423   or `**kwargs` used in the signature or call. (#8)
1424
1425 - fixed invalid spacing of dots in relative imports (#6, #13)
1426
1427 - fixed invalid splitting after comma on unpacked variables in for-loops (#23)
1428
1429 - fixed spurious space in parenthesized set expressions (#7)
1430
1431 - fixed spurious space after opening parentheses and in default arguments (#14, #17)
1432
1433 - fixed spurious space after unary operators when the operand was a complex expression
1434   (#15)
1435
1436 ### 18.3a0
1437
1438 - first published version, Happy 🍰 Day 2018!
1439
1440 - alpha quality
1441
1442 - date-versioned (see: https://calver.org/)
1443
1444 ## Authors
1445
1446 Glued together by [Łukasz Langa](mailto:lukasz@langa.pl).
1447
1448 Maintained with [Carol Willing](mailto:carolcode@willingconsulting.com),
1449 [Carl Meyer](mailto:carl@oddbird.net),
1450 [Jelle Zijlstra](mailto:jelle.zijlstra@gmail.com),
1451 [Mika Naylor](mailto:mail@autophagy.io), and
1452 [Zsolt Dollenstein](mailto:zsol.zsol@gmail.com).
1453
1454 Multiple contributions by:
1455
1456 - [Abdur-Rahmaan Janhangeer](mailto:cryptolabour@gmail.com)
1457 - [Adam Johnson](mailto:me@adamj.eu)
1458 - [Alexander Huynh](mailto:github@grande.coffee)
1459 - [Andrew Thorp](mailto:andrew.thorp.dev@gmail.com)
1460 - [Andrey](mailto:dyuuus@yandex.ru)
1461 - [Andy Freeland](mailto:andy@andyfreeland.net)
1462 - [Anthony Sottile](mailto:asottile@umich.edu)
1463 - [Arjaan Buijk](mailto:arjaan.buijk@gmail.com)
1464 - [Artem Malyshev](mailto:proofit404@gmail.com)
1465 - [Asger Hautop Drewsen](mailto:asgerdrewsen@gmail.com)
1466 - [Augie Fackler](mailto:raf@durin42.com)
1467 - [Aviskar KC](mailto:aviskarkc10@gmail.com)
1468 - [Benjamin Woodruff](mailto:github@benjam.info)
1469 - [Brandt Bucher](mailto:brandtbucher@gmail.com)
1470 - Charles Reid
1471 - [Christian Heimes](mailto:christian@python.org)
1472 - [Chuck Wooters](mailto:chuck.wooters@microsoft.com)
1473 - [Daniel Hahler](mailto:github@thequod.de)
1474 - [Daniel M. Capella](mailto:polycitizen@gmail.com)
1475 - Daniele Esposti
1476 - dylanjblack
1477 - [Eli Treuherz](mailto:eli@treuherz.com)
1478 - [Florent Thiery](mailto:fthiery@gmail.com)
1479 - hauntsaninja
1480 - Hugo van Kemenade
1481 - [Ivan Katanić](mailto:ivan.katanic@gmail.com)
1482 - [Jason Fried](mailto:me@jasonfried.info)
1483 - [jgirardet](mailto:ijkl@netc.fr)
1484 - [Joe Antonakakis](mailto:jma353@cornell.edu)
1485 - [Jon Dufresne](mailto:jon.dufresne@gmail.com)
1486 - [Jonas Obrist](mailto:ojiidotch@gmail.com)
1487 - [Josh Bode](mailto:joshbode@fastmail.com)
1488 - [Juan Luis Cano Rodríguez](mailto:hello@juanlu.space)
1489 - [Katie McLaughlin](mailto:katie@glasnt.com)
1490 - Lawrence Chan
1491 - [Linus Groh](mailto:mail@linusgroh.de)
1492 - [Luka Sterbic](mailto:luka.sterbic@gmail.com)
1493 - Mariatta
1494 - [Matt VanEseltine](mailto:vaneseltine@gmail.com)
1495 - [Michael Flaxman](mailto:michael.flaxman@gmail.com)
1496 - [Michael J. Sullivan](mailto:sully@msully.net)
1497 - [Michael McClimon](mailto:michael@mcclimon.org)
1498 - [Miguel Gaiowski](mailto:miggaiowski@gmail.com)
1499 - [Mike](mailto:roshi@fedoraproject.org)
1500 - [Min ho Kim](mailto:minho42@gmail.com)
1501 - [Miroslav Shubernetskiy](mailto:miroslav@miki725.com)
1502 - [Neraste](mailto:neraste.herr10@gmail.com)
1503 - [Ofek Lev](mailto:ofekmeister@gmail.com)
1504 - [Osaetin Daniel](mailto:osaetindaniel@gmail.com)
1505 - [Pablo Galindo](mailto:Pablogsal@gmail.com)
1506 - [Peter Bengtsson](mailto:mail@peterbe.com)
1507 - pmacosta
1508 - [Rishikesh Jha](mailto:rishijha424@gmail.com)
1509 - [Stavros Korokithakis](mailto:hi@stavros.io)
1510 - [Stephen Rosen](mailto:sirosen@globus.org)
1511 - [Sunil Kapil](mailto:snlkapil@gmail.com)
1512 - [Thom Lu](mailto:thomas.c.lu@gmail.com)
1513 - [Tom Christie](mailto:tom@tomchristie.com)
1514 - [Tzu-ping Chung](mailto:uranusjr@gmail.com)
1515 - [Utsav Shah](mailto:ukshah2@illinois.edu)
1516 - vezeli
1517 - [Vishwas B Sharma](mailto:sharma.vishwas88@gmail.com)
1518 - [Yngve Høiseth](mailto:yngve@hoiseth.net)
1519 - [Yurii Karabas](mailto:1998uriyyo@gmail.com)