The uncompromising Python code formatter

Overview

Black Logo

The Uncompromising Code Formatter

Build Status Actions Status Actions Status Documentation Status Coverage Status License: MIT PyPI Downloads conda-forge Code style: black

“Any color you like.”

Black is the uncompromising Python code formatter. By using it, you agree to cede control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting. You will save time and mental energy for more important matters.

Blackened code looks the same regardless of the project you're reading. Formatting becomes transparent after a while and you can focus on the content instead.

Black makes code review faster by producing the smallest diffs possible.

Try it out now using the Black Playground. Watch the PyCon 2019 talk to learn more.


Contents: Installation and usage | Code style | Pragmatism | pyproject.toml | Editor integration | blackd | black-primer | Version control integration | GitHub Actions | Ignoring unmodified files | Used by | Testimonials | Show your style | Contributing | Change log | Authors


Installation and usage

Installation

Black can be installed by running pip install black. It requires Python 3.6.2+ to run but you can reformat Python 2 code with it, too.

Install from GitHub

If you can't wait for the latest hotness and want to install from GitHub, use:

pip install git+git://github.com/psf/black

Usage

To get started right away with sensible defaults:

black {source_file_or_directory}

You can run Black as a package if running it as a script doesn't work:

python -m black {source_file_or_directory}

Command line options

Black doesn't provide many options. You can list them by running black --help:

Usage: black [OPTIONS] [SRC]...

  The uncompromising code formatter.

Options:
  -c, --code TEXT                 Format the code passed in as a string.
  -l, --line-length INTEGER       How many characters per line to allow.
                                  [default: 88]

  -t, --target-version [py27|py33|py34|py35|py36|py37|py38|py39]
                                  Python versions that should be supported by
                                  Black's output. [default: per-file auto-
                                  detection]

  --pyi                           Format all input files like typing stubs
                                  regardless of file extension (useful when
                                  piping source on standard input).

  -S, --skip-string-normalization
                                  Don't normalize string quotes or prefixes.
  -C, --skip-magic-trailing-comma
                                  Don't use trailing commas as a reason to
                                  split lines.

  --check                         Don't write the files back, just return the
                                  status.  Return code 0 means nothing would
                                  change.  Return code 1 means some files
                                  would be reformatted. Return code 123 means
                                  there was an internal error.

  --diff                          Don't write the files back, just output a
                                  diff for each file on stdout.

  --color / --no-color            Show colored diff. Only applies when
                                  `--diff` is given.

  --fast / --safe                 If --fast given, skip temporary sanity
                                  checks. [default: --safe]

  --include TEXT                  A regular expression that matches files and
                                  directories that should be included on
                                  recursive searches.  An empty value means
                                  all files are included regardless of the
                                  name.  Use forward slashes for directories
                                  on all platforms (Windows, too).  Exclusions
                                  are calculated first, inclusions later.
                                  [default: \.pyi?$]

  --exclude TEXT                  A regular expression that matches files and
                                  directories that should be excluded on
                                  recursive searches.  An empty value means no
                                  paths are excluded. Use forward slashes for
                                  directories on all platforms (Windows, too).
                                  Exclusions are calculated first, inclusions
                                  later.  [default: /(\.direnv|\.eggs|\.git|\.
                                  hg|\.mypy_cache|\.nox|\.tox|\.venv|\.svn|_bu
                                  ild|buck-out|build|dist)/]

  --extend-exclude TEXT           Like --exclude, but adds additional files
                                  and directories on top of the excluded
                                  ones (useful if you simply want to add to
                                  the default).

  --force-exclude TEXT            Like --exclude, but files and directories
                                  matching this regex will be excluded even
                                  when they are passed explicitly as
                                  arguments.


  --stdin-filename TEXT           The name of the file when passing it through
                                  stdin. Useful to make sure Black will
                                  respect --force-exclude option on some
                                  editors that rely on using stdin.

  -q, --quiet                     Don't emit non-error messages to stderr.
                                  Errors are still emitted; silence those with
                                  2>/dev/null.

  -v, --verbose                   Also emit messages to stderr about files
                                  that were not changed or were ignored due to
                                  exclusion patterns.

  --version                       Show the version and exit.
  --config FILE                   Read configuration from FILE path.
  -h, --help                      Show this message and exit.

Black is a well-behaved Unix-style command-line tool:

  • it does nothing if no sources are passed to it;
  • it will read from standard input and write to standard output if - is used as the filename;
  • it only outputs messages to users on standard error;
  • exits with code 0 unless an internal error occurred (or --check was used).

Using Black with other tools

While Black enforces formatting that conforms to PEP 8, other tools may raise warnings about Black's changes or will overwrite Black's changes. A good example of this is isort. Since Black is barely configurable, these tools should be configured to neither warn about nor overwrite Black's changes.

Actual details on Black compatible configurations for various tools can be found in compatible_configs.

Migrating your code style without ruining git blame

A long-standing argument against moving to automated code formatters like Black is that the migration will clutter up the output of git blame. This was a valid argument, but since Git version 2.23, Git natively supports ignoring revisions in blame with the --ignore-rev option. You can also pass a file listing the revisions to ignore using the --ignore-revs-file option. The changes made by the revision will be ignored when assigning blame. Lines modified by an ignored revision will be blamed on the previous revision that modified those lines.

So when migrating your project's code style to Black, reformat everything and commit the changes (preferably in one massive commit). Then put the full 40 characters commit identifier(s) into a file.

# Migrate code style to Black
5b4ab991dede475d393e9d69ec388fd6bd949699

Afterwards, you can pass that file to git blame and see clean and meaningful blame information.

$ git blame important.py --ignore-revs-file .git-blame-ignore-revs
7a1ae265 (John Smith 2019-04-15 15:55:13 -0400 1) def very_important_function(text, file):
abdfd8b0 (Alice Doe  2019-09-23 11:39:32 -0400 2)     text = text.lstrip()
7a1ae265 (John Smith 2019-04-15 15:55:13 -0400 3)     with open(file, "r+") as f:
7a1ae265 (John Smith 2019-04-15 15:55:13 -0400 4)         f.write(formatted)

You can even configure git to automatically ignore revisions listed in a file on every call to git blame.

$ git config blame.ignoreRevsFile .git-blame-ignore-revs

The one caveat is that GitHub and GitLab do not yet support ignoring revisions using their native UI of blame. So blame information will be cluttered with a reformatting commit on those platforms. (If you'd like this feature, there's an open issue for GitLab and please let GitHub know!)

NOTE: This is a beta product

Black is already successfully used by many projects, small and big. It also sports a decent test suite. However, it is still very new. Things will probably be wonky for a while. This is made explicit by the "Beta" trove classifier, as well as by the "b" in the version number. What this means for you is that until the formatter becomes stable, you should expect some formatting to change in the future. That being said, no drastic stylistic changes are planned, mostly responses to bug reports.

Also, as a temporary safety measure, Black will check that the reformatted code still produces a valid AST that is equivalent to the original. This slows it down. If you're feeling confident, use --fast.

The Black code style

Black is a PEP 8 compliant opinionated formatter. Black reformats entire files in place. It is not configurable. It doesn't take previous formatting into account. Your main option of configuring Black is that it doesn't reformat blocks that start with # fmt: off and end with # fmt: on, or lines that ends with # fmt: skip. Pay attention that # fmt: on/off have to be on the same level of indentation. To learn more about Black's opinions, to go the_black_code_style.

Please refer to this document before submitting an issue. What seems like a bug might be intended behaviour.

Pragmatism

Early versions of Black used to be absolutist in some respects. They took after its initial author. This was fine at the time as it made the implementation simpler and there were not many users anyway. Not many edge cases were reported. As a mature tool, Black does make some exceptions to rules it otherwise holds. This section of the_black_code_style describes what those exceptions are and why this is the case.

Please refer to this document before submitting an issue just like with the document above. What seems like a bug might be intended behaviour.

pyproject.toml

Black is able to read project-specific default values for its command line options from a pyproject.toml file. This is especially useful for specifying custom --include and --exclude/--extend-exclude patterns for your project.

Pro-tip: If you're asking yourself "Do I need to configure anything?" the answer is "No". Black is all about sensible defaults.

What on Earth is a pyproject.toml file?

PEP 518 defines pyproject.toml as a configuration file to store build system requirements for Python projects. With the help of tools like Poetry or Flit it can fully replace the need for setup.py and setup.cfg files.

Where Black looks for the file

By default Black looks for pyproject.toml starting from the common base directory of all files and directories passed on the command line. If it's not there, it looks in parent directories. It stops looking when it finds the file, or a .git directory, or a .hg directory, or the root of the file system, whichever comes first.

If you're formatting standard input, Black will look for configuration starting from the current working directory.

You can also explicitly specify the path to a particular file that you want with --config. In this situation Black will not look for any other file.

If you're running with --verbose, you will see a blue message if a file was found and used.

Please note blackd will not use pyproject.toml configuration.

Configuration format

As the file extension suggests, pyproject.toml is a TOML file. It contains separate sections for different tools. Black is using the [tool.black] section. The option keys are the same as long names of options on the command line.

Note that you have to use single-quoted strings in TOML for regular expressions. It's the equivalent of r-strings in Python. Multiline strings are treated as verbose regular expressions by Black. Use [ ] to denote a significant space character.

Example pyproject.toml
[tool.black]
line-length = 88
target-version = ['py37']
include = '\.pyi?$'
extend-exclude = '''
# A regex preceded with ^/ will apply only to files and directories
# in the root of the project.
^/foo.py  # exclude a file named foo.py in the root of the project (in addition to the defaults)
'''

Lookup hierarchy

Command-line options have defaults that you can see in --help. A pyproject.toml can override those defaults. Finally, options provided by the user on the command line override both.

Black will only ever use one pyproject.toml file during an entire run. It doesn't look for multiple files, and doesn't compose configuration from different levels of the file hierarchy.

Editor integration

Black can be integrated into many editors with plugins. They let you run Black on your code with the ease of doing it in your editor. To get started using Black in your editor of choice, please see editor_integration.

Patches are welcome for editors without an editor integration or plugin! More information can be found in editor_integration.

blackd

blackd is a small HTTP server that exposes Black's functionality over a simple protocol. The main benefit of using it is to avoid paying the cost of starting up a new Black process every time you want to blacken a file. Please refer to blackd to get the ball rolling.

black-primer

black-primer is a tool built for CI (and humans) to have Black --check a number of (configured in primer.json) Git accessible projects in parallel. black_primer has more information regarding its usage and configuration.

(A PR adding Mercurial support will be accepted.)

Version control integration

Use pre-commit. Once you have it installed, add this to the .pre-commit-config.yaml in your repository:

repos:
  - repo: https://github.com/psf/black
    rev: 20.8b1 # Replace by any tag/version: https://github.com/psf/black/tags
    hooks:
      - id: black
        language_version: python3 # Should be a command that runs python3.6+

Then run pre-commit install and you're ready to go.

Avoid using args in the hook. Instead, store necessary configuration in pyproject.toml so that editors and command-line usage of Black all behave consistently for your project. See Black's own pyproject.toml for an example.

If you're already using Python 3.7, switch the language_version accordingly. Finally, stable is a branch that tracks the latest release on PyPI. If you'd rather run on master, this is also an option.

GitHub Actions

Create a file named .github/workflows/black.yml inside your repository with:

name: Lint

on: [push, pull_request]

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
      - uses: psf/black@stable
        with:
          args: ". --check"

Inputs

black_args

optional: Black input arguments. Defaults to . --check --diff.

Ignoring unmodified files

Black remembers files it has already formatted, unless the --diff flag is used or code is passed via standard input. This information is stored per-user. The exact location of the file depends on the Black version and the system on which Black is run. The file is non-portable. The standard location on common operating systems is:

  • Windows: C:\\Users\<username>\AppData\Local\black\black\Cache\<version>\cache.<line-length>.<file-mode>.pickle
  • macOS: /Users/<username>/Library/Caches/black/<version>/cache.<line-length>.<file-mode>.pickle
  • Linux: /home/<username>/.cache/black/<version>/cache.<line-length>.<file-mode>.pickle

file-mode is an int flag that determines whether the file was formatted as 3.6+ only, as .pyi, and whether string normalization was omitted.

To override the location of these files on macOS or Linux, set the environment variable XDG_CACHE_HOME to your preferred location. For example, if you want to put the cache in the directory you're running Black from, set XDG_CACHE_HOME=.cache. Black will then write the above files to .cache/black/<version>/.

Used by

The following notable open-source projects trust Black with enforcing a consistent code style: pytest, tox, Pyramid, Django Channels, Hypothesis, attrs, SQLAlchemy, Poetry, PyPA applications (Warehouse, Bandersnatch, Pipenv, virtualenv), pandas, Pillow, every Datadog Agent Integration, Home Assistant, Zulip.

The following organizations use Black: Facebook, Dropbox, Mozilla, Quora.

Are we missing anyone? Let us know.

Testimonials

Dusty Phillips, writer:

Black is opinionated so you don't have to be.

Hynek Schlawack, creator of attrs, core developer of Twisted and CPython:

An auto-formatter that doesn't suck is all I want for Xmas!

Carl Meyer, Django core developer:

At least the name is good.

Kenneth Reitz, creator of requests and pipenv:

This vastly improves the formatting of our code. Thanks a ton!

Show your style

Use the badge in your project's README.md:

[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

Using the badge in README.rst:

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
    :target: https://github.com/psf/black

Looks like this: Code style: black

License

MIT

Contributing to Black

In terms of inspiration, Black is about as configurable as gofmt. This is deliberate.

Bug reports and fixes are always welcome! However, before you suggest a new feature or configuration knob, ask yourself why you want it. If it enables better integration with some workflow, fixes an inconsistency, speeds things up, and so on - go for it! On the other hand, if your answer is "because I don't like a particular formatting" then you're not ready to embrace Black yet. Such changes are unlikely to get accepted. You can still try but prepare to be disappointed.

More details can be found in CONTRIBUTING.

Change log

The log's become rather long. It moved to its own file.

See CHANGES.

Authors

Glued together by Łukasz Langa.

Maintained with Carol Willing, Carl Meyer, Jelle Zijlstra, Mika Naylor, Zsolt Dollenstein, and Cooper Lees.

Multiple contributions by:

Comments
  • Non-prerelease black release

    Non-prerelease black release

    It looks like Black is stable enough at the moment to release it as stable to PyPI. There are plenty of tools and integrations already which rely on black package and the fact that it is still in prerelease state sometime causes inconveniences, i.e. using it with pipenv forces allow_prereleases flag to be set to true.

    C: packaging C: maintenance 
    opened by lig 113
  • [Feature Request] Optimize imports

    [Feature Request] Optimize imports

    Can we please have a feature, similar to PyCharm's "optimize imports" feature, which basically sorts and removes un-used import statements?

    P.S. Great work!, Black works like a charm for me.

    T: enhancement help wanted 
    opened by devxpy 92
  • "INTERNAL ERROR: Black produced different code on the second pass of the formatter"

    • Version: 20.8b0
    • OS and Python version: all

    This is a rare problem that we're currently investigating. The most common case of it has to do with a combination of magic trailing commas and optional parentheses. Long story short, there's this behavior:

    • Black now treats all pre-existing trailing magic commas found in bracket pairs as signal to explode that bracket pair (e.g. to format it "one element per line");
    • in other places Black inserts trailing commas itself after reformatting a long expression or statement;
    • then on another run, Black finds those trailing commas and treats them as pre-existing trailing commas that signal that the given bracket pair should be exploded.

    The expected behavior is that there should be no difference between the first formatting and the second formatting. In practice Black sometimes chooses for or against optional parentheses differently depending on whether the line should be exploded or not. This is what needs fixing.

    Workaround

    We're working on fixing this, until then, format the file twice with --fast, it will keep its formatting moving forward.

    Call To Action

    If you find a case of this, please attach the generated log here so we can investigate. We've already added three identifying examples of this as expected failures to https://github.com/psf/black/pull/1627/commits/25206d8cc6e98143f0b10bcbe9e8b41b8b543abe.

    Finally, if you're interested in debugging this yourself, look for should_explode in if statements in the Black codebase. Those are the decisions that lead to unstable formatting.

    T: bug C: unstable formatting F: parentheses F: trailing comma 
    opened by ambv 80
  • Single quotes option

    Single quotes option

    Hi! Although Black now prefers doubles, can we have an option to keep single quotes? Forcing double quotes would make this great project unusable for many users who picked the rule of using single quotes.

    Operating system: MacOS Python version: 3.6 Black version: 18.4a0 Does also happen on master: yes

    T: design 
    opened by bofm 72
  • Black should have an opinion about doc strings

    Black should have an opinion about doc strings

    Operating system: Ubuntu 16.04 Python version: 3.6.1 Black version: master Does also happen on master: yes

    Hi,

    currently Black doesn't seem to have an opinion about doc strings or rather where the quotes should go.

    Black claims for this file for example that it is already formatted:

    def test():
        """This is one possibility.
    
        Very important stuff here.
        """
    
    
    def test2():
        """This is another one possibility.
    
        Very important stuff here."""
    
    
    def test3():
        """
        This is another one possibility.
    
        Very important stuff here.
        """
    
    
    def test4():
        """
        What about this?
        """
    
    
    def test5():
        """What about this?
    
        Some people also like to have an empty line at the end of the doc string.
    
        """
    

    The tool pydocstyle (in the spirit of PEP-0257) at least complains that the closing quotes should go on a separate line and if the docstring fits one line it should only span one line.

    It would be nice if that could be incorporated in Black as well.

    Thanks for the great work!

    Lukas.

    T: enhancement T: design 
    opened by Lukas0907 69
  • tweak collection literals to explode with trailing comma

    tweak collection literals to explode with trailing comma

    This is a change I discussed with @ambv at PyCon - the commit sequence should make things clear. I didn't go to the effort of fixing up existing tests (they'll fail a lot right now), but I can if this looks like a valid approach. This is somewhere between "proof of concept" and something I'd feel happy about, but I wanted feedback on how I'm tackling this early in development since I'm very much noideadog on this code.

    opened by durin42 65
  • Finish

    Finish "magic trailing comma" handling

    #826 introduced the concept of a magic trailing comma: if you, the programmer, explicitly put a trailing comma in a collection, it signals to Black that you want a given collection exploded into multiple lines, always. While this flies a bit in the way of "doesn't look at pre-existing formatting" and "non-configurability", it is extremely pragmatic and consistent with "make diffs as small as possible".

    However, there's issues with it so far. It doesn't yet work on nested collections. Worse yet, in those cases it leaves trailing commas behind when a collection ends up compressed into one line. We need to fix those edge cases to make it generally dependable.

    T: bug 
    opened by ambv 54
  • Black violates pep8 recommendation with long argument list

    Black violates pep8 recommendation with long argument list

    Currently, black reformats long routine names as follow

    # in:
    
    def very_important_function(template: str, *variables, file: os.PathLike, engine: str, header: bool = True, debug: bool = False):
        """Applies `variables` to the `template` and writes to `file`."""
        with open(file, 'w') as f:
            ...
    
    # out:
    
    def very_important_function(
        template: str,
        *variables,
        file: os.PathLike,
        engine: str,
        header: bool = True,
        debug: bool = False,
    ):
        """Applies `variables` to the `template` and writes to `file`."""
        with open(file, "w") as f:
    

    Desired style

    The current style done by black violates pep8 recommendation

    # Add 4 spaces (an extra level of indentation) to distinguish arguments from the rest.
    def long_function_name(
            var_one, var_two, var_three,
            var_four):
        print(var_one)
    

    The logic and motivation behind pep8 formatting, and against black, is that one wants to keep the indentation of the function definition continuation at a different level compared to the logic block. Otherwise, it's harder to differentiate what's one and what's the other, despite the indented frowny face.

    In fact, flake8 reports a pep8 violation for a case such as this

        if path.suffix in (
            '.js', '.json'
            ):
            proto = Protocol.json
    
    x.py:20:5: E125 continuation line with same indent as next logical line
    

    Black current formatting would be equivalent to this

        if path.suffix in (
            '.js', '.json'
        ):
            proto = Protocol.json
    

    Which we can probably all agree is a bad idea.

    Additional context from python-ideas mailing list

    T: design 
    opened by stefanoborini 54
  • Black does not honor exclude regex when files explicitly listed on the command line

    Black does not honor exclude regex when files explicitly listed on the command line

    Operating system: OSX Python version: 3.6.2 Black version: black, version 18.6b4

    The problem: certain directories in our repo contain generated python code that we don't want black to change. We've configure our repo to run black via pre-commit. Pre-commit invokes black with a list of changed files on the command line, and black's exclude regex does not work against those files and paths.

    i.e.

    black --exclude "/migrations/" content/migrations/0049_publicationstore_is_test.py
    reformatted content/migrations/0049_publicationstore_is_test.py
    All done! ✨ 🍰 ✨
    1 file reformatted.
    

    This makes us sad, since we've carefully put exclusion regexes into our pyproject.toml and black doesn't honor them when pre-commit calls it. Instead, we're having to workaround by configuring pre-commit to skip that path:

    repos:
    -   repo: https://github.com/ambv/black
        rev: stable
        hooks:
        - id: black
          language_version: python3.6
          exclude: migrations
    

    The behavior we'd like to see is that black's exclude regex would apply even when full file paths are listed on the commandline. I'd be happy to try for a PR if this seems like desirable behavior to anyone else...

    opened by adamehirsch 48
  • Fluent interfaces

    Fluent interfaces

    Operating system: Mac OS Python version: 3.6.4 Black version: 18.3a3 Does also happen on master: yes


    Black removes trailing backlashes, which can be used, for instance with yapf, to signal "don't join these line".

    This is problematic, for instance, if one uses the "fluent interface" idiom, which can lead to long chains of attribute accesses in a given expression.

    Here's an example:

    -        return sa.sql \
    -            .select([sa.sql.func.count(membership.c.user_id)]) \
    -            .where(membership.c.group_id == cls.id) \
    -            .group_by(membership.c.group_id) \
    -            .label('members_count')
    +        return sa.sql.select([sa.sql.func.count(membership.c.user_id)]).where(
    +            membership.c.group_id == cls.id
    +        ).group_by(
    +            membership.c.group_id
    +        ).label(
    +            'members_count'
    +        )
    

    The easiest solution would be to keep the line break in the presence of a backslash.

    T: enhancement help wanted 
    opened by sfermigier 43
  • Offer option other than pyproject.toml for config

    Offer option other than pyproject.toml for config

    https://github.com/pypa/pip/issues/6163 https://github.com/pypa/setuptools/issues/1642

    It seems that pyproject.toml is a trigger for enabling PEP 517 isolated builds. This seems a not good thing to tie to configuration of black. It broke pyinstaller and others with the pip-19.0 release.

    T: enhancement 
    opened by altendky 41
  • Bump sphinx from 5.3.0 to 6.0.0 in /docs

    Bump sphinx from 5.3.0 to 6.0.0 in /docs

    Bumps sphinx from 5.3.0 to 6.0.0.

    Release notes

    Sourced from sphinx's releases.

    v6.0.0

    Changelog: https://www.sphinx-doc.org/en/master/changes.html

    v6.0.0b2

    Changelog: https://www.sphinx-doc.org/en/master/changes.html

    v6.0.0b1

    Changelog: https://www.sphinx-doc.org/en/master/changes.html

    Changelog

    Sourced from sphinx's changelog.

    Release 6.0.0 (released Dec 29, 2022)

    Dependencies

    • #10468: Drop Python 3.6 support
    • #10470: Drop Python 3.7, Docutils 0.14, Docutils 0.15, Docutils 0.16, and Docutils 0.17 support. Patch by Adam Turner

    Incompatible changes

    • #7405: Removed the jQuery and underscore.js JavaScript frameworks.

      These frameworks are no longer be automatically injected into themes from Sphinx 6.0. If you develop a theme or extension that uses the jQuery, $, or $u global objects, you need to update your JavaScript to modern standards, or use the mitigation below.

      The first option is to use the sphinxcontrib.jquery_ extension, which has been developed by the Sphinx team and contributors. To use this, add sphinxcontrib.jquery to the extensions list in conf.py, or call app.setup_extension("sphinxcontrib.jquery") if you develop a Sphinx theme or extension.

      The second option is to manually ensure that the frameworks are present. To re-add jQuery and underscore.js, you will need to copy jquery.js and underscore.js from the Sphinx repository_ to your static directory, and add the following to your layout.html:

      .. code-block:: html+jinja

      {%- block scripts %} {{ super() }} {%- endblock %}

      .. _sphinxcontrib.jquery: https://github.com/sphinx-contrib/jquery/

      Patch by Adam Turner.

    • #10471, #10565: Removed deprecated APIs scheduled for removal in Sphinx 6.0. See :ref:dev-deprecated-apis for details. Patch by Adam Turner.

    • #10901: C Domain: Remove support for parsing pre-v3 style type directives and roles. Also remove associated configuration variables c_allow_pre_v3 and c_warn_on_allowed_pre_v3. Patch by Adam Turner.

    Features added

    ... (truncated)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    T: documentation C: dependencies skip news 
    opened by dependabot[bot] 1
  • Preview style: Crash on walrus in with statement

    Preview style: Crash on walrus in with statement

    This crashes in 23.1a1:

    async def f():
        with (x := await sleep(0)):
            pass
    

    Reported by @Zac-HD in https://github.com/psf/black/issues/3407#issuecomment-1364681511.

    T: bug F: parentheses C: preview style 
    opened by JelleZijlstra 1
  • Extra parentheses added even when string isn't split

    Extra parentheses added even when string isn't split

    Describe the bug With preview style, a long f-string where the only spaces are in the expression bit has parentheses added even though it isn't split over lines. For example:

    f(
        f'longstringwithnospacesinthestringbitbutwithspacesintheformattyfstringbithere{ 1 }',
    )
    

    becomes

    f(
        (
            f"longstringwithnospacesinthestringbitbutwithspacesintheformattyfstringbithere{ 1 }"
        ),
    )
    

    I would instead expect it not to have changed. See on black playground

    I noticed it also seems to occur with normal strings where the split is very near the start or end

    f(
        "l ongstringwithnospacesinthestringbitbutwithspacesintheformattyfstringbitherelollol",
    )
    

    becomes

    f(
        (
            "l ongstringwithnospacesinthestringbitbutwithspacesintheformattyfstringbitherelollol"
        ),
    )
    

    See on black playground Version Black 23.1a1, with --preview

    T: bug F: parentheses F: strings C: preview style 
    opened by wookie184 2
  • Black is not honoring #fmt: skip

    Black is not honoring #fmt: skip

    Describe the bug

    With below configuration in pyproject.toml :

    [tool.black]
    
    # How many characters per line to allow.
    line-length = 120
    
    # When processing Jupyter Notebooks, add the given magic to the list of known 
    # python-magics (timeit, prun, capture, pypy, python3, python, time). 
    # Useful for formatting cells with custom python magics.
    # python-cell-magics = 
    
    # Require a specific version of Black to be running 
    # (useful for unifying results across many environments e.g. with a pyproject.toml file). 
    # It can be either a major version number or an exact version.
    # required-version = 
    
    # A regular expression that matches files and directories that should be 
    # included on recursive searches. An empty value means all files are included 
    # regardless of the name. Use forward slashes for directories on all platforms (Windows, too). 
    # Exclusions are calculated first, inclusions later.
    # include = "(\.pyi?|\.ipynb)$"
    
    # A regular expression that matches files and directories that should be 
    # excluded on recursive searches. An empty value means no paths are excluded. 
    # Use forward slashes for directories on all platforms (Windows, too). 
    # Exclusions are calculated first, inclusions later.
    # exclude = "/(\.direnv|\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|venv|\.svn|\.ipynb_checkpoints|_build|buck-out|build|dist|__pypackages__)/"
    
    # Like 'exclude', but adds additional files and directories on top of the excluded ones.
    # (Useful if you simply want to add to the default).
    # extend-exclude = 
    
    # Like 'exclude', but files and directories matching this regex will be excluded 
    # even when they are passed explicitly as arguments.
    # force-exclude = 
    
    # The name of the file when passing it through stdin. 
    # Useful to make sure Black will respect 'force-exclude' option on some editors that rely on using stdin.
    # stdin-filename = 
    
    # Number of parallel workers. 
    # Can be a number or a range.
    # workers = 
    

    and this command line :

    black --config "pyproject.toml" --target-version py39 --check --diff .
    

    the following line of code is flagged :

    ave_quantity = self.exec_math(math_iterable["mean"], "mean", [])  # execute the "mean" fxn on the dataset  # cspell: disable-line # fmt: skip
    
    --- properties/datasets/models.py    2022-11-30 00:01:16.590743 +0000
    +++ properties/datasets/models.py    2022-11-30 00:01:18.692767 +0000
    @@ -746,11 +746,13 @@
             calculate the mean value of all the dataset points
     
             return: numerical value of this function when all variables are zero
             rtype: float
             """
    -        ave_quantity = self.exec_math(math_iterable["mean"], "mean", [])  # execute the "mean" fxn on the dataset # fmt:skip
    +        ave_quantity = self.exec_math(
    +            math_iterable["mean"], "mean", []
    +        )  # execute the "mean" fxn on the dataset # fmt:skip
             return getattr(ave_quantity, "magnitude", 0.0)
     
         def serialize(self, flat=False):
             return {
                 "type": "dataset",
    would reformat properties/datasets/models.py
    
    Oh no! 💥 💔 💥
    1 file would be reformatted, 102 files would be left unchanged.
    

    Which contradicts

    Black reformats entire files in place. It doesn’t reformat lines that end with # fmt: skip or blocks that start with # fmt: off and end with # fmt: on.

    Expected behavior

    Black should honor the directive # fmt: skip and ignore the flagged line of code.

    Environment

    • Black's version: 22.12.0
    • OS and Python version: Ubuntu 22.04.1 LTS/Python 3.9.16

    Additional context

    With directive #fmt:skip as the solely comment in the end of the line, black honors the directive and ignores the line of code.

    Related to

    • #451
    • #2024
    T: bug F: fmtskip 
    opened by ricardo-dematos 0
  • Black crashes with a single `# fmt: off` before a dict's closing bracket

    Black crashes with a single `# fmt: off` before a dict's closing bracket

    Describe the bug

    To Reproduce

    For example, take this code:

    dependencies = {
        a: b,
        # fmt: off
    }
    

    And run it with these arguments:

    $ black t.py
    

    The resulting error is:

    error: cannot format /Users/yileiyang/Downloads/t.py: Unable to match a closing bracket to the following opening bracket:
    
    Oh no! 💥 💔 💥
    1 file would fail to reformat.
    

    Expected behavior

    This is not a valid use of # fmt: off, but Black shouldn't crash either.

    Environment

    • Black's version: this crash existed since v22.1.0 in the stable style

    Additional context

    T: bug C: crash F: fmtoff 
    opened by yilei 0
Releases(23.1a1)
  • 23.1a1(Dec 18, 2022)

    This release provides a preview of Black's 2023 stable style. Black's default formatting style includes the following changes:

    • Enforce empty lines before classes and functions with sticky leading comments (#3302) (22.12.0)
    • Reformat empty and whitespace-only files as either an empty file (if no newline is present) or as a single newline character (if a newline is present) (#3348) (22.12.0)
    • Implicitly concatenated strings used as function args are now wrapped inside parentheses (#3307) (22.12.0)
    • Correctly handle trailing commas that are inside a line's leading non-nested parens (#3370) (22.12.0)
    • --skip-string-normalization / -S now prevents docstring prefixes from being normalized as expected (#3168) (since 22.8.0)
    • When using --skip-magic-trailing-comma or -C, trailing commas are stripped from subscript expressions with more than 1 element (#3209) (22.8.0)
    • Implicitly concatenated strings inside a list, set, or tuple are now wrapped inside parentheses (#3162) (22.8.0)
    • Fix a string merging/split issue when a comment is present in the middle of implicitly concatenated strings on its own line (#3227) (22.8.0)
    • Docstring quotes are no longer moved if it would violate the line length limit (#3044, #3430) (22.6.0)
    • Parentheses around return annotations are now managed (#2990) (22.6.0)
    • Remove unnecessary parentheses around awaited objects (#2991) (22.6.0)
    • Remove unnecessary parentheses in with statements (#2926) (22.6.0)
    • Remove trailing newlines after code block open (#3035) (22.6.0)
    • Code cell separators #%% are now standardised to # %% (#2919) (22.3.0)
    • Remove unnecessary parentheses from except statements (#2939) (22.3.0)
    • Remove unnecessary parentheses from tuple unpacking in for loops (#2945) (22.3.0)
    • Avoid magic-trailing-comma in single-element subscripts (#2942) (22.3.0)

    Please try it out and give feedback here: https://github.com/psf/black/issues/3407

    A stable 23.1.0 release will follow in January 2023.

    Source code(tar.gz)
    Source code(zip)
    black_linux(20.16 MB)
    black_macos(8.78 MB)
    black_windows.exe(8.92 MB)
  • 22.12.0(Dec 9, 2022)

    Preview style

    • Enforce empty lines before classes and functions with sticky leading comments (#3302)
    • Reformat empty and whitespace-only files as either an empty file (if no newline is present) or as a single newline character (if a newline is present) (#3348)
    • Implicitly concatenated strings used as function args are now wrapped inside parentheses (#3307)
    • Correctly handle trailing commas that are inside a line's leading non-nested parens (#3370)

    Configuration

    • Fix incorrectly applied .gitignore rules by considering the .gitignore location and the relative path to the target file (#3338)
    • Fix incorrectly ignoring .gitignore presence when more than one source directory is specified (#3336)

    Parser

    • Parsing support has been added for walruses inside generator expression that are passed as function args (for example, any(match := my_re.match(text) for text in texts)) (#3327).

    Integrations

    • Vim plugin: Optionally allow using the system installation of Black via let g:black_use_virtualenv = 0(#3309)
    Source code(tar.gz)
    Source code(zip)
    black_linux(20.16 MB)
    black_macos(8.78 MB)
    black_windows.exe(8.92 MB)
  • 22.10.0(Oct 6, 2022)

    22.10.0

    Highlights

    • Runtime support for Python 3.6 has been removed. Formatting 3.6 code will still be supported until further notice.

    Stable style

    • Fix a crash when # fmt: on is used on a different block level than # fmt: off (#3281)

    Preview style

    • Fix a crash when formatting some dicts with parenthesis-wrapped long string keys (#3262)

    Configuration

    • .ipynb_checkpoints directories are now excluded by default (#3293)
    • Add --skip-source-first-line / -x option to ignore the first line of source code while formatting (#3299)

    Packaging

    • Executables made with PyInstaller will no longer crash when formatting several files at once on macOS. Native x86-64 executables for macOS are available once again. (#3275)
    • Hatchling is now used as the build backend. This will not have any effect for users who install Black with its wheels from PyPI. (#3233)
    • Faster compiled wheels are now available for CPython 3.11 (#3276)

    Blackd

    • Windows style (CRLF) newlines will be preserved (#3257).

    Integrations

    • Vim plugin: add flag (g:black_preview) to enable/disable the preview style (#3246)
    • Update GitHub Action to support formatting of Jupyter Notebook files via a jupyter option (#3282)
    • Update GitHub Action to support use of version specifiers (e.g. <23) for Black version (#3265)
    Source code(tar.gz)
    Source code(zip)
    black_linux(16.43 MB)
    black_macos(6.93 MB)
    black_windows.exe(7.50 MB)
  • 22.8.0(Aug 31, 2022)

    Highlights

    • Python 3.11 is now supported, except for blackd as aiohttp does not support 3.11 as of publishing (#3234)
    • This is the last release that supports running Black on Python 3.6 (formatting 3.6 code will continue to be supported until further notice)
    • Reword the stability policy to say that we may, in rare cases, make changes that affect code that was not previously formatted by Black (#3155)

    Stable style

    • Fix an infinite loop when using # fmt: on/off in the middle of an expression or code block (#3158)
    • Fix incorrect handling of # fmt: skip on colon (:) lines (#3148)
    • Comments are no longer deleted when a line had spaces removed around power operators (#2874)

    Preview style

    • Single-character closing docstring quotes are no longer moved to their own line as this is invalid. This was a bug introduced in version 22.6.0. (#3166)
    • --skip-string-normalization / -S now prevents docstring prefixes from being normalized as expected (#3168)
    • When using --skip-magic-trailing-comma or -C, trailing commas are stripped from subscript expressions with more than 1 element (#3209)
    • Implicitly concatenated strings inside a list, set, or tuple are now wrapped inside parentheses (#3162)
    • Fix a string merging/split issue when a comment is present in the middle of implicitly concatenated strings on its own line (#3227)

    Blackd

    • blackd now supports enabling the preview style via the X-Preview header (#3217)

    Configuration

    • Black now uses the presence of debug f-strings to detect target version (#3215)
    • Fix misdetection of project root and verbose logging of sources in cases involving --stdin-filename (#3216)
    • Immediate .gitignore files in source directories given on the command line are now also respected, previously only .gitignore files in the project root and automatically discovered directories were respected (#3237)

    Documentation

    • Recommend using BlackConnect in IntelliJ IDEs (#3150)

    Integrations

    • Vim plugin: prefix messages with Black: so it's clear they come from Black (#3194)
    • Docker: changed to a /opt/venv installation + added to PATH to be available to non-root users (#3202)

    Output

    • Change from deprecated asyncio.get_event_loop() to create our event loop which removes DeprecationWarning (#3164)
    • Remove logging from internal blib2to3 library since it regularly emits error logs about failed caching that can and should be ignored (#3193)

    Parser

    • Type comments are now included in the AST equivalence check consistently so accidental deletion raises an error. Though type comments can't be tracked when running on PyPy 3.7 due to standard library limitations. (#2874)

    Performance

    • Reduce Black's startup time when formatting a single file by 15-30% (#3211)

    Full Changelog: https://github.com/psf/black/compare/22.6.0...22.8.0


    Thank you!

    • @hauntsaninja for modernizing our type annotations and fixing a few bugs too
    • @yilei for fixing our # fmt: off/on/skip code and continuing to improve the preview style, notably the (still) experimental string processing
    • The many community contributions to the non-core parts of the project:
      • @tobast for improving the QOL of the Vim plugin by simply appending Black: to most emitted messages
      • @Mogost for adding preview style support to blackd (finally :tada:)
      • @n-borges for improving the Docker image
      • @ionite34 for removing a hack in the official Black GitHub Action's start up code
    • @cooperlees for adding support for Python 3.11 and addressing DeprecationWarnings
    • @graingert for adding PyPy 3.8 to our CI matrix so we know Black works in even more places
    • @martinResearch for contributing a simple fix for such a silly and stupid .gitignore bug that we should've caught many moons ago
    • @fabioz for contributing the original patch that reduced the start up overhead when formatting a single file by 15-30% (!)

    ... and everyone else who contributed documentation, tests, or other improvements to the Black project!

    Finally congratulations to the first time contributors this time around!

    • @dmerejkowsky made their first contribution in https://github.com/psf/black/pull/3142
    • @m-aciek made their first contribution in https://github.com/psf/black/pull/3150
    • @Panther-12 made their first contribution in https://github.com/psf/black/pull/3167
    • @onescriptkid made their first contribution in https://github.com/psf/black/pull/3170
    • @tobast made their first contribution in https://github.com/psf/black/pull/3194
    • @n-borges made their first contribution in https://github.com/psf/black/pull/3202
    • @Mogost made their first contribution in https://github.com/psf/black/pull/3217
    • @ionite34 made their first contribution in https://github.com/psf/black/pull/3226
    • @martinResearch made their first contribution in https://github.com/psf/black/pull/3237
    Source code(tar.gz)
    Source code(zip)
    black_linux(16.43 MB)
    black_windows.exe(7.50 MB)
  • 22.6.0(Jun 28, 2022)

    Style

    • Fix unstable formatting involving #fmt: skip and # fmt:skip comments (notice the lack of spaces) (#2970)

    Preview style

    • Docstring quotes are no longer moved if it would violate the line length limit (#3044)
    • Parentheses around return annotations are now managed (#2990)
    • Remove unnecessary parentheses around awaited objects (#2991)
    • Remove unnecessary parentheses in with statements (#2926)
    • Remove trailing newlines after code block open (#3035)

    Integrations

    • Add scripts/migrate-black.py script to ease introduction of Black to a Git project (#3038)

    Output

    • Output Python version and implementation as part of --version flag (#2997)

    Packaging

    • Use tomli instead of tomllib on Python 3.11 builds where tomllib is not available (#2987)

    Parser

    • PEP 654 syntax (for example, except *ExceptionGroup:) is now supported (#3016)
    • PEP 646 syntax (for example, Array[Batch, *Shape] or def fn(*args: *T) -> None) is now supported (#3071)

    Vim Plugin

    • Fix strtobool function. It didn't parse true/on/false/off. (#3025)

    Full Changelog: https://github.com/psf/black/compare/22.3.0...22.6.0


    Thank you!

    • @jpy-git for improving our parentheses formatting significantly
    • @siuryan for fixing a fmt: skip bug, making it a little less annoying to use :)
    • @isidentical for implementing support for PEP 654 and 646 syntax
    • @defntvdm for fixing our vim plugin, especially as we (the maintainers) don't really know vim script sadly
    • @idorrington92 for fixing the docstring bug where Black would move the closing quotes causing it to violate the line length limit (whoops!)
    • @hbrunn for contributing the migrate-black script
    • @saroad2 for improving newline handling after code blocks and test infrastructure improvements

    ... and everyone else who contributed documentation, tests, or other improvements to the Black project!

    Finally congrats to first contributors!

    • @kolibril13 made their first contribution in https://github.com/psf/black/pull/2982
    • @siuryan made their first contribution in https://github.com/psf/black/pull/2970
    • @dignissimus made their first contribution in https://github.com/psf/black/pull/3007
    • @JiriKr made their first contribution in https://github.com/psf/black/pull/3023
    • @defntvdm made their first contribution in https://github.com/psf/black/pull/3025
    • @naveensrinivasan made their first contribution in https://github.com/psf/black/pull/3043
    • @idorrington92 made their first contribution in https://github.com/psf/black/pull/3044
    • @laundmo made their first contribution in https://github.com/psf/black/pull/3063
    • @ysk24ok made their first contribution in https://github.com/psf/black/pull/3070
    • @hbrunn made their first contribution in https://github.com/psf/black/pull/3038
    • @vivekvashist made their first contribution in https://github.com/psf/black/pull/3096
    • @nateprewitt made their first contribution in https://github.com/psf/black/pull/3125
    • @yilei made their first contribution in https://github.com/psf/black/pull/3135
    Source code(tar.gz)
    Source code(zip)
    black_linux(16.44 MB)
    black_macos(6.90 MB)
    black_windows.exe(7.47 MB)
  • 22.3.0(Mar 28, 2022)

    Preview style

    • Code cell separators #%% are now standardised to # %% (#2919)
    • Remove unnecessary parentheses from except statements (#2939)
    • Remove unnecessary parentheses from tuple unpacking in for loops (#2945)
    • Avoid magic-trailing-comma in single-element subscripts (#2942)

    Configuration

    • Do not format __pypackages__ directories by default (#2836)
    • Add support for specifying stable version with --required-version (#2832).
    • Avoid crashing when the user has no homedir (#2814)
    • Avoid crashing when md5 is not available (#2905)
    • Fix handling of directory junctions on Windows (#2904)

    Documentation

    • Update pylint config documentation (#2931)

    Integrations

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

    Output

    • In verbose, mode, log when Black is using user-level config (#2861)

    Packaging

    • Fix Black to work with Click 8.1.0 (#2966)
    • On Python 3.11 and newer, use the standard library's tomllib instead of tomli (#2903)
    • black-primer, the deprecated internal devtool, has been removed and copied to a separate repository (#2924)

    Parser

    • Black can now parse starred expressions in the target of for and async for statements, e.g for item in *items_1, *items_2: pass (#2879).
    Source code(tar.gz)
    Source code(zip)
    black_linux(17.03 MB)
    black_macos(7.26 MB)
    black_windows.exe(7.71 MB)
  • 22.1.0(Jan 29, 2022)

    At long last, Black is no longer a beta product! This is the first non-beta release and the first release covered by our new stability policy.

    Highlights

    • Remove Python 2 support (#2740)
    • Introduce the --preview flag (#2752)

    Style

    • Deprecate --experimental-string-processing and move the functionality under --preview (#2789)
    • For stubs, one blank line between class attributes and methods is now kept if there's at least one pre-existing blank line (#2736)
    • Black now normalizes string prefix order (#2297)
    • Remove spaces around power operators if both operands are simple (#2726)
    • Work around bug that causes unstable formatting in some cases in the presence of the magic trailing comma (#2807)
    • Use parentheses for attribute access on decimal float and int literals (#2799)
    • Don't add whitespace for attribute access on hexadecimal, binary, octal, and complex literals (#2799)
    • Treat blank lines in stubs the same inside top-level if statements (#2820)
    • Fix unstable formatting with semicolons and arithmetic expressions (#2817)
    • Fix unstable formatting around magic trailing comma (#2572)

    Parser

    • Fix mapping cases that contain as-expressions, like case {"key": 1 | 2 as password} (#2686)
    • Fix cases that contain multiple top-level as-expressions, like case 1 as a, 2 as b (#2716)
    • Fix call patterns that contain as-expressions with keyword arguments, like case Foo(bar=baz as quux) (#2749)
    • Tuple unpacking on return and yield constructs now implies 3.8+ (#2700)
    • Unparenthesized tuples on annotated assignments (e.g values: Tuple[int, ...] = 1, 2, 3) now implies 3.8+ (#2708)
    • Fix handling of standalone match() or case() when there is a trailing newline or a comment inside of the parentheses. (#2760)
    • from __future__ import annotations statement now implies Python 3.7+ (#2690)

    Performance

    • Speed-up the new backtracking parser about 4X in general (enabled when --target-version is set to 3.10 and higher). (#2728)
    • Black is now compiled with mypyc for an overall 2x speed-up. 64-bit Windows, MacOS, and Linux (not including musl) are supported. (#1009, #2431)

    Configuration

    • Do not accept bare carriage return line endings in pyproject.toml (#2408)
    • Add configuration option (python-cell-magics) to format cells with custom magics in Jupyter Notebooks (#2744)
    • Allow setting custom cache directory on all platforms with environment variable BLACK_CACHE_DIR (#2739).
    • Enable Python 3.10+ by default, without any extra need to specify --target-version=py310. (#2758)
    • Make passing SRC or --code mandatory and mutually exclusive (#2804)

    Output

    • Improve error message for invalid regular expression (#2678)
    • Improve error message when parsing fails during AST safety check by embedding the underlying SyntaxError (#2693)
    • No longer color diff headers white as it's unreadable in light themed terminals (#2691)
    • Text coloring added in the final statistics (#2712)
    • Verbose mode also now describes how a project root was discovered and which paths will be formatted. (#2526)

    Packaging

    • All upper version bounds on dependencies have been removed (#2718)
    • typing-extensions is no longer a required dependency in Python 3.10+ (#2772)
    • Set click lower bound to 8.0.0 as Black crashes on 7.1.2 (#2791)

    Integrations

    • Update GitHub action to support containerized runs (#2748)

    Documentation

    • Change protocol in pip installation instructions to https:// (#2761)
    • Change HTML theme to Furo primarily for its responsive design and mobile support (#2793)
    • Deprecate the black-primer tool (#2809)
    • Document Python support policy (#2819)

    Full Changelog: https://github.com/psf/black/compare/21.12b0...22.1.0


    Thank you!

    • @isidentical for their continued work on making our Python 3.10 support better than ever (we made them a co-maintainer :tada:)
    • @hauntsaninja for their help improving our stub style
    • @nipunn1313 making Black more stable (which has been a long running battle)
    • .. and all of my fellow co-maintainers who have made working on this project a wonderful ride @JelleZijlstra @cooperlees @felix-hilden @ambv @zsol

    And also congrats to first contributors!

    • @mwtoews made their first contribution in https://github.com/psf/black/pull/2701
    • @gunungpw made their first contribution in https://github.com/psf/black/pull/2733
    • @joshowen made their first contribution in https://github.com/psf/black/pull/2748
    • @Shivansh-007 made their first contribution in https://github.com/psf/black/pull/2526
    • @cbows made their first contribution in https://github.com/psf/black/pull/2761
    • @jlazar17 made their first contribution in https://github.com/psf/black/pull/2765
    • @VanSHOE made their first contribution in https://github.com/psf/black/pull/2712
    • @emfdavid made their first contribution in https://github.com/psf/black/pull/2786
    • @mgmarino made their first contribution in https://github.com/psf/black/pull/2744
    • @RHammond2 made their first contribution in https://github.com/psf/black/pull/2792
    • @percurnicus made their first contribution in https://github.com/psf/black/pull/2739
    • @sobolevn made their first contribution in https://github.com/psf/black/pull/2802
    Source code(tar.gz)
    Source code(zip)
    black_linux(17.03 MB)
    black_macos(7.23 MB)
    black_windows.exe(7.68 MB)
  • 21.12b0(Dec 5, 2021)

    Black

    • Fix determination of f-string expression spans (#2654)
    • Fix bad formatting of error messages about EOF in multi-line statements (#2343)
    • Functions and classes in blocks now have more consistent surrounding spacing (#2472)

    Jupyter Notebook support

    • Cell magics are now only processed if they are known Python cell magics. Earlier, all cell magics were tokenized, leading to possible indentation errors e.g. with %%writefile. (#2630)
    • Fix assignment to environment variables in Jupyter Notebooks (#2642)

    Python 3.10 support

    • Point users to using --target-version py310 if we detect 3.10-only syntax (#2668)
    • Fix match statements with open sequence subjects, like match a, b: or match a, *b: (#2639) (#2659)
    • Fix match/case statements that contain match/case soft keywords multiple times, like match re.match() (#2661)
    • Fix case statements with an inline body (#2665)
    • Fix styling of starred expressions inside match subject (#2667)
    • Fix parser error location on invalid syntax in a match statement (#2649)
    • Fix Python 3.10 support on platforms without ProcessPoolExecutor (#2631)
    • Improve parsing performance on code that uses match under --target-version py310 up to ~50% (#2670)

    Packaging

    • Remove dependency on regex (#2644) (#2663)

    Thank you!

    • @isidentical for the polishing up 3.10 syntax support (which they contributed in the first place!)
    • @MarcoGorelli for their ever-continuing work on Black's jupyter support
    • @jalaziz for cleaning up our Pyinstaller CD workflow
    • @hauntsaninja for helping us drop the regex dependency

    And also congrats to first contributors!

    • @MatthewScholefield made their first contribution in https://github.com/psf/black/pull/2631
    • @AshIsbitt made their first contribution in https://github.com/psf/black/pull/2632
    • @kalbasit made their first contribution in https://github.com/psf/black/pull/2638
    • @danieleades made their first contribution in https://github.com/psf/black/pull/2653
    • @danielsparing made their first contribution in https://github.com/psf/black/pull/2630
    • @tanvimoharir made their first contribution in https://github.com/psf/black/pull/2343
    Source code(tar.gz)
    Source code(zip)
    black_linux(16.92 MB)
    black_macos(7.19 MB)
    black_windows.exe(7.71 MB)
  • 21.11b1(Nov 18, 2021)

  • 21.11b0(Nov 17, 2021)

    Black

    • Warn about Python 2 deprecation in more cases by improving Python 2 only syntax detection (#2592)
    • Add experimental PyPy support (#2559)
    • Add partial support for the match statement. As it's experimental, it's only enabled when --target-version py310 is explicitly specified (#2586)
    • Add support for parenthesized with (#2586)
    • Declare support for Python 3.10 for running Black (#2562)

    Integrations

    • Fixed vim plugin with Python 3.10 by removing deprecated distutils import (#2610)
    • The vim plugin now parses skip_magic_trailing_comma from pyproject.toml (#2613)
    Source code(tar.gz)
    Source code(zip)
    black_linux(17.60 MB)
    black_macos(7.44 MB)
    black_windows.exe(7.93 MB)
  • 21.10b0(Nov 1, 2021)

    Black

    • Document stability policy, that will apply for non-beta releases (#2529)
    • Add new --workers parameter (#2514)
    • Fixed feature detection for positional-only arguments in lambdas (#2532)
    • Bumped typed-ast version minimum to 1.4.3 for 3.10 compatiblity (#2519)
    • Fixed a Python 3.10 compatibility issue where the loop argument was still being passed even though it has been removed (#2580)
    • Deprecate Python 2 formatting support (#2523)

    Blackd

    • Remove dependency on aiohttp-cors (#2500)
    • Bump required aiohttp version to 3.7.4 (#2509)

    Black-Primer

    • Add primer support for --projects (#2555)
    • Print primer summary after individual failures (#2570)

    Integrations

    • Allow to pass target_version in the vim plugin (#1319)
    • Install build tools in docker file and use multi-stage build to keep the image size down (#2582)
    Source code(tar.gz)
    Source code(zip)
    black_linux(17.61 MB)
    black_macos(7.43 MB)
    black_windows.exe(7.90 MB)
  • 21.9b0(Sep 14, 2021)

  • 21.8b0(Aug 29, 2021)

    Black

    • Add support for formatting Jupyter Notebook files (#2357)
    • Move from appdirs dependency to platformdirs (#2375)
    • Present a more user-friendly error if .gitignore is invalid (#2414)
    • The failsafe for accidentally added backslashes in f-string expressions has been hardened to handle more edge cases during quote normalization (#2437)
    • Avoid changing a function return type annotation's type to a tuple by adding a trailing comma (#2384)
    • Parsing support has been added for unparenthesized walruses in set literals, set comprehensions, and indices (#2447).
    • Pin setuptools-scm build-time dependency version (#2457)
    • Exclude typing-extensions version 3.10.0.1 due to it being broken on Python 3.10 (#2460)

    Blackd

    • Replace sys.exit(-1) with raise ImportError as it plays more nicely with tools that scan installed packages (#2440)

    Integrations

    • The provided pre-commit hooks no longer specify language_version to avoid overriding default_language_version (#2430)
    Source code(tar.gz)
    Source code(zip)
    black_linux(16.54 MB)
    black_macos(7.36 MB)
    black_windows.exe(7.89 MB)
  • 21.7b0(Jul 16, 2021)

    Black

    • Configuration files using TOML features higher than spec v0.5.0 are now supported (#2301)
    • Add primer support and test for code piped into black via STDIN (#2315)
    • Fix internal error when FORCE_OPTIONAL_PARENTHESES feature is enabled (#2332)
    • Accept empty stdin (#2346)
    • Provide a more useful error when parsing fails during AST safety checks (#2304)

    Docker

    • Add new latest_release tag automation to follow latest black release on docker images (#2374)

    Integrations

    • The vim plugin now searches upwards from the directory containing the current buffer instead of the current working directory for pyproject.toml. (#1871)
    • The vim plugin now reads the correct string normalization option in pyproject.toml (#1869)
    • The vim plugin no longer crashes Black when there's boolean values in pyproject.toml (#1869)
    Source code(tar.gz)
    Source code(zip)
    black_linux(16.35 MB)
    black_macos(7.30 MB)
    black_windows.exe(7.85 MB)
  • 21.6b0(Jun 10, 2021)

    Black

    • Fix failure caused by fmt: skip and indentation (#2281)
    • Account for += assignment when deciding whether to split string (#2312)
    • Correct max string length calculation when there are string operators (#2292)
    • Fixed option usage when using the --code flag (#2259)
    • Do not call uvloop.install() when Black is used as a library (#2303)
    • Added --required-version option to require a specific version to be running (#2300)
    • Fix incorrect custom breakpoint indices when string group contains fake f-strings (#2311)
    • Fix regression where R prefixes would be lowercased for docstrings (#2285)
    • Fix handling of named escapes (\N{...}) when --experimental-string-processing is used (#2319)
    Source code(tar.gz)
    Source code(zip)
    black_linux(16.47 MB)
    black_macos(7.12 MB)
    black_windows.exe(7.82 MB)
  • 21.5b2(May 31, 2021)

    Black

    • A space is no longer inserted into empty docstrings (#2249)
    • Fix handling of .gitignore files containing non-ASCII characters on Windows (#2229)
    • Respect .gitignore files in all levels, not only root/.gitignore file (apply .gitignore rules like git does) (#2225)
    • Restored compatibility with Click 8.0 on Python 3.6 when LANG=C used (#2227)
    • Add extra uvloop install + import support if in python env (#2258)
    • Fix --experimental-string-processing crash when matching parens are not found (#2283)
    • Make sure to split lines that start with a string operator (#2286)
    • Fix regular expression that black uses to identify f-expressions (#2287)

    Blackd

    • Add a lower bound for the aiohttp-cors dependency. Only 0.4.0 or higher is supported. (#2231)

    Packaging

    • Release self-contained x86_64 MacOS binaries as part of the GitHub release pipeline (#2198)
    • Always build binaries with the latest available Python (#2260)

    Documentation

    • Add discussion of magic comments to FAQ page (#2272)
    • --experimental-string-processing will be enabled by default in the future (#2273)
    • Fix typos discovered by codespell (#2228)
    • Fix Vim plugin installation instructions. (#2235)
    • Add new Frequently Asked Questions page (#2247)
    • Fix encoding + symlink issues preventing proper build on Windows (#2262)
    Source code(tar.gz)
    Source code(zip)
    black_linux(16.47 MB)
    black_macos(7.12 MB)
    black_windows.exe(7.82 MB)
  • 21.5b1(May 10, 2021)

  • 21.5b0(May 4, 2021)

  • 21.4b2(Apr 28, 2021)

  • 21.4b1(Apr 27, 2021)

    Black

    • Fix crash on docstrings ending with "\ ". (#2142)

    • Fix crash when atypical whitespace is cleaned out of dostrings (#2120)

    • Reflect the --skip-magic-trailing-comma and --experimental-string-processing flags in the name of the cache file. Without this fix, changes in these flags would not take effect if the cache had already been populated. (#2131)

    • Don't remove necessary parentheses from assignment expression containing assert / return statements. (#2143)

    Packaging

    • Bump pathspec to >= 0.8.1 to solve invalid .gitignore exclusion handling
    Source code(tar.gz)
    Source code(zip)
    black.elf(13.84 MB)
    black.exe(7.64 MB)
  • 21.4b0(Apr 25, 2021)

    Black

    • Fixed a rare but annoying formatting instability created by the combination of optional trailing commas inserted by Black and optional parentheses looking at pre-existing "magic" trailing commas. This fixes issue #1629 and all of its many many duplicates. (#2126)

    • Black now processes one-line docstrings by stripping leading and trailing spaces, and adding a padding space when needed to break up """". (#1740)

    • Black now cleans up leading non-breaking spaces in comments (#2092)

    • Black now respects --skip-string-normalization when normalizing multiline docstring quotes (#1637)

    • Black no longer removes all empty lines between non-function code and decorators when formatting typing stubs. Now Black enforces a single empty line. (#1646)

    • Black no longer adds an incorrect space after a parenthesized assignment expression in if/while statements (#1655)

    • Added --skip-magic-trailing-comma / -C to avoid using trailing commas as a reason to split lines (#1824)

    • fixed a crash when PWD=/ on POSIX (#1631)

    • fixed "I/O operation on closed file" when using --diff (#1664)

    • Prevent coloured diff output being interleaved with multiple files (#1673)

    • Added support for PEP 614 relaxed decorator syntax on python 3.9 (#1711)

    • Added parsing support for unparenthesized tuples and yield expressions in annotated assignments (#1835)

    • use lowercase hex strings (#1692)

    • added --extend-exclude argument (PR #2005)

    • speed up caching by avoiding pathlib (#1950)

    • --diff correctly indicates when a file doesn't end in a newline (#1662)

    • Added --stdin-filename argument to allow stdin to respect --force-exclude rules (#1780)

    • Lines ending with fmt: skip will now be not formatted (#1800)

    • PR #2053: Black no longer relies on typed-ast for Python 3.8 and higher

    • PR #2053: Python 2 support is now optional, install with python3 -m pip install black[python2] to maintain support.

    • Exclude venv directory by default (#1683)

    • Fixed "Black produced code that is not equivalent to the source" when formatting Python 2 docstrings (#2037)

    Packaging

    • Self-contained native Black binaries are now provided for releases via GitHub Releases (#1743)
    Source code(tar.gz)
    Source code(zip)
    black.elf(13.84 MB)
    black.exe(7.64 MB)
  • 20.8b1(Aug 26, 2020)

  • 20.8b0(Aug 26, 2020)

Owner
Python Software Foundation
Python Software Foundation
Komodo Edit is a fast and free multi-language code editor. Written in JS, Python, C++ and based on the Mozilla platform.

Komodo Edit This readme explains how to get started building, using and developing with the Komodo Edit source base. Whilst the main Komodo Edit sourc

ActiveState Komodo 2k Dec 28, 2022
A free Python source code editor and Notepad replacement for Windows

Website Download Features Toolbar Wide array of view options Syntax highlighting support for Python Usable accelerator keys for each function (Ctrl+N,

Mohamed Ahmed 7 Feb 16, 2022
A code-completion engine for Vim

YouCompleteMe: a code-completion engine for Vim NOTE: Minimum Requirements Have Changed Our policy is to support the Vim version that's in the latest

null 24.5k Dec 30, 2022
An experimental code editor for writing algorithms

Algojammer Algojammer is an experimental, proof-of-concept code editor for writing algorithms in Python. It was mainly written to assist with solving

Chris Knott 2.9k Dec 27, 2022
A small, simple editor for beginner Python programmers. Written in Python and Qt5.

Mu - A Simple Python Code Editor Mu is a simple code editor for beginner programmers based on extensive feedback from teachers and learners. Having sa

Mu 1.2k Jan 3, 2023
Python-Text-editor: a simple text editor on Python and Tkinter

Python-Text-editor This is a simple text editor on Python and Tkinter. The proje

Innokentie 1 Jan 3, 2022
Emacs Python Development Environment

Elpy, the Emacs Python IDE Elpy is an Emacs package to bring powerful Python editing to Emacs. It combines and configures a number of other packages,

Jorgen Schäfer 1.8k Jan 2, 2023
awesome Python autocompletion with SublimeText

SublimeJEDI SublimeJEDI is a Sublime Text 3 and Sublime Text 2 and plugin to the awesome autocomplete library Jedi Python Version Support Sublime Jedi

Serhii Ruskykh 933 Dec 8, 2022
Vim python-mode. PyLint, Rope, Pydoc, breakpoints from box.

Python-mode, a Python IDE for Vim This project needs contributors. Documentation: :help pymode https://github.com/python-mode/python-mode/wiki Importa

The Python-Mode 5.4k Jan 1, 2023
Python Tools for Visual Studio

Python tools for Visual Studio Python support for Visual Studio is developed and managed here. Visit our product overview and downloads page, read our

Microsoft 2.4k Dec 30, 2022
Official repository for Spyder - The Scientific Python Development Environment

Copyright © 2009–2021 Spyder Project Contributors Some source files and icons may be under other authorship/licenses; see NOTICE.txt. Project status B

Spyder IDE 7.3k Dec 31, 2022
Leo is an Outliner, Editor, IDE and PIM written in 100% Python.

Leo 6.3, http://leoeditor.com, is now available on GitHub. Leo is an IDE, outliner and PIM. The highlights of Leo 6.3 leoAst.py: The unification of Py

Leo Editor 1.4k Dec 27, 2022
Python IDE for beginners

Thonny Thonny is a Python IDE meant for learning programming. End users See https://thonny.org and wiki for more info. Contributors Contributions are

Thonny, Python IDE for beginners 2.1k Jan 2, 2023
A simple Notepad-like editor written in Python

monkepad A simple Notepad-like editor written in Python Since MonkePad is written in one file, all your customization can be done without much trouble

null 5 Dec 28, 2021
A very simple Editor.js parser written in pure Python

pyEditor.js A very simple Editor.js parser written in pure Python. Soon-to-be published on PyPI. Features: Automatically convert Editor.js's JSON outp

Kevo 7 Nov 1, 2022
A basic Python IDE made by Anh Đức

Python IDE by Anh Đức A basic Python IDE made with python module tkinter. Hope you enjoy this IDE! V 1.3 "Open Terminal from IDE" feature V 1.2 Now yo

null 1 May 30, 2022
The uncompromising Python code formatter

The Uncompromising Code Formatter “Any color you like.” Black is the uncompromising Python code formatter. By using it, you agree to cede control over

Python Software Foundation 30.7k Jan 2, 2023
The uncompromising Python code formatter

The Uncompromising Code Formatter “Any color you like.” Black is the uncompromising Python code formatter. By using it, you agree to cede control over

Python Software Foundation 30.7k Jan 3, 2023
Opinionated code formatter, just like Python's black code formatter but for Beancount

beancount-black Opinionated code formatter, just like Python's black code formatter but for Beancount Try it out online here Features MIT licensed - b

Launch Platform 16 Oct 11, 2022
A formatter for Python files

YAPF Introduction Most of the current formatters for Python --- e.g., autopep8, and pep8ify --- are made to remove lint errors from code. This has som

Google 13k Dec 31, 2022