#black-formatter
1 messages Β· Page 16 of 1
you're doing awesome work, writing docs isn't as pleasant as coding (at least for me) and doesn't give immediate feedback but it can help the project a lot in the long run so it's good to see someone puts work into it :)
@bright glacier I was looking at https://github.com/psf/black/issues/2351 and https://github.com/psf/black/issues/2359, do you happen to know what kind of formatting issue in .gitignore caused this exception? I have hard time reproducing it. Thanks.
We've found two patterns that reproduce the bug, a line with just a \ or a ! will do the trick.
I guess we should report a bug to the gitignore parsing library we're using. In Black we can just try-except the exception produced and print that the gitignore is invalid
@dense jungle We found the bug in the original parsing library, we're doing a little open source contributing session at work (Ordina Pythoneers), so we're going to open a PR to fix it at the upstream library.
Great! We might still want the try-except in Black for people using an old version of the library
Alright
Hello π
Quick question - what do --run-optional no_python2 and --run-optional python2 do? I just tried both of them, and it seems to me that they collect the same tests:
$ pytest tests/test_black.py --collect-only
116 tests collected in 0.19s
$ pytest tests/test_black.py --collect-only --run-optional python2
116 tests collected in 0.15s
$ pytest tests/test_black.py --collect-only --run-optional no_python2
116 tests collected in 0.13s
They collect the same number
But different tests (edit: are run)
Look for ones marked with
@pytest.mark.(no_)python2
(The python2 ones install the extra)
Are you sure? It seems to me that both are collecting test_docstring_reformat_for_py27, even though it's marked @pytest.mark.python2:
$ pytest tests/test_black.py --collect-only --run-optional python2 | grep test_docstring_reformat_for_py27
<TestCaseFunction test_docstring_reformat_for_py27>
$ pytest tests/test_black.py --collect-only --run-optional no_python2 | grep test_docstring_reformat_for_py27
<TestCaseFunction test_docstring_reformat_for_py27>
Interesting, I can't repro that
hmm
Well, I can if I run collect, but actually running it, it gets skipped
tests/test_black.py::BlackTestCase::test_docstring_reformat_for_py27 SKIPPED (Marked with disabled optional tests (python2))
Ah, you're right!
$ pytest tests/test_black.py --run-optional no_python2 -k test_docstring_reformat_for_py27
1 skipped, 115 deselected in 0.20s
$ pytest tests/test_black.py --run-optional python2 -k test_docstring_reformat_for_py27
1 passed, 115 deselected in 0.20s
Cool, thanks for your help, I'll try doing something similar for the jupyter tests
just gotta love an install error when trying to update your year out of date system π
I honestly have no clue on how my Python installation is set up / works in this environment.
It's one giant mess π
obligatory xkcd https://xkcd.com/1987/
site-packages/~ip hmmm
Yeah some sort of delete operation failed, pip renames a directory before truly deleting it
My environment isn't broken though, so I'mma just leave it alone for now and see if I can get away with mypyc + black without breaking something π
(I know, final last words)
It's been so long that I don't remember why there's two site-packages, one in roaming and another one in local
There's no such thing as virtual environments in this system, everything is installed user level (which is fun /s)
It's probably obvious which system I started my development journey on ahaha, it's windows.
I can't even get mypyc working, and my environment is fine π
π yeah mypy has been just fine for anything I've worked on so far
Anyway, I opened https://github.com/psf/black/pull/2357 last week, and just wanted to ask if anyone has any early feedback - assurance that it's on the right track would be appreciated
No hurry though, I understand that reviewing PRs is hard and that black is probably an all-volunteer project!
I kinda have to wait for Windows update to do its thing since it's slowing down my laptop to unusable levels .-.
I'll take a look soon! I was on vacation for a week and barely caught up on github notifs now π
ooo welcome back then, and yeah those damn GH notifications are like spam, hard to get rid of and there's a lot of them
π thanks! Take your time, and I hope you had a nice vacation π΄
cool stuff
I've come to love Vim. It's my primary editor π
Although I do use Visual Studio Code for complex projects or tasks.
YAY, I was able to reproduce the Windows + mypyc "Reached allegedly unreachable code!" issue, now time to debug.
Some fighting and head scratching with Visual Studio and the C build tools / chain may have or may have not been involved π
> if sys.platform == "win32":
RuntimeError: Reached allegedly unreachable code!
I guess this is because of the platform=linux in mypy.ini?
And somehow I've managed to freeze Notepad++ :sigh:
Thank you for putting in the work here!
Also, this should be mentioned in the docs somewhere, not just in README.
oh for goodness sake, I switched shell from CMD to powershell and now I can't convince the build tools to use 64-bit mode ....
back to cmd I guess
@dense jungle would it be better to just remove platform=linux from mypy.ini or to add logic to setup.py to override that platform override (ie. "--platform={sys.platform}") under mypyc?
It doesn't make much sense to me for it to be in mypy.ini, so I'd just remove it
even without mypyc we should typecheck Black on Windows too
Fair enough, that's what I was thinking too. Let's hope this fixes the unreachable crash π
AND I got the test suite passing locally with mypyc-ified black on Windows! π₯³ Now time to push my fixes and see if my cibuildwheel workflow will work now on windows.
The main reason why it took so long to get to this point is probably due to windows update. I've been debugging / compiling / testing with updates happening in the background and wow my system is slow and sometimes unresponsive π
Yeah same - I use VSCode with vim keybindings and find it to be awesome. Recently found vim keybindings for Jupyter, which make DS work so much more pleasurable https://github.com/axelfahy/jupyterlab-vim
I like the lightweightness of vim though, so Visual Studio Code feels a bit much to me sometimes.
true, but in vscode I can do gd and go to the definition of a function, which I can't do in vim (at least, not out-of-the-box - do you have a trick for jumping to function definitions?)
I'm no vim pro :p
Use language servers
I don't use vim but I know there is an extension/plugin for adding language server integration and then you can just use whatever server you wish to
if anyone is curious to the current status on mypyc + black, I just repurposed the wheel building repository to also serve as the project's main base: https://github.com/ichard26/black-mypyc-wheels
TL;DR is that wheels have been successfully built for Windows, MacOS, and Linux across arm64, universal2, and amd64 / x86_64, but there's still a few smaller items to complete regarding the builds. More performance tuning and testing is also something that is on my radar.
not sure how your experience with the need of manual workflow approval for first-time contribs was for you but GitHub made it a bit more configurable in case you're interested:
https://github.blog/changelog/2021-07-01-github-actions-new-settings-for-maintainers/
just saw that as I quickly checked the GHA default artifacts retention duration π
lol
I thought of it after looking at one of the PR updates with more tests and seeing that it needs workflow run approval
https://github.com/psf/black/settings/actions admin-only (I 'm guessing)
should have thought of that
My experience has been that the workflow approval hasn't been an issue for us (although we haven't experienced abuse of GHA either)
I'm just one maintainer out of many though π
I'm annoyed by having to click that button all the time
ye, I haven't experienced abuse of GHA either which I just find it a bit annoying for the projects I work on
It actually hasn't been annoying for me lol
I'm not sure there's much risk for maintainers? I assumed GitHub did this to reduce resource usage
they already changed the more likely abuse which is the upstream being affected by the activity of forks
which was dumb
I don't have access to the setting for Black but I changed it for typeshed
I think it's annoying experience for first-time contribs too, because you need to run the tests locally rather than just rely on CI
That's a great point!
when I'm contributing to such projects I often end up enabling actions on my fork just so that I can get the tests to run and see I don't fail something in CI
sometimes CI isn't the same as local run too so there's also that
I am curious about the "who recently created a GitHub account" bit, like I've seen spam from quite old accounts. Not that it matters much, but I'm curious π
ye, "who recently created a GitHub account" might not be effective but I feel that until maintainers experience the abuse from their first-time contributors, it's probably better to go for that than make people's life harder
I feel like "don't run Actions" doesn't help that much against abuse anyway. I guess it prevents the PR from eating up our CI budget?
but ye, just letting you guys know about the feature since not all people are probably following GH's changelogs
But we still have to close the PR
Indeed. I basically never contribute outside of projects that aren't either mine or ones I've contributed to already (I would burn out if I picked up more things) so this hasn't bit me much.
also, thanks for letting us know! really useful to have this option now
it's more so that GH can block Actions on the repo if a PR does malicious stuff
Yeah, I was like "they could submit a typo fix PR trivially, and then the protections would be useless"
but like, if malicious PRs start happening, you can always temporarily enable it back as I doubt GH would just straight out block a repo on a first such PR rather than continuous occurence
Fair enough
actually I thought this was about the forks affecting upstream repo without the PR, but now that I read the associated blog post again, it looks like they actually did change it so that PRs against the upstream affect the fork
The recent surge in cryptocurrency prices has driven a significant increase in targeted abuse across CI providers. At GitHub, weβve seen a variety of vectors being exploited. One of these is pull requests from forks being used by bad actors to run mining code on upstream repositories. This obviously has a negative impact on repository owners whose legitimate pull requests and accounts may be blocked as a result of this activity.
To prevent this, weβre delivering two changes to how we treat pull requests from public forks in Actions to help maintainers.
First, weβre updating how we assess reputation on Actions. Specifically, if we determine an Actions run to be abusive or against our terms, our enforcement will be directed at the account hosting the fork and not the account associated with the upstream repository. The goal is to prevent maintainer accounts from being flagged and blocked due to these bad actors.
so should not be a big deal for repo maintainers to not require approval regardless of potential bad actors
other than big spam that literally throttles actions on your repo due to rate limits lol
yep! good thing it's easy to cancel workflows
oh ugh π¦ I haven't seen crypto miners spam in the wild on GitHub. mypy occasionally gets PRs that just seem like clueless people
still annoying though (the notification they send you when a workflow has been successfully cancelled is understandable, but annoying)
I think the cancel notification is sent to the person that triggerred the workflow run, not the one who cancelled, right?
I don't know, but it's still annoying π
ye, I wish the notifications for workflows were a bit more configurable
and I mean both on user level and repo level
for repo level I'm thinking of some actions that I wouldn't want people to be emailed when they fail
like... I wanted to make a check using GH Actions that fails when the PR has some "Blocked by" label (i.e. dependency, damage control, etc.) and make it required check but that would email the author of PR even though they did nothing wrong lol
I know I can use GH app/bot, just kinda wanted to do it with GH Actions
@dense jungle it looks like our test suite has a flaw: only the original safety checks behavior is used during tests, the extra runs behaviour isn't implemented, so the test suite is not reflecting real-world behaviour which probably isn't ideal?
oops
Yes, that's not good. I think it also doesn't do AST safety checks
Yeah, I was like "they could submit a typo fix PR trivially, and then the protections would be useless"
LOOL, that's was I did last week, thanks for the fast approval π
I had zero reason to not trust you π
even though I always run tests locally, I got failures which I hadn't foreseen in CI, so it's been really useful
I on the other hand had some failures locally that weren't actually related to my PR but CI was passing
something about typed-ast
I'm pretty sure the AST safety check is implemented, but I'll quickly double check
I know I said it on one Black issue but I suppose it might have made some sense to make separate issue for it as well
Yeah, I just install typed-ast in my environment because I haven't spent the time to learn how the testing infrastructure works since the changes made during the refactors.
ah ye, this one
https://github.com/psf/black/issues/2238#issuecomment-857569590
the no_python2 test
we fixed the other with Felix so I should cross that out
I still need to actually do something about the "improving the contributing experience" issue, but I've procrastinated with other work π
actually @dense jungle I found at least a few tests that don't run the AST safety checks
I'm in the middle of improving the contributing experience for one of the projects I work on right now too π Indirectly though as it's about better triaging so that the status of issues is presented more clearly but in the end it helps contributors too since they know what issues they can (safely) make PRs for
there's like 4 different patterns of formatting code across the test suite, lovely!
π¦
sigh
I recall somewhere that I had code that produced a syntax error in the output and the test didn't fail
Here's some patterns from a quick scan :
# I think this one is actually doing more work than necessary?
actual = fs(source, mode=mode)
self.assertFormatEqual(expected, actual)
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, mode)
# no AST safety checks since fs is a wrapper over format_str
actual = fs(fs(source))
black.assert_stable(source, actual, DEFAULT_MODE)
# also limited safety checks, although it appears be intentional?
ff(tmp_file, write_back=black.WriteBack.YES)
self.assertFormatEqual(expected, actual)
# this one is used by test_format.py (which contains the majority
# of our formatting tests)
actual = fs(source, mode=mode)
self.assertFormatEqual(expected, actual)
if source != actual:
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, mode
Very consistent indeed π
It was way worse before test_format.py existed though, since every single format test file had to be linked up manually with the choice of how to call black yours! (lots of copying and pasting ended up happening)
At least what was copied and pasted over and over again called all the right safety checks π
Describe the bug
no_python2 test errors on main while following Black's docs for contributing.
To Reproduce
Per docs:
pipenv install --dev
pipenv shell
pre-commit install
pre-commit run -a
tox -e py
The above works properly, however another run of tox -e py results in an error due to tox's usage of existing py environment causing no_python2 mark to be fulfilled:
__________...
decided to make a full issue for easier tracking
almost gave up because it worked on first try lol
thanks for the issue! I don't use the tox setup because reasons ... so I wouldn't have known
personally, as a new contrib I'm more likely to use those kinds of tools so that I can test while making contributions to the projects I'm not that familiar with yet rather than make a PR before I even am sure that I'll be able to fix it
yeah I'm well aware of that π
once I am more familiar with the codebase, I usually just rely on CI π
CI?
CI - Continuous integration
Doh shouldβve known that one π
Basically running stuff like tests and any other checks on a build server
i.e. GitHub Actions
Closes #2355
No added trailing comma in one argument function definitions
def no_trailing_comma_one_argument_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
some_argument
):
pass
This is consistent with the existing style for two and more arguments
def no_trailing_comma_multiple_arguments_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
first_arg, second_arg
):
pass
closes #2367
I ran
rm -rf .tox
tox -e py
tox -e py
and it worked fine
cc @jack1142
For what it's worth I'm not convinced we should change anything here.
Thanks for your contribution though!
I assume it probably works but it feels kinda hacky, I wonder if tox has some configuration option to fix this 
good point - could set recreate = True
I was more wondering if it could somehow cache both of the environments as separate ones to still keep the performance of the cache but I suppose the recreate option is good too
oh right
cause it's all done in a single testenv right now
hmm
should be a matter of splitting it in two and adding to envlist?
with use of extras = instead of pip install too
and would have to not use skip_install which I'm not entirely sure why it is used in the first place
hmm, single coverage report
I guess that would be split too if splitting testenvs, not sure if that's an issue...
just tried timing it with recreate=True, and on my laptop it took just under 1 minute
163.86s user 16.32s system 312% cpu 57.643 total
which, arguably, is fast enough?
Either way, I'm no tox expert, so if you know of a better way to do this I'll close my PR and you can submit a fix, no worries π
if anyone wants speed (eg. me) they can just call the individual commands (eg. me)
Aussie detected π
I am in fact not an Aussie lol
:o
Eh. It is what it is.
Describe the style change
Currently, black does not check blank lines between functions docstring and body.
That means both these options are valid:
def foo():
"""docstring"""
return 0
def foo():
"""docstring"""
return 0
As black is uncompromising and opinionated, I guess this should be taken into account.
Personally I tend to put a blank line but looking at the only potential reference [PEP 257](https://www.pyth...
placefolder function name for demonstration
I see that https://github.com/pypa/pip/pull/10035 has been merged. I just updated the toml -> tomli PR (ie. redid, the conflicts made it easier to just redo the changes) so once CI passes it should be good to go, any concerns?
Sounds good to me!
oh wait, there's an error in the setup.py requirement definition π€¦
setup.py line 77
"tomli>=0.2.6.<2.0.0",```
>>> Requirement("tomli>=0.2.6.<2.0.0").specifier.contains("2.5.5")
True
well lemme fix that
oh it's a period instead of a comma?
yep, tiny mistake that makes packaging think 2.5.5 is now a valid version ._.
Looks like graingert has been getting a lot of projects to switch from toml to tomli, that's another reason for us to switch too
What a time to be alive
I vote push when thatβs released just to see who that upsets β¦
*merged even
here's what happens with a comma lol
>>> from packaging.specifiers import SpecifierSet
>>> SpecifierSet(">=0.2.6,<2.0.0").contains("2.5.5")
False
just almost entered a git command into discord by a window switching mistake π
@dense jungle LoL
glad to be helpful
Much satisfaction.
@solid adder congrats on being the first cpython developer-in-residence!
Thanks
wait @solid adder is the first member here who has the cpython core devs role?
<@&699731944149090466>
no nvm they aren't
there's at least 3 others
The first one getting paid for it directly by the PSF
??
This is some of the most amazing news in the past few years for me. Python needs full-time development to stay competitive, Iβve been talking about this for years, dreaming about it for even longer than that. Now itβs becoming a reality. Today is my first day. Itβs both scary and exciting.
wow, legend!
Black formatted cpython here we come π
nice, saw the reddit post yesterday. congrats!
Whoa, that's amazing! Hearty congratulations!
In the location ~/.config/black I have
[tools.black] line-width = 79
But black still uses 88 unless I pass it as a command argument...
Any ideas?
whats psf
Python Software Foundation
Do you have pyproject.toml in any of the parent directories of the files that you pass to black?
as project's pyproject.toml takes priority over user configuration
@dense jungle + @bright glacier - Thoughts on a low risk release for toml + other fixes?
P.s. I ran experimental on some FB code, but even without it we had some crashes ....
Haven't had time to dig in
hm, doesn't look like we've made a lot of changes to formatting behavior since the last release. would be good to resolve if there are new crashes though
O, we don't have black on 100% of our repos so I'm prob hitting areas that are disabled etc. - Haven't looked into it. I can now parse a toml config with the new library easy having tomli so I'll write a runner to parse our internal config file and check those directories only
It was a very hacky runner just to see how it went
I need to also try it on Instagram
Bah - I am blind - Ignore my dataclass comment on diff, clicked wrong button as I was doing a review. Then saw it, I was like I thought we were using these elsewhere.
π no worries, and thanks for taking a look!
Any objections to the following PRs?
Get rid of .github stuff
Cya profiling stuff (this really isn't useful for end-users)
Yeet Vim plugin files
Dust away official Action
They should be low-risk but I don't think these had strong approval either so π€·
I have no opinion on the MANIFEST one but cooper seemed to disagree?
I'll take a look at the other one
Yeah, admittedly it's arguably pretty useless as now we should be shipping wheels all of the time so when a sdist is downloaded, it's probably for cases that go beyond a simple install (or at least that's what I thought Cooper's point was).
That's exactly my point. Can we leave all the CI config please
I feel we're limiting people there for little gain. Now the other stuff, that makes sense to me to clean up.
It's so old lemme look at the commit history π
Looks like those files were used as profiling targets when working on performance regressions / lows
I've occasionally used them as a quick benchmark between two versions, but that sort of stuff is rather rare.
Sdist (on main): 1.1M, sdist (with prune profiling): 540k
The rest of the difference between the sdist and wheel (roughly 400kB) is basically the docs and tests now IIRC. That's a fair bit of text lol.
OT: is it just me or is the requests documentation getting worse over time?
I'm trying to create some new graphs regarding the pull requests and it's shockingly hard to navigate.
Thought you meant are the requests for documentation getting worse
But you mean the requests lib...?
the theme doesn't help
Yes. I'm querying the GitHub graphql API
But like why is the table of contents so low in the sidebar ???
Use httpx
that too :|
but just scroll a bit and you don't even see the toc at all!
I'm used to requests as my http library but honestly I might just use urllib3 or something like that
tbf, Python's docs have a static toc too
what exactly is it you're looking for? i found most stuff in requests is so simple the docs are rarely needed.
I personally use httpx rn lol
but well
with Python I know what I'm looking for generally
with requests, I have no idea
will know when I find it
Requests is simple, but the documentation experience is not great (tm) so when searching for stuff like (like how to add a timeout or auth) it's annoying, not hard, just annoying.
Aiohttp
my approach to documentation in general is just to google what im looking for like "python requests timeout", click the first link that seems promising, and ctrl + F my main search term
But actually I would use httpx for simple stuff now. Aside from not having websockets, it's basically a drop in replacement for requests
I think I'll stick with requests for this project, but the next one I'll probably look for something new.
that's a terrible section name if I just want to find how to make a request with json payload
i havent really encountered any docs other than discord.py which were hard to navigate this way
Section underneath: Even more complicated POST requests /s
Yeah, but it would be great if I could go up the content tree without having to look for it very hard.
Also that mailchimp ad is quite something
black is using the same theme and i dont really see a reason why requests is much worse than black docs wise Β―_(γ)_/Β―
d.py is all on one page which just freezes my mobile browser and Ctrl+Fing gives you a lot of stuff but usually Ctrl+Fing still works for me
but then again, as you play more with it...
you learn how to work with it I guess
It's mostly the TOC being hard to use in the documentation, Black's TOC ain't great either, but at least it's not hidden down.
in dpy its really the library design and not the docs
i really dont know how the ToC is hidden for you, its right there https://img.laundmo.com/u/RqxZDY.png
the only meh thing is that you always need to start on advanced usage
it stays in the same spot?
here's my view
instead of separate "Useful Links" section
you must have quite a small screen + no adblocker
As I said, scroll down
the toc doesn't scroll with you
it does on black :P
and I can barely see the toc too
I wonder if that's due to the custom CSS we added π
when I'm on top
it must be, its not a theme default thats for sure
You tell me dude.
im really used to it not scrolling with me, so that doesnt bother me
I can go to GH with star button
but there's no "Requests" header or something that lets me click on it so that I can go to homepage
i always use this thing to go to github https://img.laundmo.com/u/z5EJ8a.png
there is no href to the homepage , i searched the source code
this is why i dont rely on the docs themselves to be easy to navigate
- search on google
- find link and ctrl + f
- read relevant sections
- start over with new terms if nothing found
Maybe it's just me fooling myself that docs can be easy to navigate given I'm the one responsible for black's docs π
Nope.
@lament crow you are currently speaking in the black irc
well
where its migrated to
Discord is the new IRC?
isnt it? you used the IRC for what you now use this channel for, right?
ye, I asked because I've seen there's an IRC link in black's docs but now I see that I was on stable, not latest docs so my bad :P
Well yeah Discord serves the same purpose as IRC, but I feel like IRC is distinct from Discord as a platform.
Ah ok that makes sense.
And here's the first graph produced by my latest scripting project. Note that "core review" means a review either by a collaborator or a contributor of the repo. Also note that PRs without a review in their lifetime had their delay value calculated with their creation date diff-ed either against their merge datetime (I'm assuming the PR was reviewed while merging) or the current datetime.
Yeah, there's a few PRs that had delays of over 400 days π (it's the vim ones of course)
Oh right and PRs that ended up closed aren't factored into the calculations at all (mostly because I was too lazy to handle their edge cases).
nice! I guess the data for more recent months is biased downward because it doesn't include PRs that are still open
Unless I'm misunderstanding your point, that bias shouldn't exist since PRs that are still opened are factored in?
though maybe there aren't any PRs that haven't received any review
That seems more likely, there were a lot of PRs that were never reviewed back then lol.
Also, because I keep forgetting to mention all of the little details, only the delay between the PR being opened and the first core review is counted.
The delays between the next reviews aren't counted - my thinking was that the initial delay is way more important to the contributing experience then the average delay of the all reviews.
And yes I was inspired to make this graph reading up on the DIR position π
But anyway, I think this shows *some* progress in improving the contributing experience. Having your PR be a desert ain't fun and reducing time spent in that state is IMO important. Makes sense since there's more people available to do reviews these days π
speaking of old PRs, what do people think of https://github.com/psf/black/pull/1715 ?
Well first of all I don't have any plans of actually reviewing it anytime soon (matter of fact I just removed my self-request) π
I sorta get its value (maybe you have some fancy frontend to your CI pipeline or test suite) but it feels like a lot of code for an uncommon use-case (I feel the same way regarding the GitHub Actions statuses integration issue)
I'm also worried that if we implement that, we'll get closer to "black is now a linter" zone and I would rather not go there.
Yes, I feel like invoking Black in CI should just be --check: if it returns 0 you're good and if it returns 1 you're not
and another graph, with atleast all of the same pitfalls as the previous one π
I do --check --diff for contributor's convenience
as well as my own lol
well, that's assuming I don't use pre-commit already anyway
since then it has diff on failure flag
I need to make a socket and how can I make like a delay for example
the server waits for few seconds, if the client dont send anything in this seconds I will reply to the client a message that the package is loss
this is I'm doing
Hey! Is this related to black? If not, you may find more help in the help channels. Check out #βο½how-to-get-help
Any opinions or input on https://github.com/psf/black/pull/2165?
I don't feel like the question I asked there was ever answered: what observable behavior does this change?
Looking at the code probably nothing. And if my knowledge on this area is serving me right, we still need typed-ast < 3.8 because feature_version support was spotty for the built-in ast module so that answers their "question reply".
is this just a bug of blib2to3? https://github.com/psf/black/pull/2343#discussion_r658632079
If so, I want to ignore that and work on getting the PR landed.
yes, seems like a blib2to3 issue
Alright cool, I'll let them know that we can just ignore that (it's probably fine, Black happily accepts invalid input in certain edge cases so it's not Black is good at being a syntax checker anyway) π
typing-extensions only introduced TypeGuard in 3.10.0.0, is it OK to bump the minimum requirement of it for #2357 ?
yes
Don't forget to bump the requirement in Pipfile although it appears no locking is required whew π
I recently did a pipenv lock (for the tomli PR) so it looks like the pinned typing-extensions is already at 3.10.0.0
ooh, it is in Pipefile.lock, but not in Pipfile nor in setup.py
Wait what?
Oh you mean like it being pinned to 3.10.0.0 already?
Yeah pipenv lock upgrades all of your dependencies when relocking
yeah, I meant: to make 3.10.0.0 the minimum runtime dependency. Currently setup.py just has "typing_extensions>=3.7.4; python_version < '3.8'",
Is the Pipfile meant to contain all the dev dependencies? I'm just a bit confused as to why pytest and tox aren't there
I think I left a comment on that in my first time contrib feedback
For whatever reason, package deps are in pip file, but doc and test deps are separate
It technically allows you to do things a bit quicker, say if you just wanted to build docs, or just wanted to run tests
But I donβt personally think the time gain there is worth all the extra setup steps
I think it would be good to like move them in tests/ and add the test dependencies to pipfile.lock
I just haven't done that yet (well IIRC I have actually have a local branch with such a commit but I didn't finish the rest)
That file might be worth keeping for CI since speed is quite import there tho
Speaking of, I left an update on my pre-commit issue
psf/black#2299
!remind 18h look into maybe* pushing a new release
Your reminder will arrive in 18 hours!
When I use pre-commit I noticed black and isort were in conflict when it comes to long lists of imports
I tried to add an argument for the isort hook but I still have the same error
βprofile blackdoesnβt seem to work for some reason
Is it about magic trailing comma perhaps?
i.e. isort puts the imports back into one line even though black considers it fine?
Black auto-explodes imports, collections, function calls, etc. when they contain a trailing comma: https://github.com/psf/black/blob/master/docs/the_black_code_style.md#the-magic-trailing-comma Thi...
Other than that, the only other thing I can think of is not setting same line length for both formatters or some edge case
Without you showing actual code, it's not possible to tell what is actually wrong and if there is even anything wrong.
Yeah it puts the imports line by line and isort pushes them on two/three lines
Can you show an example?
from drf_yasg.utils import swagger_auto_schema
from rest_framework import status
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView,
TokenVerifyView,
)
from .serializers import (
MyTokenObtainPairSerializer,
TokenObtainPairResponseSerializer,
TokenRefreshResponseSerializer,
TokenVerifyResponseSerializer,
)
And the output is?
Oh nevermind I solved it by just passing args inside setup.cfg
[isort]
profile=black
multi_line_output=3
Describe the bug
If a with or async with statement with multiple with items has parenthesises around the items, like in this example:
async with (
get_connection_pool() as pool,
get_cursor(pool) as read_cursor,
aiohttp.ClientSession() as session
):
...
Black fails to parse it with error: cannot format ...: Cannot parse error, even thought the regular Python interpreter has no problem executing the file.
**To Reprodu...
yay I get to close a duplicate
Describe the bug
When you are creating Docker image, you always tag it with latest tag and either:
- Git tag
or: latest_non_release
This is done in line #41 of docker.yml.
Earlier GIT_TAG is prepared in line #32 of docker.yml.
To Reproduce
Pull both images:
$ docker pull pyfound/black:latest
$ docker pull p...
@bright glacier
Here's your reminder: look into pushing a new release.
[Jump back to when you created the reminder](#black-formatter message)
@neon loom it would be great if you could do a quick look over for the MANIFEST.in PR, it's probably the last thing I want to get in for the next release. Thanks!
Sure
Great! So what are we thinking for 21.7b0?
it needs to happen
Got any final things you want landed?
How to use black in vscode?
The docs have a guide on doing that
Side note: docs look really weird on mobile
!remind 3s hi there
Your reminder will arrive in 3 seconds!
@urban cape
Here's your reminder: hi there.
[Jump back to when you created the reminder](#black-formatter message)
sry shouldn't have done this here
Docker images created during release process will have extra tag 'latest_release'.
This closes #2373.
With this change image with following tags was created when release was created:

Steps in workflow:

And image with fol...
Signed-off-by: BernΓ‘t GΓ‘bor
Signed-off-by: BernΓ‘t GΓ‘bor
LGTM - For bonus points or I can do later - We should describe the tags and their intended usages somewhere in our documentation.
If you have time that would be awesome, otherwise I'll add one day.
Sounds like a smart move to me. Thanks @gaborbernat !
- Can we please just make a note in
CHANGES.mdabout the switch just to inform people
Thanks, looks good!
@ofek just curious, what changed in the fork to make import time faster?
I'm off the grid (literally - Going off roading) in ~10 mins or so - So I can cut a release now or someone else can do it over the weekend. I won't be back till Monday evening with Internet.
I might add the change log entry myself for #2374 and merge if we do want to push now
let's do it now, if anything goes wrong I can deal with fallout
(Y) I'll go add a commit to that with changes entry - I guess it would be nice to get new platformdirs too - That import speed is a nice win
It can wait though, no hurry
@neon loom I noticed one PR that was merged after the last release got put in the wrong place in changelog, let me push a change to your PR real quick
@dense jungle - Sure - thanks!
more than one actually
done
It's pretty easy to make this mistake with the way CHANGES.md works; if there's a release between the time the PR is made and the time it's merged, the changelog entry will likely end up in the wrong place
Cool - once CI passes I'll merge and cut a release. Cheers
it did!
https://github.com/psf/black/actions - Here we go
I don't understand what change we made that allows this person's interesting way of building our docs to work now, but I'm happy it's closed :)
(that was kinda a joke btw, I bet they installed black before building the docs which has been a requirement for a long time)
Why do people build docs? isnβt that what CI is for?
Does it actually upload the results anywhere
Looks like that was a packager for some distro in that issue
why else would you make a man page
I don't know, but virtually every repo ever has been receiving similar issues π This is my "favourite" one: https://gitlab.com/pycqa/flake8/-/commit/f7bda9296329cd0ad22cc38fe51b9fd679eed296#note_554175188
This is a mirror of github.com/pycqa/flake8. Please open issues and pull requests there
even the same person gosh
I donβt think Iβve seen something quite like this before.
Are they building their own python tool with like⦠all the packages ever?
I'd guess they're a Python package maintainer for some linux distro, but apparently that's not the case?
Oh nice, one less unmaintained dependency; and that import time reduction is real nice :tada: I hope the pipenv locking wasn't too painful :)
Thank you for the PR!
By the way, if time allows it would be great if you could add any comments on your contributing experience here: #2238. I understand that you're probably busy though. P.S. thanks for maintaining virtualenv :smiley:
!remind 1D document docker tags
Your reminder will arrive in 1 day!
Does anyone understand this issue more than I do? https://github.com/psf/black/issues/2328
P.S. you can skip like the first minute of their video, it's just them setting up a virtual environment pretty much.
yeah, the current theme isn't maintained since a long time and it shows :p
OK, maybe not a long time (the last commit was from Jan 2020), but in general IIRC this theme was built during the era when responsive mobile design considerations weren't really a thinig
Video indicates they installed from pip, could ask for the output of black version
isn't it shown in the video?
Uhh, oh yeah they did pop list
also, it appears they want two terminating newlines which ???
unless I'm missing something, I'm not sure what Black is doing wrong
anyway, I'm impressed that Alabaster has continued to be Sphinx's default theme in 2021.
My best guess at why they are confused is on Windows it's typical to see the terminating newline to be rendered as an empty line
Also, Visual Studio Code also renders the terminating newline as an empty line too IIRC
I'm doing some refactoring work on the code between main() and format_str() and I got a question. What's the reasoning behind getting the STDOUT buffer, wrapping it, and then writing directly to it? Encodings stuff?
@dense jungle I have my doubts I'll be beating you anytime soon (if ever) π
Just introduce some really buggy new feature and then fix them π
45 times ... (nah people who aren't familiar with the issue tracker are really bad at finding duplicates so it should only take a few horribly broken changes)
i feel called out
it's nothing be ashamed of, who else would vaguely remember hundreds of issues at once? ... maintainers of course!
no, no, I have submitted a bug report to a repo and it was a dupe of a pinned issue
hopefully the maintainer was having a good day ^^
yep all of them were thankfully
i may have done it again on a different repo
sorry @tribal thistle
I want to do a review first Jelle. I got some feedback.
sounds good
By the way, do we have a Jupyter user who could review ( ... or is that you Jelle? I've seen you use a Jupyter notebook IIRC)?
I don't use it
Ah, well, I don't either so hmm.
we do have some in our codebase, let me run the branch on them
so for some reason some jupyter tests fail when running the full test suite but then everything passes when only selecting the jupyter tests ...
I wonder if this is an actual issue or just something with my environment hmm
def test_non_python_notebook() -> None:
> with open(os.path.join("tests", "data", "non_python_notebook.ipynb"), "rb") as fd:
E FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/non_python_notebook.ipynb'
/home/ichard26/programming/oss/black/tests/test_ipynb.py:306: FileNotFoundError
β― find | grep "tests/data/non_python_notebook.ipynb"
./tests/data/non_python_notebook.ipynb
well that's totally not confusing π
I feel like I'm missing something real dumb, but this makes no sense AFAIK
so wait, apparently CWD is being modified somewhere, why not always is still beyond me
tests/test_black.py: os.chdir(str(root))
tests/test_black.py: os.chdir(str(old_cwd))
tests/test_black.py: os.chdir("..")
tests/test_black.py: os.chdir("tests")
whelp, is CI on github passing, would surprise if so
it probably is though since I've expected pushes
yes, it's all green
sigh
oh, the jupyter tests are only run standalone not with the rest of the test suite
I strongly suspect it's due to the os.chdir calls I flagged above
man the various optional test groups really make this confusing
we should use some sort of context manager that resets the cwd to where it came from after the test
It 100% is, but this situation isn't run on CI because ... of course
do you know if unittest or pytest provides something like that?
not by heart, but it would surprise if pytest didn't come with something for that, lemme look
I found https://bugs.python.org/issue25625 but that was rejected
So we have the following optionals: no_python2, no_blackd, and now no_jupyter. I plan on adding a incompatible_with_mypyc marker ... gosh that's a lot. Good thing it appears no test is dependent on another one (that would've been real fun to debug).
I can't find a pytest fixture or general utility for this surprisingly, rolling our own context manager should be simple though
sounds good, I'll send a PR
@ichard26 noticed that the tests from #2357 fail locally due to order dependence. This change makes it so tests don't pollute the global state by making sure any chdir() is reversed.
can tell, I've been hovering over the GHA status π
We still gotta fix that issue where the AST equivalence checks aren't always run in situations they should be in the test suite but this is an improvement :tada:
65abd10 add context manager to temporarily change the c... - JelleZijlstra
Alright first initial lookover complete (I skimmed the jupyter specific code since I have no knowledge of jupyter).
Probably worth some more manual testing though (looks like you found a bug).
I have no experience Jupyter so I can't comment on the Jupyter specific code, but there are a few more minor issues I noted.
Thank you so much for the work, it's great seeing this support being implemented :tada:
I was going to check if the changes would break my mypyc work (was a little worried about the dataclasses inheriting ast.NodeVisitor) but it turns out there's a few merge conflicts in the parsing module from main already so I noped out π
It gets worse, I've seen issues which would've been answered by the issue template... π€¦
silly question
you have https://github.com/psf/black/blob/65abd1006bca13aa5fc12b173bf206dc261bd592/src/black/__init__.py#L91
defined in black/__init__.py but only referenced in a single test in black/test_black.py?
src/black/__init__.py line 91
def read_pyproject_toml(```
nevermind, getting played by github, apparently ctrl+f works better than github's own lookup
@bright glacier
Here's your reminder: document docker tags.
[Jump back to when you created the reminder](#black-formatter message)
if i ever start to finish stuff I work on I'm kinda interested in what this would be like~
There is no official blackd client tool (yet!). You can test that blackd is working using curl:
apparently black is reponsible for over 12% of click's downloads π€―
27% (i.e. largest dependant) of appdirs' π
55% of pathspec ... well okay damn
(it should be noted that this data 100% has issues, but even the possibility of black being *that* influential via what it depends on is a bit scary and crazy)
Is paren in the raise section correct?
https://github.com/psf/black/blob/65abd1006bca13aa5fc12b173bf206dc261bd592/src/black/nodes.py#L595
Additional refactors based on the PR #2206
this is really cool π
Make PyCharm integration less confusing
^ anyone using PyCharm who can confirm this change is correct?
I remember setting up the integration when I first started contributing here, and didn't run into any problems
I'll do a more thorough test now though
oh what
Yeah seems that change is indeed incorrect
I'm not quite sure if this change is due to some perceived enhancement in behavior, or if it's a purely cosmetic one. Removing the quotes had a negative effect, at least in my case, as it meant the file path was treated as multiple separate arguments when there was a space in the path. Having the quotes worked as expected.
no i was more interested in the library itself
Replying to the messages above
ah
(since its named click, but actually isn't a tui framework is a bit surprising imo)
For those following along at home:
Path to my file was: "C:\Folder Name\file.py"
Running without the quotes netted: Error: Invalid value for 'SRC ...': Path 'C:\Folder' does not exist.
Running with quotes outputted regular black output
thanks @tribal thistle ! that's very useful
isn't that inhernet to terminals tho?
I've never had any path that didn't need "" around it if the path had a space
It is expected behavior, so the quotes should probably be left in there
true
hmmmm
is there an "official" way to add black to ci?
Right now I am using black through pre-commit in the ci
o
hm
maybe i should remove it from pre-commit
or run it seperately with different args
because if it would reformat a file i would rather it doesn't so flake8 can get to it and report on it
or wait no that's kinda dumb π
It might make sense to use βcheck in that case
right
but
does it also make sense to use --check locally?
i feel like running it locally it makes sense to run the format
which would mean setting it up to be bypassed in the ci
That depends on what you believe the hook should do. If itβs just meant as a fallback in case something gets missed before commiting, sure
and then after bypassing it in the ci, run it seperately
yeah
wait why am i using the repo as my hook in pre-commit when i can use local black
huh
oh no
@tribal thistle i regret my life choices right now
well no shit that workflow errored
when you scan all of the site packages, what do you think would happe
relevant because it was black
fixed
smh
finally
its done
mmm
i still might change that a little more haha
Update: fixed ci, but my commits weren't signed so now I have to fix it again
Describe the bug
When formatting a *.py file with bracketed returns annotations the error below is returned:
error: cannot format test.py: INTERNAL ERROR: Black produced code that is not equivalent to the source on pass 1. Please report a bug on https://github.com/psf/black/issues. This diff might be helpful: /var/folders/9m/cps802s92k77tpy3z1w56hxr0000gn/T/blk_fu7q8w3k.log
To Reproduce
For example:
test.py
import typing
returning_a_deeply_nested_im...
From @akaihola in #779:
In akaihola/darker#164 (comment) we noticed that format_str() gives different results for some files than running black from the command line or black.main(..., standalone_mode=False). This should probably be fixed before making format_str() an officially public Python API.
Consider this test script compare_black.py:
import io
import sys
from contextlib import redirect...
Hello,
Not sure where the best place to ask this question is so I decided to file an issue. In my organization, we've been running black for a couple of months under python versions 3.7 and 3.8 in our CI and I've never noticed that the output is different between the two.
Is there any scenario where the code style between the python 3 versions will be different? I'm wondering if I should suggest that we only run black with python 3.8.
Thank you! I love using your package.
I've run into a really weird situation testing the above issue
On a py37 install, I ran the following:
black -t py37 file.py
where file.py is:
if x := False:
print("wot")
It errored out my first run, but then... it just worked for all subsequent runs. The content of the file on disk has not changed as far as I can tell.
https://paste.pythondiscord.com/hekeferavi.yaml
Output from my terminal
Ok well... I managed to get it working again.
Having a newline at the end of the file causes it to work
not having it causes it to fail
I'm back in civilization. How'd the release? Any fallout (haven't read shit)
I see we got a latest_release tag for docker now so people can just get released version upgrade for free in their CI: https://hub.docker.com/layers/pyfound/black/latest_release/images/sha256-96a813e046857c2606d15fef05c5b4b8bdc4e764615748b433b7367430260f01?context=explore
AFAIK we had no new issues related to the new release so far π cc @dense jungle
Also welcome back to the computerized part of the world π
Cheers. It's nice to be clean again.
Rubicon Trail is no joke (for any off roaders in here) - I live 45 mins away from the Tahoe entry. So I had to check it off the list.
did you walk it? looks fun!
That explains the many jeeps I saw in a quick google search for images π
Spot the nerd controlling the drone β¦ I bet you canβt guess who that is.
I bet it's not the guy who makes a Prometheus dashboard for his house
Graph everything in your life.
Fixes #2381.
This fixes a bug where a trailing comma would be added to a
parenthesized return type annotation changing its type to a tuple.
Here's one case where this bug shows up:
def spam() -> (
this_is_a_long_type_annotation_which_should_NOT_get_a_trailing_comma
):
pass
The root problem was that the type annotation was treated as if it was
a collection (is_body=True to linegen::bracket_split_build_line) where
a trailing comma is usually fine. ...
@dense jungle I can look into other syntax constructs where a trailing comma is dangerous but I am a bit busy so it will have to wait π
No problem! I can check too
Just managed to sneak a bugfix into my free time
In your code it just feels a bit ad hoc that we're checking specifically for return annotations, so that had me wondering if this could appear somewhere els
e
It seems unlikely given that code should only add a trailing comma to either imports or function parameters (according to the nearby comments)
I guess rolling up the check into the no_comma could be cleaner but I found its behaviour a bit confusing so hmm
I agree it does feel a bit ad-hoc (also technically that new variable's name is misleading)
I'll look into at least rolling the check up into no_comma, should make it a bit cleaner π (unless there's more situations leading to the bug)
π
Why does black have configuration for poetry, pipenv and tox(we could run tests with pipenv/poetry too, using tasks?)? Why not just one of them?
And the poetry configuration is faulty
well whats the pyproject section?
Oh nvm
the pyproject.toml is just a example configuration for those using black for there poetry packages
hypothesmith and hypothesis aren't included in the dev packages in pipfile? Was that just missed or?
Weeee psf/black#2360
I had to check if the opt value was of type tuple then it would have been an argument, and if the value of the argument is empty i.e () then it wasn't passed inside
Felix, do you want the Error?
i don't think it is needed when you include black is furious lol
Well that message suggestion was a bit tongue in cheek anyway π I'm not sure we should actually use it. But yeah I agree
The other maintainers haven't commented on the issue yet though, so this is by no means fully accepted
it is a good messed 
I appreciate you giving it a go though!
Ah yes, i missed it doesn't have accepted label. Lemme know what other maintainers think below
Describe the style change
Today with black, lists are either formatted as all elements on one single line, or all elements on a line each. Within the array, no room for alignment is allowed.
I think there are many cases where a middle ground makes more sense, where the data is more tabular or have other useful context. I have two examples where alignment would help readability of both 1D-lists and 2D tables/matrices.
Example 1 is a pattern we see a lot in our code base. From a re...
I decided to use output.out rather than click.UsageError to maintain consistency with other similar errors.
what terminal it this~
I'm picking this PR up again so I'm wondering whether you did this and found any other crashers? No issue if you didn't π
Prompt is https://starship.rs
pinned in my clipboard
nope, not yet
Alright, let's see if I can find any then π
I thought that PR would make Black make those transformations which got me excited. But it's only making changes in Black's own source code π
seems to be someone just applying some tool to lots of repos looking at the user history
i'm not going to bother approving the CI, I don't see a good reason to merge the changes (perf or readability wise)
Whelp I managed to cause another crash via a more complicated return annotation
looks like I'll sadly have to add something more generic and less specific to detect when we're operating on a return annotation, y'know I would've have thought this would've been an easy quick fix to improve my AST mangling skills with but nope :D
π I'm gonna guess they've done it using Sourcery, which they should at least give credit to
Describe the bug
error when running per-commit on file black
error: cannot format /home/ayesha/Desktop/workSpace/benchmark-comparison/ev/lib/python3.9/site-packages/pandas/io/pickle.py: INTERNAL ERROR: Black produced code that is not equivalent to the source. Please report a bug on https://github.com/psf/black/issues. This diff might be helpful: /tmp/blk_2pyt3r5d.log
To Reproduce
Expected behavior
**Environment (please complete the following information):*...
very useful bug report ^^ /s
actually I take that back because they're formatting a Library in a virtual environment
This won't be the easiest thing to reproduce but it might be possible
bonk, opinions?
Hello Everyone, I am a newbie to Open Source and have some experience in contributing to the documentation but when it comes to fixing issues and code contributions I am unable to perform. Like I don't understand what the issue is and its terminology can anyone help me?
Are you thinking about something specific to Black?
Describe the bug
We found two test failures when building with nix on OSX ( https://github.com/NixOS/nixpkgs/pull/130785 ).
Wondering if anyone has an idea of what could be causing this based on the output of the test failures.
To Reproduce
Happens on certain (but not all) darwin systems. Assuming the nix package manager is installed the following will build the package and run the tests
nix-build --check "" -A python3.pkgs.black
Expected behavior
Te...
Would be helpful if they shared what tests are actually failing π
Oh they shared the PR
sweet
https://black.readthedocs.io/en/stable/change_log.html still shows 21.6b0 as the latest. I guess the build didn't pass?
I might be missing something, but wont the stable version of docs show the latest version at time of release
I.E 6b
Latest shows 7
Describe the bug
Traceback (most recent call last):
File "C:\python\conda\envs\clone\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\python\conda\envs\clone\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\python\conda\envs\clone\Scripts\black.exe\__main__.py", line 7, in
File "C:\python\conda\envs\clone\lib\site-packages\black\__init__.py", line 1130, in patched_main
main()
File "C:\python\cond...
Its not specific any python organisation will do.
Nope we update the stable tag a little bit later once the dust seems to have settled a bit (although this release we had 0 reported regressions - so it's probably fine to update)
!remind 2H move the stable tag since there hasn't been a fire π₯
Your reminder will arrive <t:1626884735:R>!
All software has bugs, so my generic open source advice (for what it's worth) is to take a project which you use / are interested in, and to try fixing something. Many repos have "good first issue" labels
@bright glacier
Here's your reminder: move the stable tag since there hasn't been a fire π₯.
[Jump back to when you created the reminder](#black-formatter message)
@dense jungle any objection to moving the stable tag? There's a regression report but it's due to a buggy old pathspec release being installed (not sure how they tested 21.7b0 since that version (or before IDR well) the pathspec minimum requirement to avoid this issue but oh well)
go for it
Sounds good then
I still don't understand why RTD doesn't pick up the stable movement the first time around (I have to request another job after the first one triggered by the tag update) but everything should be fine now π
I feel like we've discussed this already, but I don't quite remember: why are the stable RTD builds not set to happen on every release?
Meaning on every tag, rather than on "stable"
That's the problem almost all the good first issues need fixing documentation and now I want to do code contribution but am facing problems in understanding the issues.
Itβs okay to ask for help as you work through the issues. Others can help get you familiarized with the code base, and push you over any initial hump
Is black the best formatter
100 %
It's the kind of tool that makes it possible for you to not worry about how you write your code. Black doesn't change the logic, only the look, so that this:
def foo(a, counter=0,con=None, close=lambda x:x.close(),write=lambda x,s:x.write(s),n=lambda a=0,b=0,c=0:0):((foo,n)[counter](a, 1, (open,n)[counter](a + '.txt', 'wt')),((n,write)[counter](con, str(a)),(n,close)[counter](con)))
becomes
def foo(
a,
counter=0,
con=None,
close=lambda x: x.close(),
write=lambda x, s: x.write(s),
n=lambda a=0, b=0, c=0: 0,
):
(
(foo, n)[counter](a, 1, (open, n)[counter](a + ".txt", "wt")),
((n, write)[counter](con, str(a)), (n, close)[counter](con)),
)
So have a look at our docs and come aboard! https://black.readthedocs.io/en/stable/
That'd be a trailing comma, aimed to minimise diffs. For example, when you add items at the end of lists or new function arguments, this way you don't have to add the comma to the previous line
Is your feature request related to a problem? Please describe.
Having to run isort is an additional step when formatting code.
Describe the solution you'd like
Black sorts imports (similar to isort) and removes unused.
Additional context
Black is great, just an idea to make it better.
Can you actually implement removal of unused imports without doing some static analysis
Hmm maybe just a blind search
not completely safely in the presence of globals() and side-effecting imports
I considered side effects, but most of the time I handle those with noqas anyways lol
is sorting imports still being considered by black? if not, then just out of interest, why not close the dupe issue?
I would kind of like to see it, but it's not likely to happen anytime soon
I would like to have a tool that knows to do all kinds of safe or probably safe source transformations. That could also include import sorting, simple type annotations like https://github.com/JelleZijlstra/autotyper, cleaning up some comprehensions, etc. I don't like having to remember tons of different tools to do these things
Describe the bug
Running :Black in a fresh install of Neovim (via Homebrew), with black installed via vim-plug, results in the following error:
Error detected while processing function provider#python3#Call:
line 18:
Error invoking 'python_execute' on channel 3 (python3-script-host):
Traceback (most recent call last):
File "", line 97, in
ModuleNotFoundError: No module named 'black'
Error detected while processing function black#Black[1]..provider#python3#Call
...
Option 1 > option 2
Yeahhhh at that point I would leave it alone (presumably option one) and try to never ever have to maintain or touch it ... ever!
Yea fair, just an example of reasonably complex formatting!
@bright glacier probably worth doing pyupgrade --py36-plus on black rather than hacking away at the old style line by line
yeah, pyupgrade's awesome - would that be welcome?
I don't think large automated code formatting changes are appreciated in black ;)
just noticed there's no isort either - gosh, I'm gonna have to manually sort the imports in my PR then, it's been a while since I did that π
Before
foo = "foo"
bar = "bar"
msg = (
f"This is a fake message containing {foo} "
f"and {bar}"
)
After
foo = "foo"
bar = "bar"
msg = f"This is a fake message containing {foo} " f"and {bar}"
which apparently is indeed valid Python, but preferably the two pieces would be combined into a single string literal.
Python: 3.8.7
Black: 21.7b0
What issues are blocking us from flipping the switch on ESP again? I am failing to remember everything again π
I know of performance issues but are there crashes too?
I think only the performance one
I believe all the crashes were fixed
The known ones at least π
There's no bugs if you don't know of them π
did we ever resolve sqlalchemy's apparent crash with esp?
I just took a look at primer.json
I bet there's an issue somewhere about it, need to find it
looks like that was https://github.com/psf/black/issues/2271
% cat legacy.py def _legacy_listen_examples(): text += ( " "listen for the '%(event_name)s' event"\n" "\n # ... (event logic logic log...
found it with discord search, pretty nice
I'mma quickly run main black over sqlalchemy locally with ESP
if it passes, I'll add ESP to primer.json
sadly there's no way to select a specific project from the black-primer cli, but doing its job manually is quite easy π
What were the results of your duration branch Jelle?
I got reminded of it watching black slowly format sqlalchemy
Nothing too interesting I think. A lot of variation in lines/s timing.
Fair enough, what was the max and min values π ?
Oh no! π₯ π π₯
411 files would be reformatted, 177 files would be left unchanged.
can't tell because the state of the repo changed π¦ my LOC counter fails because some files were deleted. I'd have to rerun the whole thing
Hallo folks!
Oh that's unfortunate, no worry then! Was just curious if you still remembered numbers.
As @bright glacier likely noticed, I'm reformating pip's codebase with black. Is this a good place to ask "why would black do this!?" questions? :)
sure!
Yeah sure, and the answer to your "is ESP safe?" question is that as far as we know, other than performance issues, it's fine. Black is run over quite a few big projects in CI with ESP enabled and there's no crashes (up in the history you can see us figuring that out - and me testing the last crashing project).
and the performance issue seems to manifest when you have extremely long logical lines (e.g., enormous list/dict literals). not sure if pip has any of those
It's breaking around a function call, rather than the or in a conditional.
(also, yes, the input isn't exactly nicely formatted)
Yes, that's a quite highly-discussed aspect of our formatting!
IMO the way black handles any complicated collection literal is ugly, but I don't make these design decisions here π
sorry what part of the diff is that referring to?
I have no idea, trying to figure it out.
Lemme try to find the issues π
Thanks!
but yes that sounds like the long-running complaint about how black splits lines π
Hmm... that link should go into the specific lines.
It doesn't for me. I think the hash may be double-encoded or something?
Here's a screenshot!
What does work is if you go into view file from the diff screen and then select your lines IIRC.
Some PyDis bot will also catch that and present it nicely
oh yeah that's a classic. I think that's what https://github.com/psf/black/pull/2278 is trying to change?
There's psf/black#2156, which has lots of references to other issues!
And is unfortunately extremely disruptive
To be clear, my goal ain't to rehash extended past discussions here. Basically, if it's stuff I can help with or if it is something new, I'd be more than happy that I asked here.
I am not sure whether this PR applies here, it seems to be mostly inline conditional expressions
Hehe, I have a lot of empathy here.
I think the summary is that it's something that it's often complained about and we have sympathy for the complaints, but it's hard for us to change existing formatting decisions at this point
Yup yup, totally understand that! :)
yeah, we closed a PR that IIRC would've addressed this: https://github.com/psf/black/pull/2163
there's technically an open PR that's a 2nd revision from the old one: https://github.com/psf/black/pull/2237
but I doubt we'll actually accept it
it's been ignored, so yeah, not looking good for it π
Yeah, I think the problem is far deper than that
Since there's a boatload of losely related issues with the "2 items not formatted but 3 are" theme
I see https://github.com/psf/black/issues/256 as well.
IIRC ambv said if we could redo this, we would just stop touching parentheses so much since they're too painful work with.
Is there any chance that black can get a special case for re-indenting textwrap.dedent(<multiline string>)?
Ah, good context to have. :)
seems reasonable to me, but Jelle didn't like it for some edge case?
also it's another pr that needs a lot more attention sadly
Hmm... That looks like something I can pick up and drive to completion actually.
Heh, I was going to say I would be fine doing that myself (although as usual I have like 4 different things on the go at once)
I bet you do too π
FWIW, I'm thinking in the context of https://github.com/pypa/pip/pull/10192/commits/1a7037eaf39eba5ee53a4c693bf0b19a7cb9f5a5#diff-176075c35af9916c79a2790a134fc3ab0d4f055e1daf2dd5503b4ca813d5f0dcR102 which is NOT fixed by that PR.
you mean that it would modify the string itself?
Screenshot, to make it easier to see here (what black gave me vs what I want)!
Yep. (also, yes, I do remember the pushback you got on the whole docstring-formatting discussion too)
yes that makes me uneasy π
like we'd have to detect the function being textwrap.dedent, but what if it's aliased?
Don't support it I guess?
Then the logic doesn't trigger. Black is formatting based on tokens, not semantics.
it's not ast safe
Sorry I mean the other way around: what if I have a totally different function that just happens to be called textwrap.dedent in the source?
what if someone overwrites textwrap
There are already non-ast-safe things in black.
And yes, it's an AST modification so it would affect our safety guarantee
Yeah, it would require hacking on the AST safety check, not sure how fun that would be be.
Yea.
A more general idea here could be a sort of plugin system that modifies certain strings. For example, this could be used to format embedded SQL or GraphQL strings.
That sounds like way too much work Jelle :p
Hmm... I wanna push back on adding additional complexity here. :)
Have you seen any code that does this?
no but that wasn't really my point
What is your point then?
It's more about the principle for me, though to be fair we do already make some AST-unsafe changes. The safety check is one of Black's main unique selling points
other than the docstrings, black doesn't do anything that can affect what the code does
(to my knowledge)
and there's already been people mad about the docstrings :)
well it may piss off some linters from moved comments
There's the del thing that changes the AST but not the meaning of the code
"what if people do something that they don't?" is NOT a good argument. "we'd need to relax our AST promise further" is.
@drowsy sonnet what I'm worried about is people thinking "I can't safely apply Black to my codebase, because it may change the meaning of my code"
Yup yup. I get that.
I was involved in the whole discussion that happened after the docstring formatting stuff. :)
(it's almost as if you quoted people from that thread lol)
I guess that thread made a deep impression on me π
FWIW, I do think this is a safe transform that does not change the meaning of anything. I definitely understand folks feeling uncomfortable about relaxing the AST checks. :)
Do we special case like the case that's being suggested right now? (I know they don't involve touching the AST checks, but I wanna see what precedent there is, if there's any).
It seems unlikely we've special case-ed based off names
No, we haven't
And to go back a bit. Honestly, wrt. all the two-item splits and parens, I still think our style would be so much better if it was implemented. But since disruptiveness is a big concern (as it should TBF), the whole argument is kinda stuck. Which is really sad to me, especially because everyone seems to agree that it's the better style π
you would have to analyze the scopes
and then there's things like people doing dynamic stuff with the global namespace
Yeah, probably we'd rely on textwrap.dedent with a single string argument just being the standard library function with behavior we understand. Which is probably true, but it's not safe in general
Technically we do have this collection of AST unsafe changes we wanted to make, but it looks like it was abandoned: https://github.com/psf/black/projects/3
I mean, yes, but I don't think anyone would want textwrap.dedent to mean anything other than textwrap.dedent ever.
And, it's easy enough to say "no, that's not supported".
I have a from package.compat import textwrap
And that textwrap.dedent passes on the b" or u"
And textwrap.dedent("...") still behaves the same there?
Yes only changed for b"..."
That one would be fine I think if we implemented what @drowsy sonnet wants, Black would just ignore anything that's not a single string argument
ANYWAY, taking a step back -- my goal here isn't to convince folks that this is a good idea -- I mostly wanna see how folks feel about these things and if there is stuff I can help with. :)
Hmm... is the concern that "oh no, a new black release changed how the code looks"?
The summary is that "while we do want to make changes, we're kinda chained by things we promised in the past - and we're not sure whether we want to change those promises"
as usual π
Yes. One of our promises is basically "git blame will be messed up once, but after that everything will be great". If we break git blame again, that kind of breaks that promise.
Not that that completely stopped us in the past π
I've got used to it now
But it raises the bar for when we want to accept changes that affect existing formatting
Yep, and I'm not that sympathetic to that sentiment, because I'd like for the tool to be the best it can. It's beta after all. But I recognise that many don't agree π as
, but again, the concerns are perfectly valid.
To a lot of people, the beta markers means nothing now
My only concern is running new black on projects without new black configured
Honestly, if you're thinking of maintaining those promises indefinitely, I'd say it is time to drop the .bN from your releases.
Eg they're not running pre-commit with the autoupdate bot
Because then you CAN use the versions to mean something.
Yeah I don't think the b makes much sense. But now dropping it becomes a big deal π
Make it a
(although, adopting CalVer means you probably wanna tie it to the annual cycle to not break semver-y expectations)
Currently the goal post for stable is getting ESP by default landed, but we're scared to be honest
I think the b just stands for Black now. We make our own versioning scheme
rc good btw
More seriously I'm not sure the versioning scheme really affects what happens in practice (except that the b causes issues for some tools that treat pre-releases differently). We already see that people use Black in tons and tons of projects, and complain if we change behavior. I don't think that would be very different if we didn't have the b.
Right, then it makes sense to just drop it. It's basically the same as 0ver, but with a beta tag because black adopted CalVer.
Yeah, and once we are stable, it seems odd to declare the tool "complete" and just fix bugs.
We both have people thinking it allows us to make disruptive changes and people who completely ignore its existence, I think (opinion) the majority is the latter camp at this point
Yeah I think that was Lukasz's original idea: Once we're stable the formatting never changes. But I don't really think that's realistic
Hmm... I wouldn't consider dropping the beta tag to mean "complete".
It's clarifying what promises you make.
Most likely π
If the trouble is that you're too constrained by the promises made in the past and that's hurting the project's evolution and users now ("we want it, but can't change now") -- then maybe what you need is to do some expectation management.
Is the plan to release final before peg?
pip had to do that, and that's how why we had to switch to calver and got a 6-months-of-warnings deprecation policy.
That'd be great, but I'm losing my hope a bit π
What did you do exactly? I'm not sure how to relate deprecations to formatting changes 
The main argument I have against Black changing formatting between releases is that a fair bit of people don't pin black (or in general but that's a packaging rant)
There aren't that many plans π
Yeah that's always the pain, isn't it π
I guess we could argue that you should pin black or "you're on your own" ...
Yeah we get all those issues where people complain about Black formatting things inconsistently and it invariably turns out they're using different versions
I think we should
Probably, it's hard to announce that to the userbase though,
People need to enable Pinning and autoupdating
Witnessing the docutils 0.17 break with sphinx wasn't fun either
Otherwise I have to check which shade of black I'm using every time I contribute to a new project
d e f i n i t e l y
is guido against black
p.s. @drowsy sonnet thanks for sparking up this conversation, I would imagine some sort of more defined policy of how formatting changes are gauged instead of gut feeling and maintainer consensus would make this situation way better!
People complained cos "why is pip changing, it broke my stuff!". And, they considered everything that pip did to be promised behaviour; even the internals of the tool. :)
pip's so much better now
From twitter it sounds like it, but that's the not the point of conversation here π black isn't for everyone IMO
FWIW, I think it should still have to be maintainer concensus or someone with a veto or whatever -- but having it being defined clearly, would be good.
The veto power was basically ambv, and I guess still is, but he's pretty inactive so ???
I benefit from black a lot, but I'm trying to understand the reasons of why not
Perhaps just personal preference
There's enough twitter threads on the topic, and we're likely to be biased π
It basically ranges from "I don't like losing control to I hate the sad face"
Agree, let me open an issue about this
The internals π well, I'm glad you managed!
people depend on e v e r y t h i n g remotely exposed
Hopefully we can learn from that
there's a ton of stackoverflow answers with people digging in pip's internal
:)
Hyrum's Law
An observation on Software Engineering
Put succinctly, the observation is this:
With a sufficient number of users of an API,
it does not matter what you promise in the contract:
all observable behaviors of your system
will be depended on by somebody.
wish it didn't exist
Law X+1: there's a law for everything
Indeed, sad reality.
Not without lots of people complaining.
I can imagine..
Once a tool is popular enough, you will have someone somewhere complaining about everything. Even good things.
Obligatory: https://xkcd.com/1172/
One thing is that y'all have auto locking on your issue threads, does that help here? Not saying we'll adopt it but it sounds like it could bring useful perspective
We're often hesitant to change formatting now, even though technically we're still in beta (#517). Some questions we should document the answer to:
- When does Black accept formatting changes? How is the decision to change formatting made?
- What are the guarantees Black wants to continue making? When will we make exceptions to the AST safety guarantee?
- As a user, what should I expect when upgrading to a new version of Black?
- How will this change when we have a "stable" release? Wil...
Yeah that can reeally get to you, I'd presume
(although stopping people from complaining sounds impossible)
sorry, I meant "unnecessarily unproductively complaining"
:)
What about if you made a whole brand new parser with its own AST
someone is going to quote me and call me an unreasonable maintainer
Yea, the balance you gotta hit is "what is unproductive complaining" vs "what is a genuine problem".
is this the right place to post a glowing review of black?
But also people use multiple tools
yes!
Not a maintainer, and YES.
100% a good idea to tell the maintainers that you like the thing they're working on. :)
black is the only reason why I haven't ripped off the heads of devs who use inconsistent indentation
black has saved me so much time effort and heartache!
LOL
you've made the world a better place
We probably don't have the maintainer resources to maintain that, we barely touch our fork of lib2to3, and honestly I would like to not touch it again.
Yes, I would prefer not to have our own parser
wait until one of your new hires hates black
All the people who apposed black quit to work at banks :(
LOL
We've had candidates ask if we use black
oh man
... as if they will decline / accept based off its usage?????
Slightly off road: the thought of making a target test suite for us has crossed my mind. A bit idealistic? Yes, but I thought that could help in planning and communicating upcoming changes.
Gonna go tweet that I caused this. :3
I guess it depends on much you think the docs I added are actually read by people
I do technically have access to the RTD stats, but I'm too lazy to check
It would help with planning though
Yeah those are absolutely fine! I just doubt how much raw code we can fit in there π but I'm glad you at least like it on some level
From watching some of the rollout of pip's new resolver, it's like impossible to be good at communicating changes
What's a target test suite?
Oh, you're never gonna reach 100%.
I name my classes Entity and Object
I would assume a test suite that asserts we produce code that matches some code that follows some formatting we would like to enforce down the road
Seriously though, like a failing test suite that would be the ideal formatting behavior
- setup communication channels
- get those to cover as many people as possible
- get everyone who complains onto those
ποΈ π°
OTOH, a passing test suite != no bugs. :)
Nevermind an empty test suite!
That said, getting a bunch of major + large OSS projects onboard to use as a smoke test sounds like be a good idea to me!
We have that with black-primer π
?
although better diffing capatibilities would be nice to help quantify changes
we have 3 pinned issues already
See! It's such a good idea that someone else thought of, and did it already!
:P
Is that a limit?
Yeah, I'd like black-primer to work like mypy-primer where it posts a comment with changes that would be made by a PR
I guess my "improving contributing experience" issue can be unpinned
I feel like it makes pinning not very meaningful if there are too many
Fair enough
Have a "policy" tag? nah, not likely to be many policy issues after these are hashed out
I'll replace my contributing focused issue with the "Define a stability policy #2394", it's IMO way more important