#black-formatter
1 messages ยท Page 1 of 1 (latest)
the big one was a weekend where I decided to do a lot of triaging
and others joined in
some of the others were similar, a few were us merging changes that fixed a lot of issues
those days were fun ๐
Ok, that's cool.
Haha, I have a bunch of silly charting scripts working with github issue and PR data :D
<!--
Please make sure that the bug is not already fixed either in newer versions or the
current development version. To confirm this, you have three options:
- Update Black's version if a newer release exists:
pip install -U black - Use the online formatter at , which will use
the latest main branch. - Or run Black on your machine:
- create a new virtualenv (make sure it's the same Python version);
- clone this repository;
- run
pip install -e .[d]; - run `...
Is your feature request related to a problem? Please describe.
When Black is run automatically as a Vim plugin, eg. upon save, and an error occurs, it is not clear that the error comes from Black.
For instance, when saving a Python file using the match ...: new syntax with an old version of Black, vim logs
Cannot parse: 282:14: match expr:
(this can be reproduced with :Black target_version=py38 with an up-to-date Black)
When Black is run automatically,...
So I have a co-worker who really doesn't want to use black because he feels it's not important enough or relevant because what we are working on is not a corporate-scale project. He also dislikes that his inline comments are re-formatted so they are not aligned with subsequent lines of code. What would be a good argument for using black? I think it's a great tool that would help us out a lot.
What would be a good argument for using black?
Not having to argue with your co-worker about style anymore lmao.
Sorry, someone else will probably be able to respond to this question better than me, the only reason I could find in the docs are here: https://black.readthedocs.io/en/stable/#the-uncompromising-code-formatter
He also dislikes that his inline comments are re-formatted so they are not aligned with subsequent lines of code.
This minimizes git diffs which generally makes reviewing easier
This question ("Why would I want to use Black?") could actually make for a good FAQ entry in the docs.
Yeah, that's something I looked for but wasn't there.
Will add your responses to my arsenal of arguments for it :p
Description
Issue #2503.
Documentation only.
Updates the "vim-plug" and "Vundle" instructions to reflect that the "origin/stable" branch was replaced with a "stable" tag.
https://github.com/psf/black/issues/2503
Checklist
Documentation only.
- [ x ] Add a CHANGELOG entry if necessary? - not applicable
- [ x ] Add / update tests if necessary? - not applicable
- [ x ] Add new / update outdated documentation?
Describe the style change
Prefer formatting an expression with a line break before the operator instead of breaking for a getitem key. This seems to be a rare example where black is making the code far less readable.
Examples in the current Black style
bad = (self.data[f"aoacfct{slot}"][i0:i1] != "TRAK") & self.data[
"npnt_kalm"
][i0:i1]
Desired style
bad = (
...
Description
Resolves #2930 and closes #2941.
Checklist - did you ...
- [x] Add a CHANGELOG entry if necessary? -> n/a
- [x] Add / update tests if necessary? -> n/a
- [x] Add new / update outdated documentation? -> n/a
Feels good to be working on Black again :)
I've changed my mind on how I want to approach the CI/CD revamp, so it shouldn't take too long to prepare CD in time for 22.7.0 now
Description
This comes from https://github.com/psf/black/pull/3017 which in hindsight was making too many changes at once. This should be easier to review, hopefully :)
This is not required for the upcoming 22.7.0 release, this is just the easiest part of #3017 to file separately. There's no rush to merge this.
Checklist - did you ...
- [x] Add a CHANGELOG entry if necessary?
- [x] Add / update tests if necessary?
- [x] Add new / update outdated documentation?
I'm still bad at keeping my commits focused and atomic, but this should be an improvement ^
Why is GitHub sending me three notifications for the failed changelog workflow? So unnecessary and annoying.
Description
Building executables without any testing is quite sketchy, let's at least verify they won't crash on startup and can 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.
Similar to #3189, this is not required for the upcoming 22.7.0 release, this is 2nd easiest part of https://github.com/psf/black/pull/3017 to file separately. Th...
Description
Got bored waiting for CI to pass on my other PRs. I'm surprised black types check without changes upgrading mypy!
Checklist - did you ...
- [x] Add a CHANGELOG entry if necessary? -> n/a
- [x] Add / update tests if necessary? -> n/a
- [x] Add new / update outdated documentation? -> n/a
Having ported over the mypyc wheel build workflow to here[^1], I realized it's using macOS 10.15 for all of the macOS wheels which has been deprecated since May. We got around a month to move to macOS 11 or 12 before it will be removed and things will break.
We might also want to bump the Windows and Ubuntu OS versions. We could also move to us...
Description
This has been annoying me for too long.
As error logs are emitted often (they happen as 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 suc...
The above doesn't really fix the root issue, but these logs have been annoying me and users for no good reason for too long.
seriously, there was confusion over this at work too?!
why didn't I file this PR earlier ๐
Description
As mentioned in #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.
This PR simply prefixes the messages with "Black: ".
Checklist - did you ...
- [X] Add a CHANGELOG entry if necessary?
- [X] Add / update tests if necessary? [no changes needed]
- [X] Add new / update outdated documentation? [no changes needed]
It seems that blackd does not support the preview option now.
I suggest implementing an option for that like it is done for other features https://black.readthedocs.io/en/stable/usage_and_configuration/black_as_a_server.html#protocol
Something like X-PREVIEW would be fine.
I faced this while using **[intellij-blackconnect](https://github.com/lensvol/intellij-blackcon...
As someone who's lost many hours to silent actions like this, I dislike silencing errors (even subtle ones) completely. Having a debug error might save someone hours in the future.
All LGTM and I see no reason to merge.
The question is that when and to whom would the logs be useful? The regular users only see this if they're using some editor integration that has logging enabled, people who use black as a library (which is technically unsupported, but we can't stop them) also have to have logging enabled. Developers of black are unlikely to see these logs because blib2to3 is the only code that uses logging, everything else uses print / click.echo for messaging.
Yes, it could be useful, but I don't think the debugging value is worth the confusion and scare this has been giving to users.
I probably should've put this in a comment on the PR. Will do that actually.
colorama isn't needed on W10, even when using cmd. It supports ansi escapes
It doesn't support everything but it definitely supports colors
Googling suggests you need to enable virtual terminal something for CMD to support ANSI but I don't know anymore
I do have a windows machine so I'll check soon
We're talking about old CMD only
if you have windows terminal installed, even starting cmd natively will open it in terminal
I'm talking about w10 cmd
Not terminal
I know rich got rid of colorama completely
Which is a huge success because colorama is painful
It might require a winapi call to enable it for the app to keep support with legacy apps, unsure
But that's certainly doable with Python, I guess ctypes
if you have terminal installed at all, opening CMD opens it in terminal
oh, right, dind't know this
Did cmd enable the virtual processing flag by default now?
I know when they added it, they didn't enable it on conhost by default
I dunno, jackenmen says yes but IME no, conhost still starts in legacy mode
It's a winapi call probs
That was several years ago though so maybe a windows 10 update changed things
Setting ENABLE_VIRTUAL_TERMINAL_INPUT via https://docs.microsoft.com/en-us/windows/console/setconsolemode will work
Setting ENABLE_VIRTUAL_TERMINAL_PROCESSING too
not sure if that can be done on an existing cmd process by a child though
Yea, otherwise we could replace colorama via an API call
That's what rich does
Honestly I just find colorama incredibly annoying and would love if it wasn't a hard dep
I think it's transitive dep from click tho so
setup.py lines 5 to 8
install_requires=[
"colorama; platform_system == 'Windows'",
"importlib-metadata; python_version < '3.8'",
],```
so technically our colorama extra is unnecessary
also, our colorama extra doesn't actually check if the system is Windows so it's a bit expansive that way ๐
Do we want to prefix the installation messages with Black: too, or is that overkill? Either way, thanks for the PR!
Is your feature request related to a problem? Please describe.
Black's general philosophy is to prefer double quotes, but only if doing so doesn't involve additional escaping.
In both of the following I'd argue triple single quotes are a better match:
""""How are you\""""
'''"It isn't fair", he said.'''
Blackened, this is:
""""How are you\""""
""""It isn't fair", he said."""
Triple single quotes would allow you to skip some escaping in the first, so cha...
man, I feel bad about upstreaming the mypyc workflow so close to the release deadline ๐
Life's been busy and I haven't found the time for much, but I think I'll just manage.
.rw-rw-r-- 3.9M ichard26 ichard26 28 Jul 2:31 black-0.1.2a7-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.rw-rw-r-- 4.0M ichard26 ichard26 28 Jul 2:31 black-0.1.2a7-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.rw-rw-r-- 4.3M ichard26 ichard26 28 Jul 2:31 black-0.1.2a7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.rw-rw-r-- 4.4M ichard26 ichard26 28 Jul 2:31 black-0.1.2a7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.rw-rw-r-- 4.4M ichard26 ichard26 28 Jul 2:31 black-0.1.2a7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.. whaat? why are the linux wheels so big now?
they've tripled in size
I can confirm debug symbols are still stripped, so I guess this is mostly just changes to mypyc...?
I wonder if it's better to hold off using mypy[c]==0.972 for this release so I have more time to sort this out (and also properly test out macOS ARM)
Yeah, I'm going to stick with the same mypy[c] version for compilation for now. I don't trust updating the buildchain so close to the release, would rather stick with what's known to work just fine.
.. wait, no, I was wrong, debug symbols are now being added. I forgot there was a somewhat recent to mypyc that appends -g1 to CFLAGS by default
Still going to postpone the various buildchain updates though as I don't have the time to give them the attention and care they need.
Description
This is the last part of #3017. This is effectively unchanged from the original PR, except for the addition of a commit to workaround a Windows shell quoting crash that I can't be bothered to deal with properly.
I don't really have solid test workflow runs to prove this will 100% work, but I've tested similar changes in this PR successfully (don't mind the Windows failure, I messed up). The only ...
d85cf00 Remove blib2to3 grammar cache logging (#3193) - ichard26
eaa0489 Add sanity check to executable CD + more (#3190) - ichard26
Signed-off-by: Shivam Durgbuns
Description
Checklist - did you ...
- [ ] Add a CHANGELOG entry if necessary?
- [ ] Add / update tests if necessary?
- [ ] Add new / update outdated documentation?
we can't
but you can!
use isort or ฮผsort
or just ฮผfmt that combines black and ฮผsort
Description
Makes more sense in scripts/ anyway.
Checklist - did you ...
- [x] Add a CHANGELOG entry if necessary? -> n/a
- [x] Add / update tests if necessary? -> n/a
- [x] Add new / update outdated documentation? -> n/a
Sure if it makes your OCD happy :)
I feel itโs more tests / testing โฆ so maybe into the black test directory โฆ
<!--
Please make sure that the bug is not already fixed either in newer versions or the
current development version. To confirm this, you have three options:
- Update Black's version if a newer release exists:
pip install -U black - Use the online formatter at , which will use
the latest main branch. - Or run Black on your machine:
- create a new virtualenv (make sure it's the same Python version);
- clone this repository;
- run
pip install -e .[d]; - run `...
@lament crow yeah the old CMD prompt does require the register tweak first before supporting colours
well, click is going to force us to pull colorama on windows anyway so not sure what the point would be ยฏ_(ใ)_/ยฏ
As long as it's transitive dep/extra, it's fine :P Maybe one day click will get rid of colorama
interesting project
This is my action on github
and it says that file got reformatted but nothing got changed in that file
when using the command locally it works
would appreciate some help
What should be reformatted is between functions in class i specially left multiple free lines to test it out locally it formats it correctly but on github the file is unchanged
CI correctly reports that files got reformatted, I'm sure. The thing is that CI doesn't commit and push any changes that are made in the repository after it runs.
The job that you posted is only supposed to report whether files are correctly formatted or not
ok and how to create a workflow wich also formats the files
cause locally when i use it it formats the files aswell
It does format the files, in the CI's environment. When you use it locally, the same happens, it formats it in your environment. Nothing automatically gets committed and pushed
So, you should ask yourself what you want to happen if there are any changes.
Make some commit? Make a PR?
ok then how should it auto-commit the reformatting it has done?
generally that's hard to do with a GitHub Actions workflow
at some projects I work on we use pre-commit.ci, it can run on PRs and push to the PR branch with formatting fixes
ok i guess then i'll just remove the workflow and tell everyone to format their code before pushing it since we are working on a rather small project with not so many contributors
Huh, I thought pre-commit.ci can also run on the branch but doesn't seem like it.
That is generally how people should work on the project, yes.
There are tools such as pre-commit that can ensure that your code is formatted properly before it allows you to commit it.
That's something that each person could install locally if they want to not forget about formatting changes and it would then use repository's configuration as described here:
Okay thanks for the help guys.
If anyone experienced with docker wants a probably simple issue to work on, psf/black#2975 is it!
Thoughts on psf/black#3089 ?
I'm inclined to accept it, but it would make this look less consistent
if condition:
def g():
pass
else:
def f():
pass
if condition:
def g():
pass
else:
def f():
pass
!remind 3D revisit 22.8.0 milestone and ask some past contributors whether they'd like to pick up some issues
Your reminder will arrive on <t:1659644433:F>!
I have two issues where I know who I'll ask, but they have open PRs currently and I'd feel bad about asking them to pick up another issue when they already have something in the works ๐
i can happily take a look at this
Description
Changes the default docker image installation to be made in a virtualenv. This way we get to keep the handy multistage build without excluding non-root users.
fixes #2975
Checklist - did you ...
- [ x] Add a CHANGELOG entry if necessary?
- [ x] Add / update tests if necessary?
- [ x] Add new / update outdated documentation?
There is no mitigation here, it's simply ignoring the issue. We might want to also try except this decorator though similar to https://github.com/psf/black/pull/2974 so when aiohttp does remove this decorator, nothing breaks :)
Thoughts @graingert ?
Thanks. This makes sense. I just think we can tweak a few things.
FINALLY. I got a clean build on a much more modern cibuildwheel setup: https://github.com/ichard26/black-mypyc-wheels/actions/runs/2779048277 I just now need to upgrade cibuildwheel itself (which is going to be painful since it's crashing on Linux last time I tried) and then test all of the wheels again because basically everything has been changed.
Oh wow, the cibuildwheel upgrade worked without issue this time: https://github.com/ichard26/black-mypyc-wheels/runs/7623757626?check_suite_focus=true Not sure what fixed the crash I was running into previously, but I'll take it :)
Thanks for the testing. This all looks good to go for me. Shouldn't break anyone unless they were using full path to the old black - Not a lot we can do there ...
Remove optional brackets around unpacking
Since #2945, Black removes brackets in the following situation:
for (x, y) in stuff:
...
Perhaps this should be extended to include unpacking assignments.
Examples in the current Black style
(x, y) = point
(first, *rest, last) = things
[a, b] = foo # Not touched with for at the moment
Desired style
x, y = point
first, *rest, last = things
a, b = foo # Not touched with...
Describe the bug
Trailing commas inside indexing square brackets are not removed when running Black with -C. This also affects generic types with multiple parameters.
To Reproduce
For example, take this code:
x = [0, 1,]
x = z[0, 1,]
and run with -C. We get
x = [0, 1]
x = z[0, 1,]
Expected behavior
The final trailing comma should disappear.
x = z[0, 1]
Environment
- Black's version: 22.6.0. ...
Hey, someone interested in working on a project with me?
Description
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.
Checklist - did you ...
- [X] Add a CHANGELOG entry if necessary?
- [X] Add / update tests if necessary?
- [X] Add new / update outdated documentation?
sorry, I should've clarified that these channels are for specific open source projects you could contribute to
you're totally welcome to try contributing to our project (black) but this isn't the place to meet people to start a new project
Ohh, I see. Where can I see the idea of the projects and source code please?
Okey, I get it. Thanks.
ah of course I was the one who introduced this faulty test case haha, thank you for catching and fixing this!
507234c Remove invalid syntax in docstrings -S --previe... - TomFryers
With the (soon to be) introduction of mypyc into our release pipeline, releasing now means rolling the dice on whether the release automation will break or not. This would be extremely annoying and add considerable stress to an already tense situation (cutting a new release).
I have access to TestPyPI's black project now. Let's run the PyPI release workflow weekly (or biweekly maybe?) and push the distributions to TestPyPI for proper e2e testing.
Credits go to @cooperlees for the sugge...
How do we know when they wipe it and when we need to generate a new API token? I guess only when it fails right ...
Shouldn't be that often
They basically never wipe it AFAIK, but it should just involve recreating a testpypi account and token and rerunning the workflow
Although depending on whose token we use, we might have to bug Jelle to update the repository secret as I don't have admin permissions.
I mean, Jelle will be involved regardless, but the token's barer changes how much he has to help out
they don't wipe it at all
I spent some time writing down my to-do list for Black and my goodness, I think I need to delegate some tasks ๐
black doesnt reformat the contents of docstrings does it?
it does
It sometimes messes with the indentation according to some pep I can't recall
PEP 257 is docstring formatting
it doesnt fix line lengths though?
or does it?
cause thatd be awesome for what im trying to do
I think that's better as a third-party tool to be honest. I really don't see Black touching the contents of docstrings even more anytime soon.
The discussion on whether we even want black to make AST altering changes is still unresolved. See the pinned proposal from Jelle on GH.
FYI I added two more status labels primarily intended for PRs: S: up for grabs and S: blocked
Gosh, I think I found two more diff-shades bugs and one of them is annoying the hell out of me
not sure where the bug is coming from to be honest though, it's the weirdest diff-shades bug I've seen so far
so diff-shades saves a copy of the files it's running Black over, this is pretty helpful as you can export the source for a file that's newly crashing from an analysis via diff-shades show $project $filepath src -q > dump.py but it's somehow saving a malformed copy, and not malformed as in outdated, but straight up broken:
@@ -507,9 +507,9 @@
]
else:
if line.inside_brackets:
- transformers =
+ transformers = [delimiter_split, standalone_comment_split, rhs]
else:
- transformers =
+ transformers = [rhs]
here's a diff comparing diff-shades' copy and the same file from my local repository
wait whaat? the source copy is actually fine in the analysis file too, where is it getting corrupted?!
oh wait, I wonder if rich is parsing the list literals and subscripts as bbcode
https://github.com/ichard26/diff-shades/blob/bd7f033cda81175be2c46b381c02269dfa3bfe03/src/diff_shades/cli.py#L351 yup, guess who forgot a escape(...) call here
src/diff_shades/cli.py line 351
console.print(getattr(result, field_key), highlight=False, soft_wrap=True)```
I agree that this improves formatting. The code looks mostly good, but noticed few issues:
- Tuple literals are not considered, that seems unconsistent
- Wrapping broken up string literals that live alone in a sequence literal that simply has a trailing comma seems overkill?
--- test.py 2022-08-03 17:43:27.228805 +0000
+++ test.py 2022-08-03 17:43:28.373631 +0000
@@ -1,8 +1,10 @@
L2 = [
- "This is a really long string that can't be expected to fit in one line and is t...
To Reproduce
~/programming/oss/black on HEAD (b776bf9) [$?] via Python v3.8.5 (venv)
โฏ echo "print('Hello, world!')" > ../outside.py
~/programming/oss/black on HEAD (b776bf9) [$?] via Python v3.8.5 (venv)
โฏ cat ../outside.py | black --stdin-filename "../outside.py" -
No Python files are present to be formatted. Nothing to do ๐ด
~/programming/oss/black on HEAD (b776bf9) [$?] via Python v3.8.5 (venv) took 711ms
โฏ black ../outside.py
reformatted ../outside.py
...
I can take a look at this one
sounds good, lemme know if you need help!
It still makes me happy to see diff-shades do its job of testing Black well ๐
Even with how much I want to rewrite the codebase as it's pretty awful ๐
is there an article about what black actually is and does?
or can someone explain how it works
Description
Fixes behaviour that prevented formatting for files outside the current working directory (#3207).
# before the fix
โฏ cat ../script.py | python -m black --stdin-filename '../script.py' -
No Python files are present to be formatted. Nothing to do ๐ด
# after the fix
โฏ cat ../test.py | python -m black --stdin-filename '../test.py' -
print("hello world")
All done! โจ ๐ฐ โจ
1 file left unchanged.
Let me know what you think! Not sure about how e...
hi, python has a -x option to skip the first line of source files when using non standard shebang it would be logical to have the exact same for black.
Why? Are the shebangs not comments?
not on dos or web
on web it could look like https://github.com/pmp-p/python-wasm-plus/blob/gh-pages/pythons.html
the # not first ๐ฆ
so black does not like it
i don't know what you mean by weird, wasm is a tier 3 support in python, so it would be nice to decently format the code that can run on web pages too - not only on wasi platform ( where -x would work anyway )
I said weird, I didn't say black shouldn't support it.
Because it is weird...
To me anyhow
It seems like a weird limitation
If this is the only way to do whatever it is that this does
Here's your reminder: revisit 22.8.0 milestone and ask some past contributors whether they'd like to pick up some issues
[Jump back to when you created the reminder](#black-formatter message)
It's so awkward when I google "black playground"
def foo():
assert (
b"RuntimeError: zasnvkdifnb2rnf cannot be abcdefgh with a "
b"bjbkjdf dfsdf of asdfasdfs"
) in proc.stderr
becomes:
def foo():
assert (
b"RuntimeError: zasnvkdifnb2rnf cannot be abcdefgh with a "
b"bjbkjdf dfsdf of asdfasdfs"
in proc.stderr
)
This is a line longer and less readable, since the string is less separated from the contains
STGM. Thank you for fixing this so quickly!
Description
Fixes #2564 and closes #2656.
Checklist - did you ...
- [x] Add a CHANGELOG entry if necessary?
- [x] Add / update tests if necessary?
- [x] Add new / update outdated documentation? -> n/a
I love my internet connection, it's very stable <3
I would've thought the GitHub UI would realize the draft PR action really only happened once on a refresh, but nope ...
lol
I was looking through the CPython issue tracker for something new to work on since I've been feeling a bit meh about working on black lately, but I realized I'm still happier contributing to projects I already know
I may catch up on my python discord PR reviews soon though
I'm thoroughly confused ๐
it's patching black.reformat_many which should be impossible / crash since I moved that function in the PR this run is failing on
I like contributing to projects I haven't contributed to already but only if it's within my reach (or well, when I think it's within my reach; sometimes that doesn't go as well as I imagine)
I'm less likely to want to contribute if I don't have some stake in it. It's fine if that stake is far-fetched but it existing at all still helps
I would love to contribute some C code to CPython one day but that sounds like a long-term goal lol
<!--
Please make sure that the bug is not already fixed either in newer versions or the
current development version. To confirm this, you have three options:
- Update Black's version if a newer release exists:
pip install -U black - Use the online formatter at , which will use
the latest main branch. - Or run Black on your machine:
- create a new virtualenv (make sure it's the same Python version);
- clone this repository;
- run
pip install -e .[d]; - run `...
I first tested whether pathspec for this works properly and then at first thought it has a bug after which I looked at it again and saw a typo in what I put in there so I thought I must have made it. Little did I know it was the issue author that made the typo which I gladly re-typed ๐
haha lol
I'm pretty sure it is the actual issue here because I can't repro it with Black either and would have been surprised if I were able to but time to wait for them to respond
Yeah that's a long term goal of mine too. I've been learning C recently (https://github.com/ichard26/masml) and I'd love to contribute to Python core, extra points if it's C code
I agree. Probably why I branched out contributing to mypyc, python discord projects (@late dew and @toxic storm ), and flake8-bugbear is that I had connections to them already
I'm pretty focused on black so far ๐
I was a bit surprised seeing you in #cibuildwheel haha
that's actually an exception for this
to my knowledge, I don't have any stake in Cirrus CI support in cibuildwheel
but I was playing quite a bit with it recently and been pretty amazed with it
ahh i see
There was a different project where I made a PR to update cibuildwheel to get macOS M1 wheels so I guess that kind of made me look at cibuildwheel a bit closer
but like, I don't have an actual reason for contributing other than just feeling like it this time
that happens to me a fair bit, sometimes something catches my interest
That reminds me I should consider pinging the maintainer of that project to remind him of my PR which... I reeeeally try to avoid doing
Tbf, reminds me of all my python/cherry-picker PRs that are just sort of waiting there...
I went on issue closing spree there but most of my PRs haven't been looked at
Yeah that's another thing about contributing to python core, it can take forever for a PR to be merged
That reminds me of this PR which I filed one year and a day ago (lol) that's just sitting like a duck https://github.com/python/mypy/pull/10940
this isn't core but I'm guessing it's the same story since cherry-picker is maintained by a small subset of core devs
mainly Mariatta but I've seen that ลukasz was the one to merge some of my PRs there
Nice to see he's still the DIR. Although the lack of weekly updates is a shame
ye, I quite liked those
I say that and I could ask him directly about that since we are co-maintainers, but ยฏ_(ใ)_/ยฏ
are we talking about mypy?
ลukasz wrote black, y'know :p
hahahaha
huh, they don't seem gone
they came back 3 months ago
it seems liek
I'm often dense so this kind of stuff happens to me often too haha
:O
semi-regular though?
yeah, not weekly anymore
might depends on how much he's done within the week
yeah, also probably quite busy helping pablo with 3.11
right
and yeah, busy helping with 3.11, various Python conferences too
EuroPython was last month ๐
ลukasz was probably rehearsing for the piano concert
:)
I heard bits and pieces of that, still don't know what really happened though ๐
I wasn't there, just seen a small bit on Twitter
something something $insert-tweet-about-piano
lol
https://github.com/KJ002/Haemophilia/blob/main/.clang-format holy crap, this is like the opposite of black
lol
I tried to configure clang format once
I actually think there might have not been enough options...

there's a lot of options yet I think something just wasn't there
of course something wasn't there :p
It might be that I was trying to make it look in a way that resembles to what I'm used to from other languages rather than whatever C++ is actually formatted like, honestly can't remember
Mhmm, I format some of my C code as if it was Python code
Although I do use hanging function calls instead of exploding them
https://github.com/ichard26/masml/blob/6647357b3164e01a49fc6050462234d15039e070/masml.c#L235-L239 lol, I'm totally a maintainer of black
masml.c lines 235 to 239
if ((arg && arg[0] != '&')
&& (atof(arg) == 0.0 && strcmp(arg, "0") && strcmp(arg, "0.0"))) {
printf("[FATAL] invalid numerical constant on line %zu\n", i);
goto BAIL;
}```
masml.c lines 267 to 270
if (arg && arg[0] == '&') {
printf("[LINE %-3zu] %-13s %-7s %s -> ram[%zu]\n",
i, stype, reg, arg, var_index);
} else {```
seems like I was wrong and most of what I wrote was hanging rather than exploded
might partially be because most of what I wrote used clang-format
BasedOnStyle: Chromium
IndentWidth: 4
ColumnLimit: 88
AccessModifierOffset: -2
BreakBeforeBinaryOperators: All
I've done exploding with Java more
I'll probably use clang-format eventually, but I've been sticking with hand formatting so far
I have an informal but totally non-strict line length limit of 90 I try to follow
ah great, nox just dropped python 3.6 support with their newest release. I was planning to finally switch black over to nox this summer
are you unhappy with tox?
it's fine, but I find nox easier to use / wrap around
also nox would probably play a lot nicer with the weird needs of my mypyc work
hmm, was tox 4 supposed to be released in May or sth?
I have no idea, I guess I can look at that too
I see it isn't but I vaguely recall it being planned to happen sooner
I was trying to run the test suite with a built wheel file (from cibuildwheel) and the way our tox setup works doesn't just work for that
I could probably let tox install the project itself instead of setting skip_install = True and then installing black manually, but I dunno
!remind 18H look into tox 4 if you're bored and have nothing else to do
Your reminder will arrive on <t:1659992446:F>!
current due date for tox 4 appears to be Oct 1
!remind 17.5H also actually, plz test black with setuptools's experimental standardized editables support
17.5H is not a valid duration string.
!remind 17H also actually, plz test black with setuptools's experimental standardized editables support
Your reminder will arrive on <t:1659988901:F>!
I've been meaning to do this for ages now, but I keep pushing it off
Pretty sure it'll land in main in a few days, so I better stop procrastinating
I honestly thought that it would have already been in main by this time
hmm.
there are released betas for tox 4 and I see one of the maintainers has been using tox 4 in prod for a long while
huge rewrites are daunting so I can't blame them for not having a set date, just kinda annoying since I want to make a decision on how to improve black's devtooling soon haha
I'll figure out, eventually -- it's like 11:09 PM right now so definitely ain't working on this today
<!--
Please make sure that the bug is not already fixed either in newer versions or the
current development version. To confirm this, you have three options:
- Update Black's version if a newer release exists:
pip install -U black - Use the online formatter at , which will use
the latest main branch. - Or run Black on your machine:
- create a new virtualenv (make sure it's the same Python version);
- clone this repository;
- run
pip install -e .[d]; - run `...
... maybe we should add a FAQ entry about this ๐ค
I doubt anyone will read it
anything short of a pinned issue probably won't be effective
Here's your reminder: also actually, plz test black with setuptools's experimental standardized editables support
[Jump back to when you created the reminder](#black-formatter message)
Here's your reminder: look into tox 4 if you're bored and have nothing else to do
[Jump back to when you created the reminder](#black-formatter message)
I'm pretty sure I'm being reasonable here but I'm not quite sure: https://stackoverflow.com/questions/73247204/black-not-respecting-extend-exclude-in-pyproject-toml
I don't agree this is a short-coming of Black. There's no way we'd be able to reliably know when a file given on the command line is from a human or an integration/IDE (and then decide whether to enforce --exclude/--include or not)
You say that it needs to piped in, I guess passing force exclude to cli doesn't override the settings from configs and just extends it then?
oh that's a good point
they could just configure vscode to pass --force-exclude and leave pyproject.toml aloone
lol I somehow missed that
coolio, time to rewrite my entire comment
I can't say that I tried it so you might want to check
Black doesn't do any per option extending between file configuration and the CLI
I feel like an idiot :)
I think I got it finally right now https://stackoverflow.com/a/73296261/18155471
I included your helpful tip about temporarily clearing --force-exclude on the command line
(watch me miss something else obvious ๐ฆ )
Looks great
Are we sure force exclude with an empty will work properly actually
Isn't it like a regex
--force-exclude $^`?
It wouldn't be invalid, just wondered if it wouldn't cause it to match all
I was actually checking how --stdin-filename interacts with all of this at the same time haha
$ black test.py --check -v
Identified `/home/ichard26/programming/misc/c-development/masml` as project root containing a .git directory.
Sources to be formatted: "test.py"
Using configuration from project root.
test.py ignored: matches the --force-exclude regular expression
No Python files are present to be formatted. Nothing to do ๐ด
~/programming/misc/c-development/masml on main [$?] via v3.8.5 took 330ms
$ black test.py --check -v --force-exclude=''
Identified `/home/ichard26/programming/misc/c-development/masml` as project root containing a .git directory.
Sources to be formatted: "test.py"
Using configuration from project root.
would reformat test.py
Oh no! ๐ฅ ๐ ๐ฅ
1 file would be reformatted.
nah, it just disables it as if it was never configured anywhere
That also works
https://github.com/ichard26/ichard26.github.io/discussions/4 first question from someone who read my mypyc blog series (that wasn't pydis staff since I've promoted it to them many times over while writing it haha)
Took a surprisingly long time but I guess I do make it hard to contact me :)
hey guys! i made a PR some days ago (https://github.com/psf/black/pull/3208): tests passed locally but the pipeline failed. How can I test local changes more thoroughly to be sure to submit a valuable PR?
run tox -e py I think? to be honest I'm not really sure myself either
it's an interesting failure case though
3.6 and 3.7 are all failing across all OSes, but only 3.8+ windows is failing
Yup, I noticed
I'm not sure if comparing stringified filepaths is a robust enough way of handling paths, but I haven't looked into this issue yet
don't feel bad about CI failing on your PR, that's what CI is for
Ok! thanks for the advice
yes I agree that was too naive, I will think of something better ๐
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.
Fixes #3207
Man you work fast :eyes: Thank you for all of your contributions to Black lately, I really appreciate it :)
6064a43 Use debug f-strings for feature detection (#3215) - hauntsaninja
Gosh, the file collection logic is soooooo confusing.
โฏ cat ../tester.py | black - --stdin-filename ../tester.py -v --check
Identified `/` as project root containing a file system root.
Sources to be formatted: "home/ichard26/programming/oss/black/-"
Using configuration from project root.
would reformat ../tester.py
Oh no! ๐ฅ ๐ ๐ฅ
1 file would be reformatted.
that sources line doesn't seem right testing your PR locally @elder tusk
From a purity standpoint I'd prefer testing main (although I say that and it'd probably involve mocking), but it's probably just easier to refactor find_project_root. All of the file collection and discovery logic is quite messy already ยฏ_(ใ)_/ยฏ
I'm going to head out for a few hours soon, but I wanted to share my initial comments before I forget.
Description
Resolves #3195
Checklist - did you ...
- [x] Add a CHANGELOG entry if necessary?
- [x] Add / update tests if necessary?
- [x] Add new / update outdated documentation?
that's a good point. "-" was being treated as a path before my PR, but this is one of the places you notice it
for example, on main:
~/dev/black/docs main ฮป cat conf.py | black --stdin-filename "outside.py" -vvv --check -
Identified `/Users/shantanu/dev/black` as project root containing a .git directory.
Sources to be formatted: "docs/-"
Using configuration from project root.
outside.py already well formatted, good job.
All done! โจ ๐ฐ โจ
1 file would be left unchanged.
where obviously "docs/-" is nothign
i pushed a quick fix for it to my branch
but yeah, the verbose reporting of "sources to be formatted" is very coupled to the get_sources logic, so ideally we'd move that log into there.
Hey thanks for filing a PR, I really appreciate it :black_heart:
The PR looks pretty good, got a few minor suggestions. I would've also suggested adding a testcase that verifies the preview style was actually enabled by using input that's only changed under the preview style, however, the test would have to be changed in 2023 when we promote many changes in preview to stable. Sooo it's probably fine to not have a test, but I just wanted to make sure we thought this through.
Out of curiosity, are there plans to include (optional) hard checks for type hints during declarations, function args, return types, etc.? Granted, it wouldn't be that easy to extrapolate what the var should be hinted to, but could at the very least the black process return an error if it finds places that aren't hinted?
i dont work on black but i think thats a job for another tool like mypy or pyright
Perhaps. Do those tools already offer such functionality?
Thank you
Alright, I've also found pytype and pyre-check. Apparently it's called "Strict mode" at some of these, so that settles it
Hey can anyone tell me how to make a discord bot using python?
Wrong channel, maybe #discord-bots ?
There is also a flake8 plugin that does exactly this - flake8-annotations
it makes the lint job fail if it finds missing annotations, and is fairly configurable in terms of which cases are acceptable (e.g. special methods, private methods, etc)
Checked it out, it seems to be only for checking function signatures, as per its first readme paragraph:
What this won't do: Check variable annotations (see: PEP 526), respect stub files, or replace mypy.
yes, it finds parameters lacking type annotations
ah, sorry, I was only considering the last part of your message:
could [...] the black process return an error if it finds places that aren't hinted?
checking the correctness of annotations & type safety is a job for type checkers such as mypy or pyright; it is beyond the scope of formatters or linters
Indeed, Black will never be a linter or type checker. That is simply out of scope for the project.
Black's architecture isn't even well suited as a linter, Black doesn't operate under a "find style violations in code -> fix them" model, it more normalizes code (specifically the CST metadata like spacing and parenthesizes) to follow the Black code style.
I'll merge this in around 24 hours if no one yelps any objections. @Mogost feel free to add yourself to the AUTHORS list, either way thank you very much! Any feedback on your experience contributing here is welcome here: #2238.
<!--
Please make sure that the bug is not already fixed either in newer versions or the
current development version. To confirm this, you have three options:
- Update Black's version if a newer release exists:
pip install -U black - Use the online formatter at , which will use
the latest main branch. - Or run Black on your machine:
- create a new virtualenv (make sure it's the same Python version);
- clone this repository;
- run
pip install -e .[d]; - run `...
well my laptop has been taken hostage by windows update so I can't even debug the above issue if I wanted to
Description
Fixes #3124
The logic implemented is as follows:
- If
target_versionis specified in thepyproject.toml, we ignore the project metadata. - If it is not specified, we try to read and parse the project metadata to determine a valid minimum
TargetVersion. If we fail for whatever reason, we continue without atarget_version. - The target version should be the major version of the minimum Python version allowed by the
requires-pythonspecifier.- `>=3....
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
In general, given that black uses mypyc, feels like you should probably start from strict and then re-enable any looseness you need. But that can be for later.
I agree :+1:
Misclicked :upside_down_face:
07b68e2 add preview option support for blackd (#3217) - Mogost
Looks good, one small nit
e7b9671 Port & upstream mypyc wheel build workflow (#3... - ichard26
nice!
to be honest, I was kinda hoping to see @neon loom get surprised by this step :) https://github.com/ichard26/black/blob/8a21bac441842da63f14a2be8466422d838102e1/.github/workflows/pypi_upload.yml#L73-L76
.github/workflows/pypi_upload.yml lines 73 to 76
- name: Upload wheels to PyPI via Twine
env:
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: pipx run twine upload --verbose -u '__token__' wheelhouse/*.whl```
@bright glacier any other PRs you'd like me to take a look at?
I wager pipx being pre-installed is not something he knew.
https://github.com/psf/black/pull/3219 is a major enough change (it adds a dependency on packaging) I'd appreciate more eyes on it, but I can do the preliminary review first. mypyc is failing due to a very lax return type annotation in packaging.
Once I fix diff-shades by working around a mypyc bug, I'll put https://github.com/psf/black/pull/3211 up for review, but honestly I might just merge it without review since impact should be low.
Description
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.reform...
https://github.com/psf/black/pull/2996 is still awaiting a decision on whether the style change is a good idea or no. The implementation is good to go though.
I was going to comment on psf/black#3198 with pointers for the author to include a proper mitigation (ran out of time and I forgot about it), but yes in its current state it should not be merged.
oh yeah, we probably don't need that global anyway
I wonder if the os.cpu_count() thing is slow on different OSes
as long black.concurrency is only imported when reformat_many is about to be called, uvloop will be imported without impacting users using black as a library
wow on linux it's even faster than my mac ```In [9]: %timeit os.cpu_count()
68.6 ns ยฑ 0.106 ns per loop (mean ยฑ std. dev. of 7 runs, 10,000,000 loops each)
technically anyone who calls black.main inline will see uvloop installed but that probably is not something we need to concern ourselves with?
import black
black.main([args, ...], standalone_mode=False)
If you're calling black.main, you're effectively handing off control to black and we reserve the rights to change the global environment as we need to
There's a non zero chance so I'll wrap it in a lru_cache decorated function.
Doesn't really hurt.
I half expect it to take like a second on Windows
Haha, I was thinking the same thing.
I'd be surprised if Python has to call some subprocess or external script to get the CPU count (as like with some other platform/system metadata functions in sys) but OSes have weird limitations ยฏ_(ใ)_/ยฏ
Yeah no clue โฆ kinda cool
Describe the style change
Examples in the current Black style
def f():
"Make sure this code is blackened"""
pass
Desired style
def f(
):
pass
Additional context
good morning folks! ๐ค๏ธ
actually we pass the CPU count as the default for --workers so we were already paying the syscall cost on startup https://github.com/psf/black/blob/4ebf14d17ed544be893be5706c02116fd8b83b4c/src/black/__init__.py#L374-L381
src/black/__init__.py lines 374 to 381
@click.option(
"-W",
"--workers",
type=click.IntRange(min=1),
default=DEFAULT_WORKERS,
show_default=True,
help="Number of parallel workers",
)```
Is it worth changing the default to be None so we can avoid calling os.cpu_count()?
More work is happening on https://github.com/psf/black/pull/3160 that's cool
yeah, lots of tiny commits so my inbox has been getting spammed :(
actually I will since this doesn't handle the case where os.cpu_count() returns None
or... the type hint is just plain wrong
I don't know when that can realistically happen, I have looked at the C code before
Lib/concurrent/futures/process.py lines 599 to 603
if max_workers is None:
self._max_workers = os.cpu_count() or 1
if sys.platform == 'win32':
self._max_workers = min(_MAX_WINDOWS_WORKERS,
self._max_workers)```
looks like we can pass None as max_workers to ProcessPoolExecutor
sooo it doesn't even matter if it returns None, we're doing extra work we don't need to
I tried looking at the C code, but I couldn't follow it. I'm just reading the os documentation.
Is black supported in Pycharm/Jetbrains IDEs?
Well I'm a better developer nowadays in the sense I write useful commit messages :p
Thanks!
dammit, I think I lost my changes to the release documentation
I probably accidentally ran a git restore on it
it's really annoying since I had spent a few hours on it
oh my goodness, there's a copy of the release process document with my changes in the sphinx build directory
thank gosh 
wait no, it's actually outdated :(
Fine, I'll rewrite it again.
what?
โฏ python
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = 'python'
isolated = 0
environment = 1
user site = 1
safe_path = 0
import site = 1
is in build tree = 0
stdlib dir = '/usr/local/lib/python3.11'
sys._base_executable = '/home/ichard26/Downloads/Python-3.11.0rc1/debug/python'
sys.base_prefix = '/usr/local'
sys.base_exec_prefix = '/usr/local'
sys.platlibdir = 'lib'
sys.executable = '/home/ichard26/programming/testing/black/3.11venv/bin/python'
sys.prefix = '/usr/local'
sys.exec_prefix = '/usr/local'
sys.path = [
'/usr/local/lib/python311.zip',
'/usr/local/lib/python3.11',
'/usr/local/lib/python3.11/lib-dynload',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007f241654f4c0 (most recent call first):
<no Python frame>
I'm trying to test 3.11rc1 and it's failing to startup. Built it from source with --with-pydebug, not sure what would be wrong :/
using 3.11's venv worked, perhaps virtualenv doesn't support 3.11 yet ยฏ_(ใ)_/ยฏ
aiohttp probably won't support 3.11 for a long time, looks like many things are still broken on their end
well, actually we'll probably have to fallback to aiohttp's pure python installation mode since their Cython sources don't work on 3.11
we need to start testing 3.11 like.. now.
OK, so our test suite passes on 3.11rc1 except for all of the blackd tests since our test setup code is isn't 3.11 compatible...?
oh, aiohttp's AioHTTPTestCase seems broken on 3.11
that might be a known issue, there were some bugs reported around IsolatedAsyncioTestCase
looks like pathspec changed the way of installing the project from source as ichard26/black-deps-ci is blowing up
Tell me about black
exactly what though?
Well let's say I have a large API project that I own that passes flake8. How might black offer different advice?
black is a code formatter, not a linter like pylint or flake8
https://black.vercel.app/ there's a demo here
Playground for Black, the uncompromising Python code formatter.
Oh, interesting
Note that we still have:
src/blib2to3/pytree.py
13:# mypy: allow-untyped-defs, allow-incomplete-defs
src/blib2to3/pgen2/tokenize.py
4:# mypy: allow-untyped-defs, allow-untyped-calls
src/blib2to3/pgen2/conv.py
4:# mypy: ignore-errors
I took a solid look at removing those from pytree, but it seems like some of the existing type annotations are lies (e.g. things annotated as _Results can have list values). Do we not compile blib2to3 with mypyc?
Description
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.
Test run: https://github.com/ichard26/black/runs/7831041412?check_suite_focus=true (note that in that run the job runs after the sdist/pure wheel job passes, while in this PR, it runs after all the PyPI jobs finish, I changed it in the test run because I didn't want to wait several minutes for the mypyc jobs to finish)
**Thi...
Black... Did something I think it shouldn't have.
I had a function that returns a list and I needed a static index from that list:
I.e. foo = bar()[1]
Black did this:
foo = bar()[
1
]
it'll only explode out like that if it hits the configured max line length iirc
Yeah that's precisely what happened
Black's output here is known to be subpar
Would link to the many issues that exist but am on phone atm
Thanks
<!--
Please make sure that the bug is not already fixed either in newer versions or the
current development version. To confirm this, you have three options:
- Update Black's version if a newer release exists:
pip install -U black - Use the online formatter at , which will use
the latest main branch. - Or run Black on your machine:
- create a new virtualenv (make sure it's the same Python version);
- clone this repository;
- run
pip install -e .[d]; - run `...
uhhh, cibuildwheel 2.9.0 is just erroring out when trying to build the 3.11rc1 wheels ๐
link to the workflow?
hmm, your x86_64 image is quite old for some reason
things break if it's unpinned though
This is the output I get:
manylinux_images: {'x86_64': 'quay.io/pypa/manylinux2014_x86_64:2022-07-17-51324db', 'i686': 'quay.io/pypa/manylinux2014_i686:2022-07-17-51324db', 'pypy_x86_64': 'quay.io/pypa/manylinux2014_x86_64:2022-07-17-51324db', 'aarch64': 'quay.io/pypa/manylinux2014_aarch64:2022-07-17-51324db', 'ppc64le': 'quay.io/pypa/manylinux2014_ppc64le:2022-07-17-51324db', 's390x': 'quay.io/pypa/manylinux2014_s390x:2022-07-17-51324db', 'pypy_aarch64': 'quay.io/pypa/manylinux2014_aarch64:2022-07-17-51324db', 'pypy_i686': 'quay.io/pypa/manylinux2014_i686:2022-07-17-51324db'}
musllinux_images: {'x86_64': 'quay.io/pypa/musllinux_1_1_x86_64:2022-07-17-51324db', 'i686': 'quay.io/pypa/musllinux_1_1_i686:2022-07-17-51324db', 'aarch64': 'quay.io/pypa/musllinux_1_1_aarch64:2022-07-17-51324db', 'ppc64le': 'quay.io/pypa/musllinux_1_1_ppc64le:2022-07-17-51324db', 's390x': 'quay.io/pypa/musllinux_1_1_s390x:2022-07-17-51324db'}
While yours is:
manylinux_images: {'x86_64': 'quay.io/pypa/manylinux2014_x86_64:2021-11-20-f410d11', 'i686': 'quay.io/pypa/manylinux2014_i686:2022-08-09-51a01be', 'pypy_x86_64': 'quay.io/pypa/manylinux2014_x86_64:2022-08-09-51a01be', 'aarch64': 'quay.io/pypa/manylinux2014_aarch64:2022-08-09-51a01be', 'ppc64le': 'quay.io/pypa/manylinux2014_ppc64le:2022-08-09-51a01be', 's390x': 'quay.io/pypa/manylinux2014_s390x:2022-08-09-51a01be', 'pypy_aarch64': 'quay.io/pypa/manylinux2014_aarch64:2022-08-09-51a01be', 'pypy_i686': 'quay.io/pypa/manylinux2014_i686:2022-08-09-51a01be'}
musllinux_images: {'x86_64': 'quay.io/pypa/musllinux_1_1_x86_64:2022-08-09-51a01be', 'i686': 'quay.io/pypa/musllinux_1_1_i686:2022-08-09-51a01be', 'aarch64': 'quay.io/pypa/musllinux_1_1_aarch64:2022-08-09-51a01be', 'ppc64le': 'quay.io/pypa/musllinux_1_1_ppc64le:2022-08-09-51a01be', 's390x': 'quay.io/pypa/musllinux_1_1_s390x:2022-08-09-51a01be'}
notice the first image
yeah, I doubt you'll be able to get it to build with old version like that
So legally speaking we are violating a whole wack of licenses via our pyinstaller executables by not redistributing the licenses of our dependencies
I'm less sure about this, but the compiled wheels might also violate a license or two as they probably include sources from both CPython and mypyc's C libraries (and maybe even system libraries via auditwheel/delocate???)
For the PyInstaller executables, it's probably a good idea to eventually redistribute licensing information, but how we'd go about that is beyond me since it gets complicated very quickly (hello CPython's many licenses - remember that PyInstaller simply bundles CPython with your application)
Content looks good, so given a consensus on branch > tag we're good to go (I don't see why not if Vim improves, RTD is already meh)
Description
Updated actions.yml to use the alternative $GITHUB_ACTION_PATH variable as documented here 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.
Checklist - did you ...
- [x] Add a CHANGELOG entry if necessary?
- [x] Add / update t...
I'm going to be out for most of today without an internet connection so I'll be pretty unreachable. Just an FYI.
Description
This PR fix the issue where a standalone comment causes strings to be merged into one far too long (and requiring two passes to do so). (Fixes #2734.)
Checklist - did you ...
- [x] Add a CHANGELOG entry if necessary?
- [x] Add / update tests if necessary?
- [x] Add new / update outdated documentation?
Describe the bug
When adding a name to .gitignore and negating a specific directory of that name, black incorrectly ignores the file.
.gitignore
build
!/foo/build
To Reproduce
By running this shell script you should see that git doesn't ignore the file but black does.
#!/usr/bin/env bash
set -e
# Create project directory
TMP_DIR="$(mktemp -d)"
cd "$TMP_DIR"
# Make this a git working copy
git -c init.defaultBranch=main init
# Create .gitig...
<!--
Please make sure that the bug is not already fixed either in newer versions or the
current development version. To confirm this, you have three options:
- Update Black's version if a newer release exists:
pip install -U black - Use the online formatter at , which will use
the latest main branch. - Or run Black on your machine:
- create a new virtualenv (make sure it's the same Python version);
- clone this repository;
- run
pip install -e .[d]; - run `...
Some dependencies are blocking us testing black to make sure we're 100% 3.11 ready. Let work with/around them for now to at least get partial testing into CI.
This issue to to track all the needed fixes to get us there. Will get more detail here are we learn.
Known Issues
- aiohttp for blackd
- Will look at skipping blackd tests for now for 3.11
- mypyc compiling
Step 1: Get partial 3.11 CI running
Step 2: work with dependency projects
Step X: Add back parts to get to ful...
What happened to your internets?
Canada go down again?
Nah, I was just out of the house, Rogers did not suffer another breakage 
That was a crazy outage. I didn't read the fine print, but the number of businesses single homed on them was crazy
(tips network engineer hat)
My house is even dual homed
Yeah I was offline for a whole day
everyone who had bell was totally fine though so that was fun
Only problem is, it's TMobile 5G, and if the one cable provider in my little town goes down, the 5G gets saturated.
Been trying to get ADSL or a WISP link ... but not many options ๐ฆ The bummer of living in the woods
I have a friend on Oakland CA, who has TWO 1/1 gig fibers with ATT and Sonic that take diverse paths for LESS than I pay for my 1 cable connection. lol
Running the latest version of black on MacOS M1 systems fails with the following error:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/bin/black", line 5, in
from black import patched_main
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/black/__init__.cpython-39-darwin.so, 0x0002): tried: '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/black/__init__.c...
No idea why the above is happening.
I've been seeing this with my new m2 MacBook which I migrated from an intel machine, but it was just fixed by reinstalling in my case
how strange
Oh boy I am one heck of a time debugging https://github.com/mypyc/mypyc/issues/827
I still have no idea what is blowing up even after 20 minutes ๐ฆ
I'll try repro later - Unit tests are eating my brain
And I'm on my x86 Linux box in office + M1 is down stairs. #lifeIshard
Still working on that python SSH thing?
Ya ya, SSH part is all done, just unittesting I'm not putting bad data into the modeling system
What's worse than no data? Incorrect data.
Writing unittests is rarely fun
asyncssh is awesome with uvloop
I still haven't used SSH lol
mypyc's async support is a bit sketchy
it just landed support for async with and async for is still a WIP
Ahh, also, I bet some of it's deps are not strongly typed
Yeah, it hurts my head thinking how they translate that code to C
me too
Been two hours and I've given up now. I learned a lot about the CPython C-API, but I still don't understand enough to feel comfortable writing a solution. I kinda understand why it's crashing now though.
Description
I had issue running Black in vim after recent updates (notably using vim > 9, linked against python 3.10.4), getting error:
TypeError: bool object expected; got int
after some tinkering i found that the values defined (or not) in pyproject.toml were the culprit. But even adding
string_normalization = false
fast = true
quiet = false
in the black block of pyproject.toml, didn't help, as it was trying to convert a...
@bright glacier I can't repro https://github.com/psf/black/issues/3231 (Black install on M1 failing) ... I give them a few days and if no response I'll close
Running the latest version of black on MacOS M1 systems fails with the following error: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.9/bin/black...
I get compiled and all ...
Thanks, it's really odd how these folks are somehow getting the Intel wheels on their ARM systems
I bet they don't update their setuptools + pip
22.3.0 works for them though
I even tried a fresh venv on 3.9, install 22.3.0 and then upgraded to 22.6.0 and it worked
To be fair, it's a horrible issue with 0 info on how to repro
I tried. Now to get some work done so I can get us partially passing 3.11 CI later today ๐
they're using Python 3.9 so unless they're using version older than 3.9.5, they would have new enough pip to install arm64 wheels tbh
@bright glacier Be proud - I even tagged ๐
I expect that too since 22.3.0 works, but don't know if it's installing compiled or not
it must be installing compiled if it fails to import shared library, right
perhaps they're using the pure wheel for 22.3.0 for some reason?
Ya - we don't have 22.3.0 info ๐
lol
not sure how that'd happen, something about weird caching but we don't know
also
https://github.com/psf/black/issues/3111 how the hell are people hitting this?
Installed multiple times on different project. Latest version( 22.3.0) gives the following error when lunched ImportError: cannot import name 'ParameterSource' from 'click.c...
+1 I had
22.3.0but I solved it installingblack-21.4b0
oh god
I mean I know people can install packages that have conflicts with the already installed packages and pip won't error actually, but it will loudly warn
You'd think someone would've noticed that by now
gotta be more aggressive with closing as no repro
It's horrifying what people do when they don't understand what is wrong
because these people don't do good job with presenting their problem
I am proud :D
It amazes me how people call themselves professional programmers but don't learn their language of choice packaging + installing.
It's like a mechanic not knowing what tool to use for different repair jobs.
The author of the issue claims they have click 8.1.2 and black 22.3.0 but I wouldn't be too surprised if that's not the case because black gets imported from different place than click or something like that
/usr/local/lib/python3.9/site-packages already worries me lmao
I see it all @ Meta ... from Data Scientists to CPython core devs using Python ...
I mean in fairness data science is an area where expecting the developers to know their packaging tooling is a bit of a stretch IMO
because it's system-wide and that's always problematic (if you don't know what you're doing anyhow)
If you want to be good ...
I mean, anaconda literally exists to help abstract away packaging from them, you can't blame the IMO
(not sure if anaconda redistributes black but I'm pretty sure they do)
I get it, but still. Not understanding how python packages layout to create your data science code (if they go that route vs. notebooks etc.) should be learnt ...
Yeah we've had issues from them early on - Pretty sure they do
I've NEVER installed a package from anaconda ... lol
I honestly don't really know how to version control notebooks properly
And I've used python for a few years.
but I only really needed to (or well, wanted to) version control notebooks for projects that I needed to do to complete university course
I have only used one notebook, and that was one hosted on GH lol
and that one time when I contributed something to Instagram's Fixit repo which used notebooks for docs
User can't repro anymore ... haha
yeah, way too many issues are filed with terrible reproduction steps (or none at all!)
Background
Hello there! The Python packaging ecosystem has standardized on the interface for build backends (PEP 517/PEP 660) and the format for metadata declaration (PEP 621/PEP 631). As a result, the execution of setup.py files is now deprecated.
So, I'm spending my ...
This is great, I love getting rid of setup.py.
- CI is failing with
rm: cannot remove 'dist': No such file or directory, probably just a matter of removing a line from the script somewhere. - 3.6 removal is tracked in #3169. It's currently planned for January but I wouldn't mind accelerating that a bit.
We should close ones with none at all if we've asked for better repro
Ok - Can confirm, black installs (not blackd) and runs over it's own codebase in 3.11
cooper@home1:~/repos/black$ /tmp/tb/bin/python -V
Python 3.11.0rc1+
cooper@home1:~/repos/black$ /tmp/tb/bin/pip install .
Processing /cesspool/home/cooper/repos/black
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Collecting click>=8.0.0
Using cached click-8.1.3-py3-none-any.whl (96 kB)
Collecting platformdirs>=2
Using cached platformdirs-2.5.2-py3-none-any.whl (14 kB)
Collecting pathspec>=0.9.0
Using cached pathspec-0.9.0-py2.py3-none-any.whl (31 kB)
Collecting mypy-extensions>=0.4.3
Using cached mypy_extensions-0.4.3-py2.py3-none-any.whl (4.5 kB)
Building wheels for collected packages: black
Building wheel for black (pyproject.toml) ... done
Created wheel for black: filename=black-22.6.1.dev33+g4ebf14d-py3-none-any.whl size=158445 sha256=2c0b4b8d25479eb9d8a16d025bee540a3e8fc47062c542bea33ebaaf1fd8ecf7
Stored in directory: /tmp/pip-ephem-wheel-cache-b1r65m6v/wheels/52/83/28/8e56a09ecf908e4805edb77af7846d99f28341e5b6fdd2ed7e
Successfully built black
Installing collected packages: mypy-extensions, platformdirs, pathspec, click, black
Successfully installed black-22.6.1.dev33+g4ebf14d click-8.1.3 mypy-extensions-0.4.3 pathspec-0.9.0 platformdirs-2.5.2
cooper@home1:~/repos/black$ /tmp/tb/bin/black .
All done! โจ ๐ฐ โจ
44 files left unchanged.
tox time
need to make 3.11 not install [d] I guess
- Had to exempt blackd tests for now due to aiohttp
- Skip by using
sys.version_infotuple - aiohttp does not compile in 3.11 yet - refer to #3230
- Skip by using
- Add a deadsnakes ubuntu workflow to run 3.11-dev to ensure we don't regress
- Have it also format ourselves
Test:
tox -e 311
Description
Checklist - did you ...
- [ ] Add a CHANGELOG entry if necessary?
- [ ] Add / update tests if necessary?
- [ ] Add new / update outdated documentation?
Sweet - Passes
oops i thought i was in #bot-commands lol
huh, I completely missed the time you made plans for dropping Python 3.6 support in 22
maybe I should pin the issue
call me surprised
I don't care for Python 3.6 but didn't expect you to do it before 23
not sure what to replace, but I guess the mypyc one since it's unlikely we'll hit more problems
unfortunately the click one is probably never going to be truly over
(unless we abuse the build number for wheels to update the requirement metadata afterthefact)
just remember to bump python_requires when you drop support
one simple trick to prevent the world from going boom
:)
looks like pathspec on master is straight up broken as importing it fails with a circular import error
going to file an issue with them
wait what, cloning it locally it works fine, wat
circular import?
what the hell, importing pathspec works if you're in the repository root
ah, sounds like the packaging setup is producing invalid wheels?
python
Python 3.8.5 (default, Sep 9 2020, 23:45:44)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pathspec
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ichard26/programming/testing/python-path-specification/venv/lib/python3.8/site-packages/pathspec/__init__.py", line 50, in <module>
from . import patterns
ImportError: cannot import name 'patterns' from partially initialized module 'pathspec' (most likely due to a circular import) (/home/ichard26/programming/testing/python-path-specification/venv/lib/python3.8/site-packages/pathspec/__init__.py)
>>>
hmm, that should be importing the package
yeah it's only a problem if you install from a wheel
uhh where is the pathspec.patterns subpackage...? ๐
bad setuptools config after they switched to pyproject.toml?
or a bug in setuptools if the config is right
I guess include doesn't apply to its children? (i.e. doesn't have wildcards affixed?)
yup.
kill it already. i think the only person in the world who still uses 3.6 is Jelle ๐
inb4 it turns out the 4% of downloads on 3.6 is from Quora :p /s
It's probably worth hooking up GitHub Actions CI for pathspec given we depend on it.
I'll do that eventually if no one else gets to it before me.
(they have a travis config, but we all know how travis turned out)
I'm unsure whether Travis CI was ever actually installed on the repo
I can't find a single commit that would have a check on it
there's a configuration, yes
but I don't know if it ever actually ran
I'm setting up github actions CI for them now
you didn't give those other people a lot of time :)
yeah, turns out I really wanted to do some good ol' devops haha :)
โฏ git add .github
The following paths are ignored by one of your .gitignore files:
.github
-what even?
ah
I started watching the pathspec repo since the valid report on black where I told the author to report the issue and they still haven't ;-(
ah of course the test suite is failing on windows cause of backward slashes
typical windows experience :)
you might want to tell them they'll need to go to the actions tab and enable the actions from there
I think they just need to approve the workflows to run since I'm a first-time contributor, no?
I'm pretty sure you can push a workflow file and it'll auto enable workflows
it would show up as such then
yeah but you're doing it in a fork
and I'm actually not entirely sure that auto-enabling is a thing
I recall having mixed experience with that in the past
Describe the bug
Black crashes when "fmt: off/on" is used with "with" expression.
To Reproduce
For example, take this code:
# file.py
def do_something():
# fmt: off
with open('foo') as foo,\
open('bar') as bar:
# fmt: on
raise SomeError()
class SomeError(Exception):
pass
And run it with these arguments:
black file.py
or check in black console online [HERE][ref_console].
The resulting...
I think that error is misleading, it regularly happens when there isn't a circular import involved. I've seen it before but not gotten around to making a CPython issue
In pathspec's case, the intention was to import a submodule but since there wasn't one with that name, the import system tried importing a name from the base module which made it into circular import
It is misleading in this case but in general, I like that Python tells you that you might be running into a circular import issue
so hopefully you wouldn't get rid of it entirely, just make it more descriptive in non-obvious cases
Yes, perhaps the heuristic for when we emit that wording could be improved. I haven't looked at the code though
in this case, I still wouldn't mind having a suggestion that it might be a circular import but I definitely would love it if it said along the lines of lines "there's either no submodule with that name or you attempted a circular import"
basically, anything to make it not misleading while still being helpful
๐
Jeez, I come back to the project after getting sucked into mypyc stuff for several days, aaaaand there's now 37 open PRs ๐
To be honest, I'm not really in the mood to work on Black, but I am release managing this month's release and I still got a few RM tasks to do first.
Will review one or two PRs first and then get back to release stuff today (hopefully ๐ค )
Good point. Would definitely encourage opening an issue about it eventually, better error messages are good.
I really appreciate you filing this PR @ionite34. I always love to remove hacky workarounds :)
Feel free to add yourself to the AUTHORS.md file, otherwise this mostly SGTM other than the changelog entry.
I have no idea what this code does in the first place ๐
Awesome work. Can't say I understand everything here, but either way this logic should've existed in the first place. Thank you so much!
@neon loom do you mind if I push changes to your 3.11 PR? I'd like to try out Jelle's suggestion (to reduce the diff size and avoid unnecessarily ruin git blame) and also try to integrate py311 into the main tox test session (via some session specific conditionals)
Once aiohttp supports 3.11 my hacks go away too and I just add 3.11 to our main test CI โฆ
So is it really worth more effort?
I already knew how I'd clean it up so it didn't take too much effort, I just didn't expect tox to not support our use-case.
commands =
!py311: pip install -e .[d]
py311: pip install -e .
I thought this would've worked, but nope. Anyway I decided to try deduplicating the sessions just so changes are easier to the config (we might to forget to update the 3.11 session for example) in case aiohttp take forever to support 3.11.
Sure. What ever you think is best. We just wanted to prove we work on 3.11 and I thought I achieved that.
I guess tox -e py just doesn't work with tox conditionals as it could be hard getting the python version factor from that
Wait a second, how did the inheritance break things? The test suite should run on 3.11, it's just that the blackd tests fail. Skipping them should avoid failures, no?
The inheritance need aiohttp installed to import
It does not build
Why are we wasting each otherโs time?
Sorry I didn't mean to.
Anyway that question was dumb. I forgot that aiohttp doesn't install (mostly because I hacked it to successfully install on 3.11 by disabling Cython_
Nothing blocking. Just quality of life suggestions really.
Thank you for the PR, I really appreciate it! You are a good maintainer of Black, it's just that your attention is divided elsewhere, and that's OK.
I can't actually test tox -e ci-py311 and make sure it works because my 3.11 install seems to be broken... ? but either way it's a valid session name so it should be fine.
I was curious and wanted to avoid ruining git blame if we could easily avoid it for what it's worth. I guess it doesn't matter anyway since this is all going to be removed eventually ๐
I gave it the 10 mins it was worth considering it would go away
๐ฆ
I'll push a revert. I just need to stop wasting your time.
Sorry about that by the way. I really should've thought it more through.
It's not a big deal, but our industry has a problem with over optimizing things that are not of large benefit for the time it can take.
I try to share the perspective to people is it really worth it - that's all I'm trying to share here.
We are all limited on time
I agree, but like people to spend their limited donated time on impact not perfection ๐
Look, it's just my fault. I don't want to fight about it.
It's just a personal preference and am for people to play with OSS projects etc. if it interests them
doing things you enjoy doesn't always align with doing the impactful things tbh
I do get your point, I just don't necessarily agree with it in the OSS context
๐
Each to their own. All good.
I've just seen to many people burn out on OSS
From doing micro optimizations that were not always huge benefit to all
But if people enjoy it, please.
59acf8a Add passing 3.11 CI by exempting blackd tests (... - cooperlees
21218b6 Fix a string merging/split issue caused by stan... - yilei
is this a black bug? https://github.com/dask/distributed/pull/6920/files#diff-fa07d391e7f82923d61dc0643961fdebcb9c4582e8f826bbc33710c5ae45a380R1390 I don't know how to describe what it did in words to search for it
input is
async def __aexit__(self, exc_type, exc_value, traceback):
await self._close(
# if we're handling an exception, we assume that it's more
# important to deliver that exception than shutdown gracefully.
fast=exc_type is not None
)
output is
async def __aexit__(self, exc_type, exc_value, traceback):
await self._close(
# if we're handling an exception, we assume that it's more
# important to deliver that exception than shutdown gracefully.
fast=exc_type
is not None
)
this one maybe? https://github.com/psf/black/issues/2593
or one of the issues that are linked in it
It seems likely it's related
run-dunders.test:339: error: Unsupported left operand type for + (<nothing>)
run-dunders.test:339: error: Argument 1 to "abs" has incompatible type "int"; expected "__SupportsAbs[<nothing>]"
working with mypyc's test suite is really painful due to the limited builtins/typing stubs, ugh I don't understand what's wrong here
the second error looks more tractable I guess
but yeah 90% of weird mypy test suite issues are due to fixtures
--- a/mypyc/test-data/fixtures/ir.py
+++ b/mypyc/test-data/fixtures/ir.py
@@ -3,7 +3,7 @@
from typing import (
TypeVar, Generic, List, Iterator, Iterable, Dict, Optional, Tuple, Any, Set,
- overload, Mapping, Union, Callable, Sequence, FrozenSet
+ overload, Mapping, Union, Callable, Sequence, FrozenSet, Protocol
)
T = TypeVar('T')
@@ -12,6 +12,10 @@ S = TypeVar('S')
K = TypeVar('K') # for keys in mapping
V = TypeVar('V') # for values in mapping
+class SupportsAbs(Protocol[T_co]):
+ def __abs__(self) -> T_co: pass
+
+
class object:
def __init__(self) -> None: pass
def __eq__(self, x: object) -> bool: pass
@@ -308,7 +312,7 @@ def zip(x: Iterable[T], y: Iterable[S]) -> Iterator[Tuple[T, S]]: ...
@overload
def zip(x: Iterable[T], y: Iterable[S], z: Iterable[V]) -> Iterator[Tuple[T, S, V]]: ...
def eval(e: str) -> Any: ...
-def abs(x: float) -> float: ...
+def abs(x: SupportsAbs[T]) -> T: ...
def exit() -> None: ...
def min(x: T, y: T) -> T: ...
def max(x: T, y: T) -> T: ...
Kind of hacky defining a typing name in a builtins stub but there's not really anywhere else that'd be less painful (since by default this stub uses the limited typing stub from mypy). Not that this works anyway.
does int have __abs__ in this fixture?
of course not
will add to int/float
OK that finally worked. I forgot that int/float were also defined in this stub. Thanks for the pointer!
i get a segfault error when i run a .so file compiled with mypyc, how can i see why it segfaulted?
use a debugger like gdb
or look at a core dump
thank you
how do you manage dupes on your issue tracker?
like it seems black is prone to a bunch of indescribable or uname-able behaviors with a many to one relationship to bug fix
most of the stuff I find are "black did this and I don't like it and don't know why"
I have tried to reduce them by adding precise labels and closing ones that seem to describe the same behavior
Could do more though
it seems like naming the issue is like 80% of the work and the bug fix is the other 80%
thanks for your work on that, it seems like an impossible job to me!
Yeah, you do get better with time at discerning what behaviours seem similar/related. It takes lots of time though so that's we rarely do issue tracker cleanups.
It's expected there are duplicates, it's not the easiest thing in the world to constantly keep track on the hundreds of issues.
When a new issue is filed, if we already know that it's a duplicate of something else (and we know what to search for so we can find the original issue) then we'll usually try to dedupe immediately, but otherwise, they're left until we do another issue tracker cleanup.
failed to do it rip
are you running into a segfault with mypyc black? or mypyc in general?
my understanding is that to do that you first run black and if its fine, mypyc?
or is that not the case? if its not then i guess mypyc in general
??? I'm asking if Black is segfaulting for you.
It wasn't clear in your original message whether you were compiling your own code with mypyc or were using black (that is compiled with mypyc)
oh, mypyc sorry
So you're compiling your own code with mypyc? black is not segfaulting?
thats correct
OK good, because this channel is meant for the black formatter project so I'd be concerned if black was crashing ๐
oops, sorry, which channel is appropiate?
This place ends up involving mypyc chatter though because we use mypyc to compile black and I contribute to mypyc
#c-extensions maybe?
yeah thats why i had come here since this seem the place with the most mypyc chatter
I haven't found a good place to talk about mypyc so I'm just abusing this channel to be honest ๐
mypy in general used to have a gitter instance, but it got merged into python/typing so I doubt mypyc would be welcome there
that's what i came here for, i think i had tried asking for help in #c-extensions in the past w mypyc and never got it so i was like welp ok
Yeah, people familiar with mypyc are still hard to find since there's not really a designated place for them.
If you want to grab an OT channel, I can try to help you out with your issue since I'm fairly familiar with mypyc.
(a help channel works too, doesn't really matter, it's still Python after all ๐ )
I guess the best-ish place right now is the mypyc issue tracker (https://github.com/mypyc/mypyc/issues) but it's not really designed for support requests ๐ฆ
I mean, there's a lot of hacks involved :)
dataclasses support is really a hack which is why it's so painful to use them in black as mypyc doesn't have good support for them
what's so hacky about it?
mypyc/lib-rt/misc_ops.c line 336
CPyDataclass_SleightOfHand(PyObject *dataclass_dec, PyObject *tp,```
SleightOfHand
oh.
since we compile classes into native classes (and change how the attributes work) we have to edit the type object on the fly to pretend it's more like a regular Python class, pass that to the dataclass decorator and then reapply the actual attributes
oh i see
The more robust solution is to compile away the dataclass decorator entirely and reimplement all of the fields and methods the decorator attaches.
That's a pretty large task though.
oh i kind of assumed mypyc maintained (at least part of) it's own copy of the stdlib
so it could make things work nicer
i will do that later today
We don't really. We do provide a lot of native C implementations of many builtins functions and methods (for certain types) aka primitives, but we don't maintain any copies of the stdlib
ah
solving issue https://github.com/psf/black/issues/2598
Description
at the moment the gitignore file in the initial target directory provided as first argment is ignored (see issue solving issue https://github.com/psf/black/issues/2598).
Checklist - did you ...
- [ ] Add a CHANGELOG entry if necessary?
- [ ] Add / update tests if necessary?
- [ ] Add new / update outdated documentation?
got around to adding a test for https://github.com/psf/black/pull/3216 (had to move around some logic to make it testable)
thank you! will take a look today or tomorrow
also mentioning https://github.com/psf/black/pull/3162 is ready to review again in case this is missed (no rush!)
I saw the gh email, I promise :)
I've just been focusing my OSS energy on other matters right now, I just finished the draft rewrite of the release process documentation: https://ichard26-testblackdocs.readthedocs.io/en/overhaul-release-doc/contributing/release_process.html
Getting this ^^ merged along with the autoupdate stable branch PR is everything that I personally need to handle before I can cut a release.
One thing I am nervous about is that the instructions may be too explicit/detailed, that it makes releasing black seem like an involved and scary endeavor when it really isn't (especially after all of the recent work on the release CD).
Describe the style change
Examples in the current Black style
init >> prepare[0], prepare[
-1
] >> approve >> fork >> branch_start, branch_end >> join >> done
Desired style
init >> prepare[0], prepare[-1] >> approve >> fork >> branch_start, branch_end >> join >> done
Additional context
Actually I've no idea why prepare[-1] was formatted and prepare[0] not. Is there an option to avoid this kind of for...
Describe the bug
Trailing commas are incorrectly being ruthlessly collapsed into one line
To Reproduce
Reproes in the black playground
def method(
self,
) -> typing_extensions.Literal[
"l1",
"l2",
]: pass
Result is
def method(
self,
) -> typing_extensions.Literal["l1", "l2",]:
pass
Expected behavior
I'd expect no change to the Literal writeout.
Environment
Black 22.6.0 in the black playground...
poopfart
Hey All! Stubled upon this, hope this is still relevant
error: cannot format [ommited]/pyqtgraph/widgets/TreeWidget.py:
INTERNAL ERROR: Black produced different code on the second pass of the formatter. Please report a bug on https://github.com/psf/black/issues. This diff might be helpful: /tmp/blk_c76gbp19.log
This version produced the error:
python3 -mblack --version
__main__.py, version 20.8b1
This version handles it fine:
black, 22.3.0 (compiled: ye...
@grizzled vessel fwiw do you want to add yourself to the AUTHORS list in your PR? If not, I'll remove the changelog entry as it's unnecessary and merge.
The amount of changes diff-shades reports for this PR scares me, especially since I'm not entirely sure if it's really an improvement in situations like these:
--- a/warehouse:warehouse/packaging/services.py
+++ b/warehouse:warehouse/packaging/services.py
@@ -33,13 +33,15 @@
# This class should not be used in production, it's trivial for it to
# be used to read arbitrary files from the disk. It is intended ONLY
# for local development with trusted use...
Yeah you can just remove the changelog entry
I thought I had to do it since it was in the PR template ๐
Glad the change worked though 
@dense jungle
@@ -17,12 +14,16 @@
"for safely locating files on disk.",
InsecureStorageWarning,
)
d = {
- "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.LimitOffsetPagination a",
+ "DEFAULT_PAGINATION_CLASS": (
+ "rest_framework.pagination.LimitOffsetPagination a"
+ ),
}
{
- "x": "some aaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaa"
- "long string aaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaa",
+ "x": (
+ "some aaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaa"
+ "long string aaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaa"
+ ),
}
looks like we already wrap multiline strings as dictionary values on main? (with --preview only mind you)
Obviously there's still the problem of strings that can't be broken up by having no spaces, but that's psf/black#413
oh good, I do kind of remember that change
Reading your comment I thought "we must've already fixed this, no?" and apparently we did although I have no recollection of the PR ๐
Apparently we fixed this before 22.1.0 ยฏ_(ใ)_/ยฏ
maybe the original ESP PR changed this?
I'd try bisecting but testing anything older than 20.8b1 is pretty annoying. Anyway 20.8b1 also wraps the string so it's probably the original ESP PR
Awesome work, thank you! I pushed a change to your test since it wasn't actually testing the buggy behaviour due to how the find_project_root function works.
c47b91f Fix misdetection of project root with `--stdin-... - hauntsaninja
Describe the style change
There are some situations in which lists and tuples have equivalent semantics, which presents an opportunity for standardisation. Tuples should be marginally faster.
Examples in the current Black style
for p in [2, 3, 5]:
...
[f(x) for x in [1, 4, 3]]
if size in ["med", "big"]:
...
for p in (2, 3, 5):
...
[f(x) for x in (1, 4, 3)]
if size in ("med", "big"):
...
Desired style
for p in (2,...
Yeah, I don't think this is happening ...
spoiler alert, the compiler does it for you
(so does mypyc, actually it converts it into a series of == / != checks bypassing the tuple/list overhead entirely)
!eval
import dis
dis.dis("x in [1, 2, 4]")
dis.dis("x in (1, 2, 4)")
@bright glacier :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | 0 0 RESUME 0
002 |
003 | 1 2 LOAD_NAME 0 (x)
004 | 4 LOAD_CONST 0 ((1, 2, 4))
005 | 6 CONTAINS_OP 0
006 | 8 RETURN_VALUE
007 | 0 0 RESUME 0
008 |
009 | 1 2 LOAD_NAME 0 (x)
010 | 4 LOAD_CONST 0 ((1, 2, 4))
011 | 6 CONTAINS_OP 0
... (truncated - too many lines)
Full output: https://paste.pythondiscord.com/cibugibuga.txt?noredirect
TIL, I didn't actually know it did this. I knew CPython did this for set literals (converting them to frozenset constants) but the thought it also works for other collection literals didn't occur to me :)
STGM, thank you for all of your work helping to migrate OSS projects to mypy post --strict-optional being on by default! Will ask @JelleZijlstra for a lookover though as I'm no pro at typing.
Hey!
It's incredible how we managed to miss this simple error for so long. Great to see it fixed finally ahaha. Would you mind adding a changelog entry (in CHANGES.md) and writing a test case for this (you'd put it under TestFileCollection, see its other cases as examples) so we won't regress on this? If not, no worries, I'm happy to do these things for you.
Also, FYI I updated y...
Description
- Formalise release cadence guidelines
- Overhaul release steps to be easier to follow and more thorough
- Reorder changelog template to something more sensible
- Update release automation docs to reflect recent improvements (notably the addition of in-repo mypyc wheel builds)
Review notes
See https://ichard26-testblackdocs.readthedocs.io/en/overhaul-release-doc/contributing/release_process.html for a preview of this newly rewritten document.
@felix-hilden g...
Nicely done! I thought about reducing detail in some sections, but ya know what, those that don't need hand holding will just skip it! And it's easier on memory as well.
Ugh, turns out converting these square brackets to parentheses is not an AST-safe transformation:
for [x,] in points:
pass
This makes the removal of unnecessary brackets for unpacking/extended assignments a bit tricky since maybe_make_parens_invisible_in_atom is not designed to handle square brackets
For for statements, it's not too bad, no one would be using square brackets like this anyway, but I've seen square brackets in regular unpacking assignment statements before so yeah, psf/black#3203 is going to involve shuffling around of pre-existing logic.
On the bright side, I can probably submit my patch for psf/black#3080 since scope-creeping it to include square brackets and regular unpacking assignment statements turns out to be not trivial.
Description
Fixes #3080.
What remains is removing unnecessary brackets because yes, you can do this:
for [x, y] in points:
print("this is valid code!!!")
I'm leaving this as a future task because it turns out simply converting these square brackets into parentheses is not an AST-safe transformation. And maybe_make_parens_invisible_in_atom is currently not designed to handle square brackets and initial attempts to add a boolean `treat_square_brackets_as_p...
My gosh, what I thought would be an easy patch took way too much time and energy. Way too much frustration, grr.
What is the point of the stable tag/branch anyway? Do people use it?
yeah our vim integration / github action docs currently suggest it as an option
not sure what else depends on it, but I'm going to assume lots given it's been there for a long now
.github/workflows/linters.yml line 62
uses: psf/black@stable```
I suppose now we can't get rid of it without breaking a lot of users
It'd be nice to get rid of it, but it's old history now. Might as well automate it I guess.
Thanks! I wouldn't worry about square brackets; that's a different and more rarely used syntax that we can handle later if we choose to make more AST-unsafe changes.
Thanks! all sounds great to me.
I don't know if it fits here, but maybe a link to something that tells us how to debug cibuildwheel compiling failures might be handy too. But it's scope creep.
Is your feature request related to a problem? Please describe.
I am currently using autopep8 to format the code in a repository and would like to gradually migrate only a part of the code to black formatting. In order to do this easily, I would like to be able to ignore selectively individual files by adding a comment at the top of the file I want to ignore. I can use "# fmt: off" but then this disables autopep8 formatting as well, while I would like to be able to disable only black an...
Aww, more docstring processing is coming
Guess that's what I get for choosing an opinionated formatter, huh? :P
How much of that do you plan btw
psf/black#2885 I know of
question about https://github.com/psf/black/issues/1352
i have a ~200 lines of patch that actually implements the functionality to restrict the formatting given a list of line ranges, mostly leveraging the existing # fmt: on/off logic (that's also why i sent a few PRs fixing some bugs related to fmt off ๐ )
are you interested in supporting this in black? i haven't done research what the actual interface will be, i.e. how editors/IDEs and git will give black the list of line ranges to format.
The existing example pyproject.toml has the extend-exclude options commented out, so the syntax isn't correct. It's possible that it's self-evident to others, but I have not been able to wrap my head around the proper way to do it. It appears that it does not work like the include option.
Here's what mine looks like right now, but returns:
Error: Invalid value for '--extend-exclude': Not a valid regular expression: nothing to repeat at position 0
[tool.black]
include ...
!eval
#pass the cutty
from random import randint, choice
#probability pool based on real world data
pool = []
pool.append("Mega")
for x in range(7): pool.append("Purple")
for x in range(22): pool.append("Cuteson")
for x in range(90): pool.append("Cutty")
pool.append("Little")
legend = {"Cutty": 1,
"Cuteson": 5,
"Purple": 15,
"Little": 25,
"Mega": 40}
totalpoints = 0
def roll_cutty():
global totalpoints
points = 0
while True:
rollq = input("Roll? ")
if rollq == "y":
pass
else:
totalpoints += points
print(f"you gained {points} points")
print(f"you now have {totalpoints} points")
break
if randint(1,200) == 122:
print("Cuteout: back to zero!")
points = 0
rolls = [choice(pool),choice(pool)]
print(f"You got a {rolls[0]} and a {rolls[1]}")
total = 0
if rolls[0] == "Cutty" and rolls[1] == "Cutty" and randint(1,4) == 1:
print("You rolled 2 Cuttys, but they were opposite! Lost all points!")
points = 0
print(f"You now have {points} potential points")
break
else:
for x in rolls:
points += legend[x]
total += legend[x]
print(f"+{total} points!")
print(f"You now have {points} potential points")
while True:
roll_cutty()
@cinder elm :x: Your 3.10 eval job has completed with return code 1.
001 | Roll? Traceback (most recent call last):
002 | File "<string>", line 54, in <module>
003 | File "<string>", line 25, in roll_cutty
004 | EOFError: EOF when reading a line
Wow the current .gitignore tests suck, they're barely testing anything.
Nevermind, apparently the autocomplete for vim in fish hides .gitignore files >.<
It's so nice when you can use the file collection test case helper I made a while ago. So easy to write a test case:
def test_nested_gitignore_directly_in_source_directory(self) -> None:
# https://github.com/psf/black/issues/2598
path = Path(DATA_DIR / "nested_gitignore_tests")
src = Path(path / "root" / "child")
expected = [src / "a.py", src / "c.py"]
assert_collected_sources([src], expected)
Description
Closes #2560.
This should get a label to silence the CHANGELOG entry check.
Adds documentation to the Future Style guide which advises the user to consider using contextlib.ExitStack() as opposed to large number of context managers following the with statement. For example, as in the Issue,
with contextlib.ExitStack() as exit_stack:
cm1 = exit_stack.enter_context(make_context_manager(1))
cm2 = exit_stack.enter_context(make_cont...
Hey thanks for the PR, I appreciate it! It's nice seeing a new face around here :)
Please fix the linter failures and replace the hardcoded URL with a Sphinx cross-reference so we shouldn't have to change the link in the future.
Thanks, y'all, for being so friendly to beginners!
A while ago I promised to contribute (#black-formatter message) and I am finally getting into it with the above PR.
I made OSS contributions one of my goals at my job, so I actually have the time to do this more now! :']
I'm trying my best to make contributing to black as smooth as an experience it reasonably can be, thanks :)
I've tried to make PRs into some other open-source things (without much, if any, traction or interaction) and I was surprised at how fast and reasonable this was . :'']
There is a reason why we mark documentation issues as good first issues, they're relatively easy haha
You got pretty lucky with my response time since I was already reviewing another PR so I was already around to do another one. Although in general for documentation PRs, we are pretty fast since they are usually simple.
Haha, yeah, I expected like, a week response time. :''] Also, do I need to do anything else for this to get merged, or will y'all take care of that?
You're good, it's on us to press the green button that does the merge ^^
Bah, of course I missed a grammatical issue. This is why I don't merge any significant documentation changes without Jelle looking over it, I'm awful at English proofreading apparently.
OK, https://github.com/psf/black/releases/tag/22.8.0 has been cut. Release workflows have triggered.
22.8.0 has been cut, let the planning for 22.9.0 begin!
Please use/see the associated milestone for what should ideally be done. Suggestions are welcome in this thread.
I'll note that this release we are planning to remove Python 3.6 runtime support and switch to Hatch. I plan to handle that myself, but this is a somewhat major change hence the mention. I will not be the RM for this release, I need a bit of a break for the time being.
The release process for 22.8.0 is now officially done.
Almost everything went smoothly, except for the native macOS executable build. I broke it ๐ psf/black#3250
oh dear gosh you're right haha
that would've been pretty embarrassing if it was September in UTC time
it's September in Poland for almost 2 hours now
So I'm late in ลukasz time, great 
hello people i am new to python
so can anyone teach me python in deep
i am at looping
Description
This change updates the message returned when Jupyter dependencies are not installed, so that it contains syntax corresponding to the platform.
Previously, attempting to apply black formatting to an ipynb notebook without black[jupyter] installed always returned the hint to run pip install black[jupyter]. This command does not work on Ubuntu with python3.
With this change, in the same scenario, the hint is pip install 'black[jupyter]' if "linux" is in the platfo...
this channel isn't for general questions
Yes your will to learn
<!--
Please make sure that the bug is not already fixed either in newer versions or the
current development version. To confirm this, you have three options:
- Update Black's version if a newer release exists:
pip install -U black - Use the online formatter at , which will use
the latest main branch. - Or run Black on your machine:
- create a new virtualenv (make sure it's the same Python version);
- clone this repository;
- run
pip install -e .[d]; - run `...
Describe the bug
When using black and virtualenv, black try to reformat entire virtual env folder, which cause heavy process execution and hang very long.
To Reproduce
For example, take this code:
mkdir myfolder
cd myfolder
virtualenv env
source env/bin/activate
pip install black
pip list
Package Version
----------------- -------
black 22.8.0
click 8.1.3
mypy-extensions 0.4.3
pathspec 0.10.0
pip ...
For the record, I used to name my virtual environments env , but I stopped a long while ago.
any reason to not ask upstream to yank pathspec 10.0.0 @dense jungle ?
looks pretty serious from the upstream bug report
can't hurt
Will do so then, I've contributed to the repository before so this should be friendly ๐ค
thanks!
I guess I'm just to used to the Python world. I wouldn't think to use env in a Python codebase, but now I think about it, could see it being used.
Would be a reasonable subpackage name for one
I use .venvs which is somewhat problematic to some tools as well ๐ Partially resolved by putting gitignore in the directory + in global gitignore but not all tools necessarily adhere to it. And then there's flake8 that doesn't even have the common venv or .venv in default excludes :/