Set tool.black.exclude so that stdlib/venv is not excluded when "manually" invoking Black#15909
Merged
Conversation
…manually" invoking Black
brianschubert
approved these changes
Jun 13, 2026
brianschubert
left a comment
Collaborator
There was a problem hiding this comment.
seems sensible to me!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If you don't set
tool.black.exclude, Black by default ignores everything listed in your.gitignorefile and ignores a hardcoded list of regex patterns. This is documented here. One of those regex patterns isvenv, so if you runuvx black stdlib/venvin this repo, Black currently does this:Now, that actually doesn't matter much for CI in this repo right now, because we run Black in CI via pre-commit, which passes all files to be formatted as positional arguments when it invokes Black. Explicitly passed positional files are formatted by Black even if the whole directory matches an exclude pattern:
So Black has been enforced in CI anyway for typeshed because of the specific way we've been invoking it. Still, it seems weird that, right now, exactly which files are formatted depends on exactly how you're invoking Black. This PR therefore adds a
tool.black.excludesetting so that this is consistent however you invoke Black. It has the same exclusions as thetool.ruff.excludesetting we already specify in ourpyproject.tomlfile.This problem has existed since 1f1bc6f, when typeshed replaced its
tool.black.excludesetting with atool.black.force-excludesetting! The reason why I noticed it now is that I was investigating why some of the docstrings in Ruff's codemodded version of typeshed have apparently quite bad formatting. The reason is that we format the stubs after codemodding them usinguvx black --config=<typeshed pyproject.toml file>, and typeshed's pyproject.toml file doesn't specifytool.black.exclude, so in Ruff's CI we were just falling back to Black's default exclude patterns too. If necessary, I can just fix this problem in Ruff's CI, but I figured that it's quite confusing to have Black work differently in typeshed depending on how it's invoked, so it might be better to fix the problem over here.(We use Black to format the stubs in Ruff's CI so that we minimize spurious differences with the upstream stubs; formatting the codemodded stubs with Ruff would increase the risk of that.)