dont skip formatting #%% by MarcoGorelli · Pull Request #2919 · psf/black (original) (raw)

They mostly cause unnecessary trouble.

Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com

Until we can properly look into and fix it. -> https://github.com/psf/black/issues/2734

Wing IDE 8 now supports autoformatting w/ Black natively 🎉

Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com

see: https://github.com/actions/runner/issues/716

*blib2to3's support was left untouched because: 1) I don't want to touch parsing machinery, and 2) it'll allow us to provide a more useful error message if someone does try to format Python 2 code.

Black would now echo the location that it determined as the root path for the project if --verbose is enabled by the user, according to which it chooses the SRC paths, i.e. the absolute path of the project is {root}/{src}.

Closes #1880

Resolves #2759

Unauthenticated git protocol was disabled recently by Github and should not be used anymore.

https://github.blog/2021-09-01-improving-git-protocol-security-github/#no-more-unauthenticated-git

Co-authored-by: Jeffrey Lazar jlazar@MacBook-Pro-2.local

They just made themselves ESP-compliant in https://github.com/python-poetry/poetry/commit/ecb030e1f0b7c13cc11971f00ee5012e82a892bc

Closes #2171

Hopefully this makes it much easier to gauge the impacts of future changes!

3.10 ships with TypeGuard which is the newest feature we need.

Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com

Bumps sphinx from 4.3.2 to 4.4.0.


updated-dependencies:

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Co-authored-by: Batuhan Taskaya isidentical@gmail.com Co-authored-by: Jelle Zijlstra jelle.zijlstra@gmail.com Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com

Fixes #2742.

This PR adds the ability to configure additional python cell magics. This will allow formatting cells in Jupyter Notebooks that are using custom (python) magics.

Closes #2774

Furo was chosen as it provides excellent mobile support, user controllable light/dark theming, and is overall easier to read

Fixes #2506

XDG_CACHE_HOME does not work on Windows. To allow for users to set a custom cache directory on all systems I added a new environment variable BLACK_CACHE_DIR to set the cache directory. The default remains the same so users will only notice a change if that environment variable is set.

The specific use case I have for this is I need to run black on in different processes at the same time. There is a race condition with the cache pickle file that made this rather difficult. A custom cache directory will remove the race condition.

I created get_cache_dir function in order to test the logic. This is only used to set the CACHE_DIR constant.

Y'all deserve it :)

This PR is intended to have no change to semantics.

This is in preparation for #2784 which will likely introduce more logic that depends on current_line.depth.

Inlining the subtraction gets rid of offsetting and makes it much easier to see what the result will be.

Co-authored-by: hauntsaninja <>

Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com

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

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

Closes #2360: I'd like to make passing SRC or --code mandatory and the arguments mutually exclusive. This will change our (partially already broken) promises of CLI behavior, but I'll comment below.

Since power operators almost always have the highest binding power in expressions, it's often more readable to hug it with its operands. The main exception to this is when its operands are non-trivial in which case the power operator will not hug, the rule for this is the following:

For power ops, an operand is considered "simple" if it's only a NAME, numeric CONSTANT, or attribute access (chained attribute access is allowed), with or without a preceding unary operator.

Fixes GH-538. Closes GH-2095.

diff-shades results: https://gist.github.com/ichard26/ca6c6ad4bd1de5152d95418c8645354b

Co-authored-by: Diego dpalma@evernote.com Co-authored-by: Felix Hildén felix.hilden@gmail.com Co-authored-by: Jelle Zijlstra jelle.zijlstra@gmail.com

The previous run-twice logic only affected the stability checks but not the output. Now, we actually output the twice-formatted code.

Found by the fuzzer. Repro case:

python -m black -c 'importA;()<<0**0#'

At the moment, it's just a source of spurious CI failures and busywork updating the configuration file.

Unlike diff-shades, it is run across many different platforms and Python versions, but that doesn't seem essential. We already run unit tests across platforms and versions.

I chose to leave the code around for now in case somebody is using it, but CI will no longer run it.

Co-authored-by: Jelle Zijlstra jelle.zijlstra@gmail.com Co-authored-by: Felix Hildén felix.hilden@gmail.com

Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com

Fixes #2651. Fixes #2754. Fixes #2518. Fixes #2321.

This adds a test that lists a number of cases of unstable formatting that we have seen in the issue tracker. Checking it in will ensure that we don't regress on these cases.

Closes #1256: I reworded our style docs to be more explicit about the style we're aiming for and how it is changed (or isn't).

It turns out "simple_stmt" isn't that simple: it can contain multiple statements separated by semicolons. Invisible parenthesis logic for arithmetic expressions only looked at the first child of simple_stmt. This causes instability in the presence of semicolons, since the next run through the statement following the semicolon will be the first child of another simple_stmt.

I believe this along with #2572 fix the known stability issues.

It was causing stability issues because the first pass could cause a "magic trailing comma" to appear, meaning that the second pass might get a different result. It's not critical.

Some things format differently (with extra parens)

Co-authored-by: hauntsaninja <>

We no longer use it

PDM uses this as part of not-accepted-yet PEP 582.

Co-authored-by: Jelle Zijlstra jelle.zijlstra@gmail.com Co-authored-by: Felix Hildén felix.hilden@gmail.com

I did this manually for the last few releases and I think it's going to be helpful in the future too. Unfortunately this adds a little more work during the release (sorry @cooperlees).

This change will also improve the merge conflict situation a bit, because changes to different sections won't merge conflict.

For the last release, the sections were in a kind of random order. In the template I put highlights and "Style" first because they're most important to users, and alphabetized the rest.

It was missing --diff as one of the default arguments passed.

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

Bumps sphinx-copybutton from 0.4.0 to 0.5.0.


updated-dependencies:

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Just make them alphabetical.

"you your" -> "your"

Co-authored-by: Felix Hildén felix.hilden@gmail.com

Bumps furo from 2022.1.2 to 2022.2.14.1.


updated-dependencies:

Signed-off-by: dependabot[bot] support@github.com Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Race between #2889 and another PR.

Fixes #2897

MD5 is unavailable on systems with active FIPS mode. That makes black crash when run on such systems.

If a vim/neovim user wishes to suppress loading the vim plugin by setting g:load_black in their VIMRC (for me, Arch linux automatically adds the plugin to Neovim's RTP, even though I'm not using it), the current location of the test comes after a call to has('python3'). This adds, in my tests, between 35 and 45 ms to Vim load time (which I know isn't a lot but it's also unnecessary). Moving the call to exists('g:load_black') to before the call to has('python3') removes this unnecessary test and speeds up loading.

Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com

Bumps furo from 2022.2.14.1 to 2022.3.4.


updated-dependencies:

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Fixes #2878

Bumps actions/checkout from 2 to 3.


updated-dependencies:

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Bumps actions/setup-python from 2 to 3.


updated-dependencies:

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Cooper Lees me@cooperlees.com

Fixes #2569

Enjoy your retirement at https://github.com/cooperlees/black-primer

It is falsely placed in preview features and always formats the power operators, it was added in #2789 but there is no check for formatting added along with it.

Fixes #2588

Fixes #2938.

All of these suggested future changes are out of scope for an autoformatter and should be handled by a linter instead.

It's in beta.

https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view

Closes #2918.

Fixes a couple places where we were using the same variable name as we are iterating over.

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

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

Now PRs will run two diff-shades jobs, "preview-changes" which formats all projects with preview=True, and "assert-no-changes" which formats all projects with preview=False. The latter also fails if any changes were made.

Pushes to main will only run "preview-changes"

Also the workflow_dispatch feature was dropped since it was complicating everything for little gain.

Bumps sphinx from 4.4.0 to 4.5.0.


updated-dependencies:

Signed-off-by: dependabot[bot] support@github.com Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Fixes #2964

Bumps actions/cache from 2.1.7 to 3.


updated-dependencies:

Signed-off-by: dependabot[bot] support@github.com Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

aiohttp.test_utils.unittest_run_loop was deprecated since aiohttp 3.8 and aiohttp 4 (which isn't a thing quite yet) removes it. To maintain compatibility with the full range of versions we declare to support, test_blackd.py will now define a no-op replacement if it can't be imported.

Also, mypy is painfully slow to use without a cache, let's reenable it.

Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com

Click 8.1.1 was released with a fix for pallets/click#2227.

Bumps peter-evans/find-comment from 1.3.0 to 2.


updated-dependencies:

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Bumps peter-evans/create-or-update-comment from 1.4.5 to 2.


updated-dependencies:

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

See #2965

I left the version check in place because mypy doesn't generally like try-excepted imports.

Broken when we converted some more RST docs to MyST

Co-authored-by: Jelle Zijlstra jelle.zijlstra@gmail.com Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com

The 8.0.x series renamed its "die on LANG=C" function and the 8.1.x series straight up deleted it.

Unfortunately this makes this test type check cleanly hard, so we'll just lint with click 8.1+ (the pre-commit hook configuration was changed mostly to just evict any now unsupported mypy environments)

Co-authored-by: Jelle Zijlstra jelle.zijlstra@gmail.com Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com

Example:

black, 22.1.1.dev56+g421383d.d20220405 (compiled: no) Python (CPython) 3.9.12

Co-authored-by: Batuhan Taskaya isidentical@gmail.com

Allows us to better control placement of return annotations by:

a) removing redundant parens b) moves very long type annotations onto their own line

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

This is a tricky one as await is technically an expression and therefore in certain situations requires brackets for operator precedence. However, the vast majority of await usage is just await some_coroutine(...) and similar in format to return statements. Therefore this PR removes redundant parens around these await expressions.

Co-authored-by: Jelle Zijlstra jelle.zijlstra@gmail.com Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com

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

I realized we don't have a FAQ entry about this, let's change that so compiled: yes/no doesn't surprise as many people :)

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

Bumps actions/upload-artifact from 2 to 3.


updated-dependencies:

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Bumps furo from 2022.3.4 to 2022.4.7.


updated-dependencies:

Signed-off-by: dependabot[bot] support@github.com Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

We just got someone on Discord who was confused because the command as written caused their shell to try to do command expansion.

Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com

Fixes #3022

Co-authored-by: Cooper Lees me@cooperlees.com

Test: tox -e fuzz

Bumps myst-parser from 0.16.1 to 0.17.2.


updated-dependencies:

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Restrict the GitHub token permissions only to the required ones; this way, even if the attackers will succeed in compromising your workflow, they won’t be able to do much.

https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions

https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs

Keeping your GitHub Actions and workflows secure Part 1: Preventing pwn requests

Signed-off-by: naveen 172697+naveensrinivasan@users.noreply.github.com

This is a slight perf win for use-cases that don't invoke reformat_many(), but more importantly to me today it means I can use Black in pyscript.

Fixes #1632

Co-authored-by: Felix Hildén felix.hilden@gmail.com

Co-authored-by: Felix Hildén felix.hilden@gmail.com

Bumps docker/setup-qemu-action from 1 to 2.


updated-dependencies:

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Bumps docker/build-push-action from 2 to 3.


updated-dependencies:

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Bumps docker/login-action from 1 to 2.


updated-dependencies:

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Bumps docker/setup-buildx-action from 1 to 2.


updated-dependencies:

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com

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

Co-authored-by: Cooper Lees me@cooperlees.com

Bumps pre-commit/action from 2.0.3 to 3.0.0.


updated-dependencies:

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

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

Furo, myst-parser, and Sphinx (had to pin docutils due to sphinx breakage)

Bumps actions/setup-python from 3 to 4.


updated-dependencies:

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

Co-authored-by: Cooper Lees me@cooperlees.com

Bumps sphinx from 5.0.1 to 5.0.2.


updated-dependencies:

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Bumps furo from 2022.6.4.1 to 2022.6.21.


updated-dependencies:

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Covers GH-2926, GH-2990, GH-2991, and GH-3035.

Co-authored-by: Jelle Zijlstra jelle.zijlstra@gmail.com Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com

See the deprecation notice: https://docs.readthedocs.io/en/stable/config-file/v2.html#python-version

Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com

Consequently with other places in the document

Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com

Otherwise they'd be deleted which was a regression in 22.1.0 (oops! my bad!). Also type comments are now tracked in the AST safety check on all compatible platforms to error out if this happens again.

Overall the line rewriting code has been rewritten to do "the right thing (tm)", I hope this fixes other potential bugs in the code (fwiw I got to drop the bugfix in blib2to3.pytree.Leaf.clone since now bracket metadata is properly copied over).

Fixes #2873

Doing so is invalid. Note this only fixes the preview style since the logic putting closing docstring quotes on their own line if they violate the line length limit is quite new.

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

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

Test:

cooper@l33t:~/repos/black$ /tmp/tb/bin/black .
All done! ✨ 🍰 ✨
44 files left unchanged.

Fixes #3110

Fix my silly typo.

Co-authored-by: Thomas Grainger tagrain@gmail.com

Co-authored-by: Cooper Ry Lees me@wcooperlees.com Co-authored-by: Thomas Grainger tagrain@gmail.com

The former was a regression I introduced a long time ago. To avoid changing the stable style too much, the regression is only fixed if --preview is enabled

Annoyingly enough, as we currently always enforce a second format pass if changes were made, there's no good way to prove the existence of the docstring quote normalization instability issue. For posterity, here's one failing example:

--- source
+++ first pass
@@ -1,7 +1,7 @@
 def some_function(self):
-    ''''<text here>
+    """ '<text here>

     <text here, since without another non-empty line black is stable>

-    '''
+    """
     pass
--- first pass
+++ second pass
@@ -1,7 +1,7 @@
 def some_function(self):
-    """ '<text here>
+    """'<text here>

     <text here, since without another non-empty line black is stable>

     """
     pass

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

The old regex in the example was invalid and caused an error on startup.

When the Leaf node with # fmt: skip is a NEWLINE inside a suite Node, the nodes to ignore should be from the siblings of the parent suite Node.

There is a also a special case for the ASYNC token, where it expands to the grandparent Node where the ASYNC token is.

This fixes GH-2646, GH-3126, GH-2680, GH-2421, GH-2339, and GH-2138.

... in the middle of an expression or code block by adding a missing return.

Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com Co-authored-by: Jelle Zijlstra jelle.zijlstra@gmail.com

... for consistency

Bumps sphinx from 5.0.2 to 5.1.0.


updated-dependencies:

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Co-authored-by: Shivansh-007 shivansh-007@outlook.com

As mentioned in GH-3185, when using Black as a Vim plugin, especially automatically on save, the plugin's messages can be confusing, as nothing indicates that they come from Black.

As error logs are emitted often (they happen when Black's cache directory is created after blib2to3 tries to write its cache) and cause issues to be filed by users who think Black isn't working correctly.

These errors are expected for now and aren't a cause for concern so let's remove them to stop worrying users (and new issues from being opened). We can improve the blib2to3 caching mechanism to write its cache at the end of a successful command line invocation later.

Building executables without any testing is quite sketchy, let's at least verify they won't crash on startup and format Black's own codebase.

Also replaced "binaries" with "executables" since it's clearer and won't be confused with mypyc.

Finally, I added colorama so all Windows users can get colour.

Bumps sphinx from 5.1.0 to 5.1.1.


updated-dependencies:

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

moves the installation path from /root/.local to a virtualenv. this way we still get the lightweight multistage build without excluding non-root users.

A changelog entry has been added under the Integration subheader

we are now using the inbuilt venv activate script, as well as explicitly mentioning the binary location in the entrypoint cmd.

Co-authored-by: Nicolò nicolo.intrieri@spinforward.it Co-authored-by: Cooper Lees me@cooperlees.com

uR is not a legal string prefix, so this test breaks (AssertionError: cannot use --safe with this file; failed to parse source file AST: invalid syntax) if changed to one in which the file is changed. I've changed the last test to have u alone, and added an R to the test above instead.

Fixes GH-2907.

This makes type checking PEP 484 compliant (as of 2018). mypy will change its defaults soon.

See: https://github.com/python/mypy/issues/9091 https://github.com/python/mypy/pull/13401

Fixes #3195

Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com

Fixes #2296, #3204

This file gets scraped a lot, so create a distinct email for potential spam.

Test:

Co-authored-by: Cooper Ry Lees me@wcooperlees.com Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com

Fixes #2734: a standalone comment causes strings to be merged into one far too long (and requiring two passes to do so).

Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com

Updates action.yml to use the alternative $GITHUB_ACTION_PATH variable instead of the original ${{ github.action_path }} which caused issues with bash on the Windows runners. This removes the need for a Python subprocess to call the main.py script.

There are a number of places this behaviour could be patched, for instance, it's quite tempting to patch it in get_sources. However I believe we generally have the invariant that project root contains all files we want to format, in which case it seems prudent to keep that invariant.

This also improves the accuracy of the "sources to be formatted" log message with --stdin-filename.

Fixes GH-3207.

black.reformat_many depends on a lot of slow-to-import modules. When formatting simply a single file, the time paid to import those modules is totally wasted. So I moved black.reformat_many and its helpers to black.concurrency which is now only imported if there's more than one file to reformat. This way, running Black over a single file is snappier

Here are the numbers before and after this patch running python -m black --version:

Co-authored-by: Fabio Zadrozny fabiofz@gmail.com

Loading .gitignore and compiling the exclude regex can take more than 15ms. We shouldn't and don't need to pay this cost if we're simply formatting files given on the command line directly.

I would've loved to lazily import pathspec, but the patch won't be clean until the file collection and discovery logic is refactored first.

Co-authored-by: Fabio Zadrozny fabiofz@gmail.com

os.cpu_count() can return None (sounds like a super arcane edge case though) so the type annotation for the workers parameter of black.main is wrong. This could technically cause a runtime TypeError since it'd trip one of mypyc's runtime type checks so we might as well fix it.

Reading the documentation (and cross-checking with the source code), you are actually allowed to pass None as max_workers to concurrent.futures.ProcessPoolExecutor. If it is None, the pool initializer will simply call os.cpu_count() ^1 (defaulting to 1 if it returns None ^2). It'll even round down the worker count to a level that's safe for Windows.

... so theoretically we don't even need to call os.cpu_count() ourselves, but our Windows limit is 60 (unlike the stdlib's 61) and I'd prefer not accidentally reintroducing a crash on machines with many, many CPU cores.

Adds parentheses around implicit string concatenations when it's inside a list, set, or tuple. Except when it's only element and there's no trailing comma.

Looking at the order of the transformers here, we need to "wrap in parens" before string_split runs. So my solution is to introduce a "collaboration" between StringSplitter and StringParenWrapper where the splitter "skips" the split until the wrapper adds the parens (and then the line after the paren is split by StringSplitter) in another pass.

I have also considered an alternative approach, where I tried to add a different "string paren wrapper" class, and it runs before string_split. Then I found out it requires a different do_transform implementation than StringParenWrapper.do_transform, since the later assumes it runs after the delimiter_split transform. So I stopped researching that route.

Originally function calls were also included in this change, but given missing commas should usually result in a runtime error and the scary amount of changes this cause on downstream code, they were removed in later revisions.

Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com

Solves https://github.com/psf/black/issues/2598 where Black wouldn't use .gitignore at folder/.gitignore if you ran black folder for example.

Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com

Co-authored-by: Felix Hildén felix.hilden@gmail.com Co-authored-by: Jelle Zijlstra jelle.zijlstra@gmail.com

We've decided to a) convert stable back into a branch and b) to update it immediately as part of the release process. We may as well automate it. And about going back to a branch ...

Git tags are not the right tool, at all^1. They come with the expectation that they will never change. Things will not work as expected if they do change, doubly so if they change regularly. Once you pull stable from the remote and it's copied in your local repository, no matter how many times you run git pull you'll never see it get updated automatically. Your only recourse is to delete the tag via git tag -d stable before pulling.

This gets annoying really quickly since stable is supposed to be the solution for folks "who want to move along as Black developers deem the newest version reliable."^2 See this comment for how this impacts users using our Vim plugin^3. It also affects us developers[^4]. If you have stable locally, once we cut a new release and update the stable tag, a simple git pull / git fetch will not pull down the updated stable tag. Unless you remember to delete stable before pulling, stable will become stale and useless.

You can argue this is a good thing ("people should explicitly opt into updating stable"), but IMO it does not match user expectations nor developer expectations[^5]. Especially since not all our integrations that use stable are bound by this security measure, for example our GitHub Action (since it does a clean fetch of the repository every time it's used). I believe consistency would be good here.

Finally, ever since we switched to a tag, we've been facing issues with ReadTheDocs not picking up updates to stable unless we force a rebuild. The initial rebuild on the stable update just pulls the commit the tag previously pointed to. I'm not sure if switching back to a branch will fix this, but I'd wager it will.

[^4]: In fairness, most folks working on Black probably don't use the stable ref anyway, especially us maintainers who'd know what is the latest version by heart, but it'd still be nice to make it usable for local dev though.

[^5]: Also what benefit does a stable ref have over explicit version tags like 22.6.0? If you're going to opt into some odd pin mechanism, might as well use explicit version tags for clarity and consistency.

Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com Co-authored-by: Jelle Zijlstra jelle.zijlstra@gmail.com

This allows the configuration of the --preview flag in the Vim plugin.

This is deprecated since aiohttp 4.0. If it doesn't exist just define a no-op decorator that does nothing (after the other aiohttp imports though!). By doing this, it's safe to ignore the DeprecationWarning without needing to require the latest aiohttp once they remove @middleware.

Test:

Co-authored-by: Cooper Ry Lees me@wcooperlees.com Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com

Fix a crash when formatting some dicts with parenthesis-wrapped long string keys. When LL[0] is an atom string, we need to check the atom node's siblings instead of LL[0] itself, e.g.:

dictsetmaker
  atom
    STRING '"This is a really long string that can\'t be expected to fit in one line and is used as a nested dict\'s key"'
  /atom
  COLON ':'
  atom
    LSQB ' ' '['
    listmaker
      STRING '"value"'
      COMMA ','
      STRING ' ' '"value"'
    /listmaker
    RSQB ']'
  /atom
  COMMA ','
/dictsetmaker

These two paragraphs were tucked away at the end of the section, after the diversion on backslashes. I nearly missed the first paragraph and opened a nonsense issue, and I think the second belongs higher up with it too.

Make sure gcc is installed in the build env

The mypyc build requires gcc to be installed even if it's being built with clang, otherwise clang fails to find libgcc.

Signed-off-by: dependabot[bot] support@github.com Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Bumps cibuildwheel from 2.8.1 to 2.10.0 which has 3.11 building enabled by default. Unfortunately mypyc errors out on 3.11:

src/black/files.py:29:9: error: Name "tomllib" already defined (by an import) [no-redef]

... so we have to also hide the fallback import of tomli on older 3.11 alphas from mypy[c].

Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com

Previously Black produces invalid code because the # fmt: on is used on a different block level.

While Black requires # fmt: off and # fmt: on to be used at the same block level, incorrect usage shouldn't cause crashes.

The formatting behavior this PR introduces is, the code below the initial # fmt: off block level will be turned off for formatting, when # fmt: on is used on a different level or there is no # fmt: on. This also matches the current behavior when # fmt: off is used at the top-level without a matching # fmt: on, it turns off formatting for everything below # fmt: off.

docs: Make README logo link to docs

This implements PEP 621, obviating the need for setup.py, setup.cfg, and MANIFEST.in. The build backend Hatchling (of which I am a maintainer in the PyPA) is now used as that is the default in the official Python packaging tutorial. Hatchling is available on all the major distribution channels such as Debian, Fedora, and many more.

Python support

The earliest supported Python 3 version of Hatchling is 3.7, therefore I've also set that as the minimum here. Python 3.6 is EOL and other build backends like flit-core and setuptools also dropped support. Python 3.6 accounted for 3-4% of downloads in the last month.

Plugins

Configuration is now completely static with the help of 3 plugins:

Readme

hynek's hatch-fancy-pypi-readme allows for the dynamic construction of the readme which was previously coded up in setup.py. Now it's simply:

[tool.hatch.metadata.hooks.fancy-pypi-readme]
content-type = "text/markdown"
fragments = [
  { path = "README.md" },
  { path = "CHANGES.md" },
]

Versioning

hatch-vcs is currently just a wrapper around setuptools-scm (which despite the legacy naming is actually now decoupled from setuptools):

[tool.hatch.version]
source = "vcs"

[tool.hatch.build.hooks.vcs]
version-file = "src/_black_version.py"
template = '''
version = "{version}"
'''

mypyc

hatch-mypyc offers many benefits over the existing approach:

Co-authored-by: Richard Si 63936253+ichard26@users.noreply.github.com Co-authored-by: Jelle Zijlstra jelle.zijlstra@gmail.com

I also missed the accidental removal of the 3.11 classifier in the PR.

updated-dependencies:

Signed-off-by: dependabot[bot] support@github.com Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Bumps sphinx from 5.1.1 to 5.2.1.


updated-dependencies:

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

Signed-off-by: dependabot[bot] support@github.com Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

To run the formatter on Jupyter Notebooks, Black must be installed with an extra dependency (black[jupyter]). This commit adds an optional argument to install Black with this dependency when using the official GitHub Action 1. To enable the formatter on Jupyter Notebooks, just add jupyter: true as an argument. Feature requested at 2.

Signed-off-by: Antonio Ossa Guerra aaossa@uc.cl

This makes the location more explicit which hopefully makes the PR process smoother for other first time contributors.

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

updated-dependencies:

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

No idea how this is still here after the Hatchling PR, but it is no longer useful and is breaking the build.

Jupyter creates a checkpoint file every single time you create an .ipynb file, and then it updates the checkpoint file every single time you manually save your progress for the initial .ipynb. These checkpoints are stored in a directory named .ipynb_checkpoints.

Co-authored-by: Batuhan Taskaya isidentical@gmail.com

Bumps myst-parser from 0.18.0 to 0.18.1.


updated-dependencies:

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

Signed-off-by: dependabot[bot] support@github.com Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Bumps furo from 2022.9.15 to 2022.9.29.


updated-dependencies:

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

Signed-off-by: dependabot[bot] support@github.com Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Cooper Lees cooper@fb.com

Bumps sphinx from 5.2.1 to 5.2.3.


updated-dependencies:

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

Signed-off-by: dependabot[bot] support@github.com Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Bumps docutils from 0.18.1 to 0.19.


updated-dependencies:

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

Co-authored-by: KotlinIsland kotlinisland@users.noreply.github.com

This commit adds a CLi option to skip the first line in the source files, just like the Cpython command line allows 1. By enabling the flag, using -x or `--ski…