#black-formatter
1 messages · Page 30 of 1
so jelle and vivax suggested use of typeddict from typing extensions
sure then :D
but need to figure why typing extensions doesn't exist now, lets see
typing_extensions>=3.10.0.0; python_version < '3.10', are there any cons for enabling it for py10?
dunno 🤔
ok fixed
now
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1
src/black/__init__.py:239:47: error: Cannot determine type of "PYTHON_CELL_MAGICS"
Found 1 error in 1 file (checked 45 source files)
whaat
i didn't even edit it
uvloop passes
nice
probably because of typing extensions
primer passes
cool
only that mypy thing now
cloudflare didn't ban pydis
i'd be wary saying things like that - it's not true. the IPs used by the cloudflare workers platform tripped the discord anti-spam ratelimits, so really cloudflare banned cloudflare workers, it's not to do with us at all
Oh, thanks for clarifying 👍 , I thought that's what you meant by #dev-contrib message
Hey everyone!
Just wanted to ask if there's a compatibility matrix of black versions and python versions somewhere?
TypedDict is in typing since I believe 3.8. You only need typing_extensions on older versions.
Not that I know of. It's a bit of a complicated thing to work out because there may be different Python versions that Black can run under vs format
We have pretty much always supported running under all Python 3 versions since 3.6, but there were a few releases that didn't support formatting all 3.10 code (and same for earlier syntactic changes, 3.10 just had more invasive ones)
So far all releases have supported formatting 2.7 code, but we'll drop that in the next release
yep, that's how I fixed it 👍
Any idea when 22/~stable~ is dropping?
before the end of the month. Felix tentatively suggested 1/29
i had probably wait that PR until the last
yeah I might need to do it again
so in case some other changelogs come they could be merged into that
happy to resolve any merge conflicts though
it would be easier to do it at the end though 🤷♂️ for others aswell
oo new GitHub feature, visited issues/PR has dim coloured 👀 or am I just noticing them
on psf/black#2360,
it treats
SRC ...items as lines of code if--codewas passed (new with this issue)
Does this basically mean that if--codeflag is passed along with a SRC let's saycodethen it would just read the code fromSRCand output the formatted code to stdout?
as Jason said your initial message about it was confusing lol
maybe, it was 1am
just saw the issue
that just partially addresses the issue
it doesn't handle the min version checker feature
probably worth opening a separate issue for tht
yes that's more of a nice to have. this is the thing we definitely need to do before the release
right, would it be better to have a min req file or automate the min ver calculation from setup.py?
it would be best if someone already built this tool for us 🙂 I don't have any strong opinions here
having to maintain a separate min requirements file sounds fragile though
yeah
I don't think someone has already built this, atleast from a quick google and github search
kind of surprising, it seems widely useful, maybe as a feature in tox or something
related
here's your chance to build a widely used dev tool 🙂
And I'm proposing that "black -c code another files", which currently formats "code" and exits would format "code/n another/n files" instead
But requiring only one SRC with -c would be fine as well imo
Description
This updates the Used by section of the readme to include various wind technology software projects created at the National Renewable Energy Laboratory that use black to varying degrees for automated code formatting.
This PR will close #1956
Checklist - did you ...
- ~[ ] Add a CHANGELOG entry if necessary?~
- ~[ ] Add / update tests if necessary?~
- [x] Add new / update outdated documentation?
95c03b9 add wind technology software projects using bla... - RHammond2
gosh the contents sidebar is so nice in furo
Description
- Add Furo dependency to docs/requirements.txt
- Drop a fair bit of theme configuration
- Fix the toctree declarations in index.rst
- Move stuff around as Furo isn't 100% compatible with Alabaster
Furo was chosen as it provides excellent mobile support, user
controllable light/dark theming, and is overall easier to read
Resolves #2397.
Preview: https://black.readthedocs.io/en/hello-furo/
Checklist - did you ...
- [x] Add a CHANGELOG entry if necessary...
Description
Y'all deserve it :)
@felix-hilden and @isidentical please check that I chose the right email!
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
https://black.readthedocs.io/en/latest/ looks sweet
Are we going to remove the "beta" product this month?
Yeah, someone just needs to do that before we release, presumably the same time Jelle lands the changelog reorganisation.
kk - See if I get time to get the PR ready today
!remind 3H assist mark with the stubs newline thingy
Your reminder will arrive on <t:1642818760:F>!
gosh this is lovely @bright glacier
Okay thanks, got it👍
Here's your reminder: assist mark with the stubs newline thingy
[Jump back to when you created the reminder](#black-formatter message)
No one commented on psf/black#449, as for njs, they said (attached). So should we just decide among ourselves or we should wait for some more time?
Follow-up from #2791 and https://github.com/psf/black/issues/2774, we should add a step to the test workflow which runs the test suite again but with the lowest supported dependencies installed. Unfortunately there doesn't really seem to be good tooling for this (short of https://github.com/ffy00/python-resolver#mindeps-cli) so this may be blocked until such tooling exists or we could take the cheap to implement / more expensive down the road route of defining a constraints file that manually...
@dense jungle There might be a super simple way to do this, we can have a simple script which basically does what the mindeps-cli is doing, and we pass that output to pip install in commands in tox.ini
sed -e 's/>=/==/' requirements.txt?
yeah something like that
same for <=
we would need to add a requirements.txt though
or we be a bit hacky and parse them from setup.py
I wonder if we can move away from setup.py
e.g. use flit and configure in pyproject.toml
Let's just stay with the env var for now.
We'd probably have to write our own mypyc driver
Probably not impossible but it sounds annoying but yeah I do wish we could use flit and pyproject.toml, so much nicer tooling
i don't think there is need to shift, a simple python script would do the work
we can pass the output of the python script to pip install
output could be in form of pip arguments?
Actually the more I think about it no it's not simple at all as mypyc defers to setuptools for the C compilation and filt obviously doesn't support tyat
And I'm not rewriting a cut down version of setuptools
I don't even want to try thinking about stuff like C header discovery or cross-platform supprt
I mean we could maintain two packaging configurations where setup.py just exists for mypyc but like that kinda kills the benefits of moving to flit
(also probably untested IRL and black is not the place for exotic packaging setups lol)
This doesn't cover the case of transitive dependencies
core black doesn't have any but blackd does via aiohttp
oh yeah and the juypter has a bunch of transitive dependencies 
they are part of extras right?
yeah I forgot to add the word 'extra'
it could be argued pinning transitive dependencies to their lowest bounds is not worth it fwiw
other than pinning any downsides? pinning could be automated
what?
I was talking about we could either test the lowest versions of only direct dependencies or all dependencies
yeah, but by "argued pinning transitive dependencies to their lowest bounds is not worth it" you meant that they are currently unpinned and taking the effort to pin them is not worth it, right?
(i didn't check whether they are pinned or not)
you're missing my point
i don't care if they're pinned on our side since we don't control 'em anyways (that's why they're transitive dependencies). My point is that since we don't control them there could be not much point in testing the lowest versions of the transitive dependencies
If we discover an issue within a transitive dependency we'd have to check where in the dep graph it is and file issues against the relevant projects to fix their lower bounds
ah right, i took it in a different way
config PR 👉 👈
when running black --diff on a large number of files where changes are expected, the "would reformat filename" lines seem to get separated from the actual diff for filename. is that expected?
hm that seems bad. maybe a consequence of parallel formatting
Hmm, regarding the mindeps issue, should we use FFY00's lib or implement it on our own, if we want a complete solution its gonna be very similar to theirs
This PR is intended to have no change to semantics.
This is in preparation for #2784 which will likely introduce more logic
that depends on current_line.depth.
Inlining the subtraction gets rid of offsetting and makes it much easier
to see what the result will be.
^this PR shouldn't need a changelog entry. Do I add one anyway or is there a better way to make CI happy?
thanks! ^PR to mention that label in the CI action 🙂
❤️ begone impostor syndrome! (or is it worse now, I can't tell 😄)
811de5f Refactor logic for stub empty lines (#2796) - hauntsaninja
b3b341b Mention "skip news" label in CHANGELOG action (... - hauntsaninja
i am not a fan of the new docs theme
Why?
I thought diff-shades suppresses messages from black https://github.com/psf/black/runs/4908218925?check_suite_focus=true#step:10:92
hmm 
Is your feature request related to a problem? Please describe.
I run an accessibility-based organization (https://github/com/grafeasgroup, https://reddit.com/r/transcribersofreddit) and we would like to transition our codebases over to tab support to allow new folks, regardless of visual ability, to join in and work on our stuff without too much effort. See https://www.reddit.com/r/javascript/comments/c8drjo/nobody_talks_about_the_real_reason_to_use_tabs/ for the majority of the argume...
Sigh, the accessibility argument is a good one but I can't really see a way to make it work with the ethos of Black given it'd introduce not only another formatting configuration option but also a controversial one (I'm just going to ignore the very possible --tab-width feature request mentally that'd probably come if this ever was supported) .
To be completely honest I've never really understood the whole giant debate between tabs and spaces. Probably since I'm a newer developer and just adopted whatever was the mainstream when I first learned Python.
how are tabs more visually accessible surely they are the same in both regards?
is it cause spaces show up as 4 things and tabs are just 1?
or is it the customisability for the developer for how big they show up as?
it's exactly that
ah
for example some people with visual impairments need bigger fonts and indentation width can fall under that too
I feel like it should be possible to customize display for spaces too
I haven't seen any such configuration before, probably since tabs are just logically better suited for this kind of configuration.
but pretty much everyone indents with spaces, so surely tools for visually impaired coders need to deal with spaces?
Yeah.
I wonder if there's a VSCode extension for this, it sounds like something that would exist by now
related blog post: https://hudochenkov.com/posts/spaces-to-tabs/
ooh this is cool
Regarding Github, you can set a default rendering tabstop with an .editorconfig in a repository, and override with ?ts=<value> in URLs.
bump
that was fast
Alabaster is certainly more stylish than Furo but the lack of mobile support is truly not OK in 2022.
FWIW Furo is designed for text readability and not really style points
well relatively speaking, yeah Furo is pretty clean, can agree on that but I'd argue the documentation contents are the 100% the focus point of Furo
Is there a way to make black place nicely with inline comments? It really seems to hate them, and just ignores them, but then mypy yells at me for lines with too many characters
(mypy will never yell at you for line length, do you mean flake8 or something?)
My apologies, you are correct. I mean pylint
problem_scraper.py:26:0: C0301: Line too long (138/100) (line-too-long)
self.service = Service(getenv("CHROMEDRIVER")) # Add environment variable to your system, or replace with your chromedriver path.
black doesnt touch this line
LOL, but apparently it does now. Please ignore me! I don't know why that didnt work the first time.
okay, here's a question: should we have a pyi mode at all? it looks like its basically just special casing based on whether classes and functions have "..." as a body. i find this desirable in py code too! for instance, when writing overloads or protocols. i haven't thought through this too carefully, so i might be missing something obvious, but getting rid of an option would be very much in the spirit of black. i can also open an issue, if people don't hate the idea.
hey, i am trying to use blackd but the command is not working, i have used pip install black[d] (windows 10)
you might need to quote black[d] to please your shell, e.g. pip install 'black[d]'
yeah inline comments are a bit troublesome with black, there are a few issues regarding that, one sec will fetch them
that spits out Invalid requirement
psf/black#458 and psf/black#379
works for me, could you paste the full output
C:\Users\l4sti>pip install 'black[d]'
ERROR: Invalid requirement: "'black[d]'"
C:\Users\l4sti>
and without the quotes? ideally it should be removing this quotes when it tries installing
it kinda works but running blackd wont work, ill edit the output and paste it here
C:\Users\l4sti>pip install black[b]
Collecting black[b]
Using cached black-21.12b0-py3-none-any.whl (156 kB)
WARNING: black 21.12b0 does not provide the extra 'b'
Requirement already satisfied: typing-extensions>=3.10.0.0 in \python39\site-packages (from black[b]) (4.0.1)
Requirement already satisfied: platformdirs>=2 in \python39\site-packages (from black[b]) (2.4.1)
Requirement already satisfied: tomli<2.0.0,>=0.2.6 in \python39\site-packages (from black[b]) (1.2.3)
Requirement already satisfied: click>=7.1.2 in \python39\site-packages (from black[b]) (8.0.3)
Requirement already satisfied: mypy-extensions>=0.4.3 in \python39\site-packages (from black[b]) (0.4.3)
Requirement already satisfied: pathspec<1,>=0.9.0 in \python39\site-packages (from black[b]) (0.9.0)
Requirement already satisfied: colorama in \python39\site-packages (from click>=7.1.2->black[b]) (0.4.4)
Installing collected packages: black
WARNING: The scripts black-primer.exe, black.exe and blackd.exe are installed in '\Python39\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed black-21.12b0
C:\Users\l4sti>blackd
'blackd' is not recognized as an internal or external command,
operable program or batch file.
its black[d]
same error
C:\Users\l4sti>black[d]
'black[d]' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\l4sti>pip install black[d]
Requirement already satisfied: black[d] in \python39\site-packages (21.12b0)
Requirement already satisfied: typing-extensions>=3.10.0.0 in \python39\site-packages (from black[d]) (4.0.1)
Requirement already satisfied: tomli<2.0.0,>=0.2.6 in \python39\site-packages (from black[d]) (1.2.3)
Requirement already satisfied: platformdirs>=2 in \python39\site-packages (from black[d]) (2.4.1)
Requirement already satisfied: pathspec<1,>=0.9.0 in \python39\site-packages (from black[d]) (0.9.0)
Requirement already satisfied: click>=7.1.2 in \python39\site-packages (from black[d]) (8.0.3)
Requirement already satisfied: mypy-extensions>=0.4.3 in \python39\site-packages (from black[d]) (0.4.3)
Requirement already satisfied: aiohttp>=3.7.4 in \python39\site-packages (from black[d]) (3.8.1)
Requirement already satisfied: charset-normalizer<3.0,>=2.0 in \python39\site-packages (from aiohttp>=3.7.4->black[d]) (2.0.10)
Requirement already satisfied: multidict<7.0,>=4.5 in \python39\site-packages (from aiohttp>=3.7.4->black[d]) (5.2.0)
Requirement already satisfied: yarl<2.0,>=1.0 in \python39\site-packages (from aiohttp>=3.7.4->black[d]) (1.7.2)
Requirement already satisfied: frozenlist>=1.1.1 in \python39\site-packages (from aiohttp>=3.7.4->black[d]) (1.2.0)
Requirement already satisfied: aiosignal>=1.1.2 in \python39\site-packages (from aiohttp>=3.7.4->black[d]) (1.2.0)
Requirement already satisfied: attrs>=17.3.0 in \python39\site-packages (from aiohttp>=3.7.4->black[d]) (21.4.0)
Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in \python39\site-packages (from aiohttp>=3.7.4->black[d]) (4.0.2)
Requirement already satisfied: colorama in \python39\site-packages (from click>=7.1.2->black[d]) (0.4.4)
Requirement already satisfied: idna>=2.0 in \python39\site-packages (from yarl<2.0,>=1.0->aiohttp>=3.7.4->black[d]) (3.3)
C:\Users\l4sti>black[d]
'black[d]' is not recognized as an internal or external command,
operable program or batch file.
unfortunately it doesnt work with a d
but i have the same issue with just black, then it even prints out succesfully installed but it does not work
with black i can type python -m black but it does not change my file(maybe i am using it wrong) but python -m doesnt work for blackd
its blackd
you use [] syntax to specify extras when installing with pip
o okay, i read your message wrongly then before
whats the output of python -m black, btw you can also use black
but blackd doesnt work either
python -m black does work but black doesnt,
C:\Users\l4sti>python -m blackd
C:\Users\l4sti\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe: No module named blackd.__main__; 'blackd' is a package and cannot be directly executed
restart your terminal, the bin must not have been sourced
yep, blackd can't be executed directly, you will need to pass in the arguments(port, etc.)
a okay so that is fine, if i specify a port and stuff it should work?
doesnt work, i also restarted my pc in case that solved anything
https://hub.docker.com/r/pyfound/black#!
this is also a server right? and not just black in a webui
not sure, maybe @neon loom would know about this
it is the same as black (src) and the container automatically shuts down if it is done, so you would need to add --restart=unless-stopped 24/7 monitoring (or a smarter way)
if i do this it still wont work, is that because of python -m ?
python -m blackd --bind-port 9090 doesn't work?
nope
same error as here
i also tried python -m blackd --bind-port 9090 & because in the docs it says blackd --bind-port 9090 & # or let blackd choose a port
oh screw that sorry,yeah it should be blackd --bind-port 9090, but you are saying it doesn't work even after restart 
going to the blackd.exe and then running blackd.exe --bind-port port works but that aint the way, is it?
it shouldn't be, not sure how windows binaries though
Can't imagine why it isn't found if black is found
Is the error still the "not found" if you start "blackd"?
if i type just black or blackd it does not work, only if i use python -m black works
Oh!
C:\Users\l4sti>python -m blackd --bind-port 9090
C:\Users\l4sti\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe: No module named blackd.__main__; 'blackd' is a package and cannot be directly executed
and this is still the issue
yeah python -m won't work with blackd
Do you use a virtualenv of some sort?
i installed it system wide
psf/black#1558 looks related (same issue)
just opened cmd, and entered pip install
but the solution was -m
Could you try using one so we can get an isolated install?
richard has a different solution commented though, not sure if that would work, but worth a try ig
sure, ill install it in a venv
do any other cli applications work?
all of them except i tried using patool but that one doesnt work
weird, could you paste your $PATH
C:\Users\l4sti\Desktop\TEMP>echo %PATH%
C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\WireGuard\;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files (x86)\dotnet\;C:\Program Files\Go\bin;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Users\l4sti\AppData\Local\Microsoft\WindowsApps;C:\Users\l4sti\AppData\Local\atom\bin;C:\Users\l4sti\.dotnet\tools;C:\Users\l4sti\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\l4sti\go\bin;C:\Users\l4sti\AppData\Local\GitHubDesktop\bin;C:\Users\l4sti\AppData\Roaming\npm
Hmm, I can't see Python in there
yeah ^
but running python works?
which python what does this show
blackd in venv does work
yep, path issue
which python does not work, but running python works
i think that is because i use the windows store installation and not the the one from python.org
(Trying to get python location, so we can add it to path)
oh
no idea then
try opening a help channel #❓|how-to-get-help
oooh
C:\Users\l4sti>python -m site --user-base
C:\Users\l4sti\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages
and windows started sending messages that i should get the windows store version, ill just install the old python style
definitely try a conventional install then :D
go to that path
then go inside bin folder
and see blackd is present in it
if it is, add that path to $PATH
blackd is present in scripts, i can run blackd.exe just fine
switching to a none windows store version solved all my issues
awesome 👍
thanks for the help guys!
your welcome 😄
gotta remember that's a thing then so we can recommend against it
or microsoft just fixes it.. the easiest solution for the many
felix, what are power statements for?
are they method call statements?
Could we add --colour as an alias, this happens a lot with me, i am sure there are others too
wait, what do you mean?
on windows it is where, not which
oh well well smh 🤦
these, the power type nodes called by Visitor in LineGenerate
could they be the exponent of a power? or the whole expr?
doesn't like exponents, see that screenshot i psoted, the statement is 5 .bit_count()
"a ** (5).bit_count()"?
no just that
src/blib2to3/Grammar.txt line 156
power: [AWAIT] atom trailer* ['**' factor]```
ok yeah, its method calls and **
Closes #2034
Checklist - did you ...
- [ ] Add a CHANGELOG entry if necessary?
- [X] Add / update tests if necessary?
- [ ] Add new / update outdated documentation? -> n/a
tada, done
Welcome to the confusing mess that is the blib2to3 grammar
It’s just black packaged. You could run blackd in there for sure unless I’m silly and forgot to do the optional install.
https://github.com/psf/black/blob/main/Dockerfile#L9 - yeah blackd is there
Dockerfile line 9
&& pip install --user --no-cache-dir .[colorama,d]```
We should probably add __main__.py if it doesn't exist already
interesting idea! could be worth looking into
one problem is that other linters (i.e. flake8) will yell at you if you put the class/function body on the same line even if it's ...
I'd also really like this
lol yeah it was super confusing at first, but now I am starting to understand :D
well, I could have got another PR today, just got into this mess #internals-and-peps message
Spent too much time trying out different methods but finally got stuck with regex
psf/black#2067
oh wow, that issue was opened on a very very nice date
and bump
Description
Just in case the blackd console script is not usable.
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
if someone could test this locally python -m blackd --help that'd be wonderful since I made this change on the web.
I'd prefer not reimplementing the wheel
although I have never used mindeps so I don't know if it works for our usecase
- State we're not stable and that we'll uphold our formatting changes as per policy
- Link to The Black Style doc.
Description
Checklist - did you ...
- [ ] Add a CHANGELOG entry if necessary?
- [ ] Add / update tests if necessary?
- [ ] Add new / update outdated documentation?
Thanks! Some wording suggestions
Thanks! Please stalk and improve any other projects of mine that you can find :)
This looks so much better, thank you!
We should add an entry about mypyc though, not sure whether to put in under highlights or performance (I'd lean towards performance but mypyc could break things although I sure hope not).
- _Black_ is now compiled with [mypyc](https://github.com/mypyc/mypyc) for an overall 2x speed-up. (#1009, #2431)
LGTM!
We should add experimental string processing to this before it's considered stable, too, but maybe not yet.
d2c938e Remove Beta mentions in README + Docs (#2801) - cooperlees
3905173 Use magic_trailing_comma and preview for `F... - sobolevn
@dense jungle black is adding spaces after 0x10 in 0x10.real (formats it to 0x10 .real), should I remove that formatting feature? or keep it
were you going to add parens instead? that feels more consistent to me
oh didn't you say it isn't needed for hexdecimals and exclusive complex numbers?
it's not syntactically needed but might still be good for clarity
don't have strong opinions here, also feels unlikely to come up much in practice
umm, i am kinda inclined towards not having them, since they are really redundant, 0x10.real is pretty clear
yep
it's just for ints you need the space or parens
yeah
but like i said in my comment, its pretty confusing
the two dot operators
() are nice there
yes agree
ok so back to question, how do i remove the space?
can't find the relevant section of code
yeah , goodnight 😄
nope, they have prefix
but the trailer stmt ( .real) doesn't have pregic as ' ', seems to be done after the power operator
lets check
ok back, found out it happens somewhere here, ```py
if node.type not in WHITESPACE:
self.current_line.append(node)
but it doesn't do anything special
also, there is nothing special in teh node
no prefix, nothing which can cause this 
color is the preferred spelling in American English while in British English, colour is preferred. A lot of people use colour (me being one of them) and there is no reason to not support --colour and make them use --color.
^^
Nice! How's the help output?
Thanks! I think this is nice, but I'd like it even more if the aliases would be hidden because it will reduce some clutter and still helps with the typo to silently accept both. But I'm not strong on that.
Jason's screen shot from the new help:

Is this the only case where alias would ever be used
or it could be used in future also
(that would change my solution to the what felix proposed)
Well I'd argue that if we do this then why not do it for other flags as well :D
hmm yeah, but i would need to patch click for that 🙃
What do you mean? For the invisible aliases?
yeah
oh, then might not be worth it
but it isn't really hacky, i will give it a shot tomorrow, gtg for now 👋
Description
Closes #2360: I'd like to make passing SRC or --code mandatory and the arguments mutually exclusive. This will change our (partially already broken) promises of CLI behavior, but I'll comment below.
Checklist - did you ...
- [x] Add a CHANGELOG entry if necessary?
- [x] Add / update tests if necessary?
- [x] Add new / update outdated documentation?
is this channel for hacking?
It's for the Black formatter, see channel info!
oh
https://black.readthedocs.io/en/stable/integrations/editors.html#pycharm-intellij-idea maybe it should be mentioned that File watchers plugin needs to be installed first (at least I had to, in PyCharm Community Edition on linux)
- Optionally, run Black on every file save:
Im referring to this part btw
feel ya, my man
I shall now retreat to my shame cave
bump, if anyone can help me out with this
73cb6e7 Make SRC or code mandatory and mutually exclusi... - felix-hilden
Suppose we have a function with both named and unnamed parameters:
def print_characters(
foo,
/,
*,
bar,
foobar,
):
print(
*foo,
sep=foobar,
end=bar,
)
Currently, Black does not allow spaces before comments to parameters. Black formats like so:
print_characters(
# Positional parameters
"42", # foo
# Name-only parameters
bar=".",
foobar=", ",
)
I would like to u...
yo how do i disable single quotes from turning into double quotes, auto editor changes it every time i run
the editor, or black does? 😅
black i think
why black is converting hex literals to uppercase? 0xaa -> 0xAA for example
what is the reason?
I think it's a common convention to write hex in uppercase
0xDEADBEEF
we did change our mind on this a few times, you can look it up in the tracker
running the hug_power_ops branch on our codebase now
thanks, it feels a bit undertested honestly but I very much do not have time to test out more
your suggestions to test float literals was a good one though, I don't think I found any issues related to 'em but it does feel a bit less sketchy now 😄
I think after this PR is merged, the last thing that's waiting on me that I still want / need to work on is the mypyc build setup, it's coming along slowly and once I'm done with this giant task I've been assigned recently I should be free to get it ready.
(I should be free by Thursday, hopefully)
great! I think mypyc will be a really compelling feature for the new release
I am probably going to merge hug power ops once this trial run finishes
so far I like the changes
I am waiting to see the diff-shades results changes meaningfully, I just don't want to see a jump in churn since that means I broke / changed something I didn't mean to :p
this would arguably be nicer if we hugged all operands ```- A = ctl["mean"] ** 2 - q ** 2 * ctl["sem"] ** 2
-
C = exp["mean"] ** 2 - q ** 2 * exp["sem"] ** 2
-
A = ctl["mean"] ** 2 - q**2 * ctl["sem"] ** 2 -
C = exp["mean"] ** 2 - q**2 * exp["sem"] ** 2
hard to be consistent about it though unless we want to expand what simple means
given subscripts can contain any valid expression, it's hard to consider them truly simple. but yeah this example does hurt to read.
yes, probably not worth changing
fortunately no.
+ negative_feedback_penalty**negative_feedback_count
Gosh, I am no fan of referencing 10s of sources at once, this is going to take a while to fill out 😔
I suppose this is the special case Łukasz wanted?
doesn't look great if both operands are variables
but then again we probably want to hug a**b
and I don't want to switch on the length of the variable name
Yeah no, I'm very against that too.
ok it's done 135 files changed, 251 insertions(+), 251 deletions(-)
let's land the change
I regret not filling out the APA references as I picked up new sources. Very very repetitive.
but hooray it's been merged 🎉 Curious what's the impact of this change compared to 21.12b0 now. Just gotta wait eight or so minutes for diff-shades to run.
╭───────────────────────── Summary ──────────────────────────╮
│ 12 projects & 271 files changed / 1928 changes [+964/-964] │
│ │
│ ... out of 2 071 575 lines, 10 149 files & 23 projects │
╰────────────────────────────────────────────────────────────╯
Heh, not as much as I expected.
hm fuzz found something but I can't repro it locally https://github.com/psf/black/runs/4931602723?check_suite_focus=true
wait I can
caused by the power hug change
but now my test for the fix hits a different stability bug 😦
AttributeError: 'Leaf' object has no attribute 'opening_bracket'
sigh, I know why this error is happening but I've tried ignoring fixing it because it's annoying to fix
yeah I'm fixing it properly now
basically there's some Leaf attributes that by default don't exist but then once BracketTracker.mark is called on a leaf, opening_bracket and bracket_depth are assigned. unfortunately making Leaf.clone() copy these attributes always breaks other code.
I suppose add a boolean parameter to clone to copy over those attributes too?
I guess we could special case it in hug_power_op but that seems a big sketchy
doesn't seem to break anything
hmm I wonder if my checkout was dirty then
possibly because I only fixed opening_bracket and not bracket_depth
Ah yeah I tried copying over bracket_depth and I got some .. interesting results
IIRC it broke some line length calculations leading to some very long lines
Found by the fuzzer. Repro case:
python -m black -c 'importA;()<<0**0#'
Unfortunately the resulting code still crashes due to an
apparently unrelated stability bug. I'd like to fix the crash
first.
I wonder how the other transformers don't experience this issue but that's for another day :)
there's another crash on top of this one 👀, wow
yes 😦
maybe they don't clone as much?
it seems to also only happen if the transformer runs and the line gets split up
ahh they clone Line objects for the most part, not Leaf objects
❯ grep -R "\.clone" src/black/trans.py -A2 -B2
should_hug = False
for idx, leaf in enumerate(line.leaves):
new_leaf = leaf.clone()
if should_hug:
new_leaf.prefix = ""
--
)
new_line = line.clone()
new_line.comments = line.comments.copy()
append_leaves(new_line, line, LL)
--
# Build the final line ('new_line') that this method will later return.
new_line = line.clone()
for (i, leaf) in enumerate(LL):
if i == string_idx:
--
return
new_line = line.clone()
new_line.comments = line.comments.copy()
try:
--
# --- Construct `next_line`
next_line = line.clone()
maybe_append_string_operators(next_line)
next_line.append(next_leaf)
--
self._maybe_normalize_string_quotes(rest_leaf)
last_line = line.clone()
maybe_append_string_operators(last_line)
--
yield Ok(last_line)
non_string_line = line.clone()
append_leaves(non_string_line, line, LL[string_idx + 1 :])
yield Ok(non_string_line)
--
# --- First Line
first_line = line.clone()
left_leaves = LL[:string_idx]
--
# --- Last Line
last_line = line.clone()
last_line.bracket_tracker = first_line.bracket_tracker
Yeah, the transformer call logic recursively applies each transformer and if one does make a change then the results get all of the transformers applied and so on.
I only somewhat wrapped my head around it today 🙂
hm the magic trailing comma hack where we format twice doesn't really work, it doesn't actually output the twice-formatted code
yay for even more discoveries for what was supposed to be a simple bugfix 😦
# requires line_length=0 I feel like this is just begging for edge cases lol, good way of stress testing the logic though haha
I did get it to repro with a normal line length too, just replace the 0 with a really long int
but I gave up on that when it hit the stability bug
what are these changes for? I'm just wondering if this could change formatting
oh wait probably mypy pleasing
yes. it should always be set to non-None at that point
otherwise it would have crashed
I guess I could put an assertion in instead
should happen if you remove the fast=False from the test I added
The previous run-twice logic only affected the stability checks but not the output. Now, we actually output the twice-formatted code.
It'd be great if we didn't need these extra passes, must hurt performance a bunch but it is what it is. Anyway curious to how diff-shades reacts.
this diff shouldn't change performance, we were already doing the second pass but throwing away the result
hmm I'm not too sure about that, right now a format would look like: format_str -> check_ast_and_stability -> format_str again (and assuming no magic trailing comma funkiness exists) -> we're done
now it's format_str -> format_str -> check_ast_and_stability -> format_str again
unless I'm missing something which is possible given it's 11:47 PM here
format_str doesn't call check_ast_and_stability, it's further up
I know, but I'm just referencing how black works in general, no? Basically assume the parent is format_file_contents. Is this less confusing?
[MAIN]
format_file_contents
- format_str
- check_ast_and_stability
-> format_str again (and assuming no magic trailing comma funkiness exists)
[PR]
format_file_contents
- format_str (makes changes)
-> format_str
- check_ast_and_stability
-> format_str again
oh yes, it would call it another time in assert_stable
we could probably avoid that if we really wanted
also assert_stable probably doesn't need to use format_str which may do two format passes
doesn't matter too much as it's on a failure path already but it'd serve as protection against any severe performance issues with other parts of black I suppose
apple = [
x + y
for x in range(10)
for y in range(10)
]
Would multiline comprehensions be good or bad
Since this gets formatted into one line
So whether it gets formatted into single line or multi-line is dependent on the comprehension's length?
Yep!
@dense jungle Quick about the stability checks in psf/black#2807: wouldn't Black abort when instabilities are found? So users can't run Black twice to get around it.
under the current or proposed behavior?
no, because of the way the stable check is currently written
we don't abort if it's stable after the second format
OH
so right now we just produce unstable output silently
oh no.
Hmm I think I get it now, so because the stability (not equivalence) check is performed after the second pass the masking is essentially the same as actually running it twice
yes. and I'm pretty sure we meant to actually run it twice
psf/black#2126
suggestions for how to do that are welcome 😄
yeah that's the rub isn't it :D but now we at least can make this change
<!--
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 `...
qq - Can I mark a directory to be ignored by black for formatting? Some special .black or something that lives along with the code?
you can use the exclude option in pyproject.toml
This will hurt the runtime for files where changes are made (without trailing comma shenanigans) by 50% which sucks especially this will undo 50% of the mypyc gains in these cases, but I can't think of anyway of working around this without changing the informal APIs which is a no-go.
Consider this approved barring one minor issue / question. Thanks.
!remind 8h make a PR that adds unit tests to black based on the code that changed in the diff-shades output for #2807
Your reminder will arrive on <t:1643171583:F>!
Did anyone test what is the overhead of parsing in general compared to the all black logic (formatting etc.)? (not in the Python 3.10 fashion, but in general)
lemme check my local benchmark data and calcuate the ratios
.., because yes I do have this information just laying around 😅
haha, amazing! I was going to do it by myself, but just wondered in case you or Jelle knows this already.
[fmt-fast] [parse]
black/__init__: 804 ms +- 25 ms 375 ms +- 13 ms
black/brackets: 251 ms +- 7 ms 116 ms +- 3 ms
black/comments: 197 ms +- 5 ms 109 ms +- 2 ms
black/linegen: 787 ms +- 21 ms 378 ms +- 10 ms
black/lines: 582 ms +- 15 ms 286 ms +- 6 ms
black/mode: 94.7 ms +- 2.1 ms 39.1 ms +- 1.1 ms
black/nodes: 659 ms +- 19 ms 318 ms +- 9 ms
black/output: 86.4 ms +- 2.2 ms 42.5 ms +- 1.2 ms
black/strings: 155 ms +- 4 ms 70.3 ms +- 1.6 ms
comments: 150 ms +- 4 ms 68.6 ms +- 1.8 ms
dict-literal: 133 ms +- 5 ms 47.5 ms +- 1.1 ms
flit/install: 422 ms +- 12 ms 215 ms +- 5 ms
flit/sdist: 188 ms +- 6 ms 105 ms +- 2 ms
flit_core/config: 561 ms +- 16 ms 275 ms +- 6 ms
list-literal: 78.7 ms +- 2.3 ms 26.3 ms +- 0.7 ms
nested: 152 ms +- 5 ms 59.1 ms +- 1.4 ms
strings-list: 24.5 ms +- 0.9 ms 6.45 ms +- 0.14 ms
this data is the interpreted black results I measured so I'd have something to compare my mypyc results to so it's a bit outdated (probably on the parser side)
interesting, so in general parsing is ~50% of total time?
Interesting, so about 30-50 % parsing
yeah that sounds about right
python -m cProfile -o profile.pstats -m black src/black/__init__.py
gprof2dot profile.pstats | dot -Tsvg -o profile.svg
most of the overhead in the parser is in addtoken which is why I made a lot of changes to it in my mypyc PR (which was unfortunately effectively reverted with the 3.10 optimization but hey that's life)
I'd imagine the 3.10 changes to the parser has hurt overall parsing performance where pattern matching is still uncommon. I don't know what the numbers are though so this is just speculative.
Random question that might not have to do with black: I feel like there was a PR for a Rust PEG parser for Python posted here, was that black or some other project?
probably LibCST, which we may end up switching to as our main parser and CST but that be a full rewrite of the project 😔
Ah, that is interesting. I knew that addtoken was a hotspot, but didn't think it was this big. There is someone who relayed their interest in optimizing it, but I don't think they are actively looking into it at this moment (no PRs yet, https://github.com/psf/black/issues/2762#issuecomment-1013884171).
if the Rust parser is fast enough it should theoretically improve overall black performance but it does have to overcome the loss in attribute access and class instance creation that currently mypyc optimizes very well (we wouldn't be able to compile libCST's node types unless we want to vendor which sounds painful)
that was probably it, thanks. I don't mean it specifically in the context of black, but I though I remembered someone (isidentical?) bringing it up here and was curious.
I asked this because I saw the double-pass PR by @dense jungle, and wondering whether we could cut the parsing overhead of the resulting tree (so we would return both the source and the modified tree from the _format_str_once() and use it again for the next time if there is a second pass needed)
There's some notes I wrote down in the issue tracker of https://github.com/ichard26/black-mypyc-wheels
While lots of compatibility work has been done in https://github.com/psf/black/tree/mypyc-support-pt2, limited performance tuning has been done. It's very possible more performance can be s...
that feels a little risky, in case the parse tree doesn't properly roundtrip with the source code
The optimizations I applied here are 100% mypyc specific but the overall way I went about optimizing for mypyc efficiency might be helpful.
I am a bit unfamiliar with the internals of that logic, but is there a case where the final lib2to3 tree would differ from the actual source?
hopefully not but there can always be bugs 🙂
well we do ignore parenthesizing del targets right as it changes the AST IIRC?
actually I think this should be safe, if there's a bug the later stability and equivalence checks will catch it
that's not relevant at the lib2to3 parse stage, it's just in the later AST check
yeah I just remembered that, sigh
😅 right
It might still be worth considering it will cut %15 (%30/2, right, if my math is not off?) would be visible change
well only for files that see formatting changes
technically we could make Jelle's PR introduce no more runtime cost but it'd involve messing up the APIs that we are kinda stuck with
I suppose we could do this but it feels inconsistent and I don't like it:
format_file_contents()
_format_str_once() (assuming this makes changes)
_format_str_once() again
assert_equivalent()
assert_stable() (if only the second _format_str_once changed something)
basically reimplementing format_str and assert_equivalence_and_stability within format_file_contents
Perhaps the best solution is remove this trailing comma instability one day (especially as we won't be able to do fancy CST reuse tricks with LibCST) now we do have some room to change the style but I'm just dreaming at this point since it sounds very very hard 🙂
Currently on main the performance characteristics are:
- no changes made: one format pass
- changes made and it's stable: two format passes
- changes made and it's unstable (presumably due to trailing commas): three format passes
Jelle's PR would eliminate the last case so any file changed would be reformatted three times.
(I think I'm repeating myself at this point, I'mma go finish up other stuff now)
I'd like to land the PR as is so the behavior is fixed, then if we have time look into possible perf improvements before the release
also I'd be grateful if someone can review https://github.com/psf/black/pull/2806
how's diff-shades btw, any complaints yet? (don't worry, I still have ideas to help performance that don't involve improving black's performance 🙂 )
it's great, it was helpful to see a few changes from the run-twice PR
@muted haven here's the parser bit of the profile from the same profile data above well OK not actually, but the same file (this run made changes hence why paser_tokens was called twice).
Seems like the net effect of 3.10 abstractions on non-3.10 code seems to be about %3 percent (the time_spent(add_token) - time_spent(_add_token), time_spent(__next__) - time_spent(generate_tokens)), but as you've said due to we can't use mypyc it will probably much more compared to the version we were able to use it.
what do we still need primer for again?
Uhh platform coverage ..?
It'd be really easy to switch it out for diff-shades although they aren't 100% feature compatible, I e. there's no config file feature for diff-shades
not currently a problem but if we want to say ignore a file we would have to make changes to ichard26/diff-shades
I'd much prefer that over having to change true to false in primer.json every so often 🙂
Kill it with fire if no benefit anymore.
I just made it so that we'd get releases and have more confidence again. It achieved it's goal.
Influenced mypy CI + diff-shades. So well done a days worth of work
At the moment, it's just a source of spurious CI failures and busywork
updating the configuration file.
Unlike diff-shades, it is run across many different platforms and
Python versions, but that doesn't seem essential. We already run unit
tests across platforms and versions.
I chose to leave the code around for now in case somebody is using it,
but CI will no longer run it.
you also influenced typeshed CI as they use mypy_primer to test out stub changes 😄
nice work :)
Story of my life. Pretty much everything I’ve done at Facebook eventually gets redone - but I tend to do the initiation and v1 then smarter people make it better / complicate it :-p
Pumped. Just got an asyncio Bluetooth le client working with the electrical system telementery of my RV. Woot. Prometheus exporter for my RV here I come 👌
as if you didn't need more home automation, mr. "I have too many IoT devices" 
I mean, there's no limit to how many IoTs devices someone can own, right? haha
also nice! a few years I looked at doing bluetooth with Python and I ended up going "nope, I'm not coding this, nuh uh" so to do it with asyncio and LE is awesome!
^ sorry I changed my mind
!remind 18H review psf/black#2799 and that bugfix for your (broken) power hugging code
Your reminder will arrive on <t:1643235799:F>!
Here's your reminder: make a PR that adds unit tests to black based on the code that changed in the diff-shades output for #2807
[Jump back to when you created the reminder](#black-formatter message)
Hi,
we use black in our CI in pre-commit with --check and --diff options
If there are bad from black point of view lines it report them like something like
...
result = {'own_key': own_key, 'defended': defended_object, 'substation': substation, 'switches': switches}
return result
would reformat source\pf\relay_switches.py
Oh no! \U0001f4a5 \U0001f494 \U0001f4a5
1 file would be reformatted.
flake8...................................................................F...
ooops sorry just read the channel description
no worries!
Uhh there is a bug with primer
two processes using the same file
Also looks like django isn't excepting any change now, https://github.com/psf/black/runs/4946883416?check_suite_focus=true
if i am reading that correctly
I am not completely sure but I think https://github.com/django/django/commit/edbf930287cb72e9afab1f7208c24b1146b0c4ec fixes the black formatting.
yield from self._iterable_class(self, chunked_fetch=use_chunked_fetch, chunk_size=chunk_size)
The above line is of 101 characters, which was removed in the above commit.
!e
print(len(" yield from self._iterable_class(self, chunked_fetch=use_chunked_fetch, chunk_size=chunk_size)"))
@tired shard :white_check_mark: Your eval job has completed with return code 0.
101
running black timed out
on uvloop
what~
now it gets a change
Failed projects:
## django:
- Returned 1
- stdout:
/home/runner/work/black/black/src/black/mode.py:151: Deprecated: `experimental string processing` has been included in `preview` and deprecated. Use `preview` instead.
warn(
--- django/apps/config.py 2022-01-26 09:36:46.954337 +0000
+++ django/apps/config.py 2022-01-26 09:36:50.009526 +0000
@@ -59,10 +59,11 @@
return '<%s: %s>' % (self.__class__.__name__, self.label)
@cached_property
def default_auto_field(self):
from django.conf import settings
+
return settings.DEFAULT_AUTO_FIELD
@property
not on 3.6 and 3.7 though 😕
psf/black#2809 to the rescue 😅
nice, closing this then
yeah it'll probably be merged soon
Remove away. I feel we're regressing our test suite a little by missing some coverage primer gave us that diff shades does not, but it seems that's been deemed not useful to black contributors.
The left uvloop_test..yml is wasting cycles as it's not testing uvloop at all I think. So might as well remove it too and state we don't test uvloop.
Makes sense + makes CI pass.
Anything blocking this from being merged?
For the record when I said we could replace primer with diff-shades I meant we could replace the primer command / step in the pre-existing primer workflows for diff-shades analyze (and then also diff-shades show-failed --check), but I won't object to removing the workflows altogether if we deem the platform and Python version coverage not necessary.
Aww thank you! you can see https://github.com/psf/black/graphs/contributors and https://github.com/psf/black/blob/main/AUTHORS.md for data on the contributors 😄
hmm why is the version zero-ed out? https://black.readthedocs.io/en/latest/
odd, did that break recently?
checking the documentation build logs right now
it's also appearing in test CI
Successfully installed aiohttp-3.8.1 aiosignal-1.2.0 async-timeout-4.0.2 asynctest-0.13.0 black-0.1.dev1+gb517dfb charset-normalizer-2.0.10 click-8.0.3 dataclasses-0.8 frozenlist-1.2.0 idna-3.3 idna-ssl-1.1.0 multidict-5.2.0 mypy-extensions-0.4.3 pathspec-0.9.0 typed-ast-1.5.2 yarl-1.7.2
maybe because I put the pip install -e in the uvloop test
though how does that affect RTD?
I have no idea, I suspect it's a setuptools-scm issue
orr a problem with recent setuptools 60 release?
their last release was Jan 16
hmm I wonder the problem is the tag is not cloned because we surpassed the 50 clone depth RTD defaults to.
and actually I know this is the reason why CI has a zeroed version, for my mypyc wheel build workflow I had to a full clone
the 0.1dev1 stuff also happens here in Shivansh's colour diff from a few days ago: https://github.com/psf/black/runs/4918827304?check_suite_focus=true
65
also we never updated the stable tag from 21.11b1 to 21.12b0
It has been 0.1.dev in test logs from a long time, https://github.com/psf/black/runs/4339088767?check_suite_focus=true#step:5:57
oh dear.
I'll do that now I guess
maybe the depth is actually 60?
no it literally says 50
if you check the log, it says --depth 50 
the 50th commit was https://github.com/psf/black/pull/2791 which I merged 5 days ago
updated the stable tag
I can reproduce the zeroing locally though doing git clone --depth 50 https://github.com/psf/black.git and then pip install .
We might have to just ask RTD to set a flag for our project for full clones. Not sure if they'd be open to that though.
Details Read the Docs project URL: https://readthedocs.org/projects/patchwork/ Build URL (if applicable): https://readthedocs.org/projects/patchwork/builds/8314815/ Read the Docs username (if appli...
https://github.com/readthedocs/readthedocs.org/issues/8839 they seem pretty responsive to turning on DONT_SHALLOW_CLONE
Details Read the Docs project URL: https://mlflow-rest-client.readthedocs.io/ Build URL (if applicable): https://readthedocs.org/projects/mlflow-rest-client/builds/15874675/ Read the Docs username ...
I'll open an issue
v
Details Read the Docs project URL: https://readthedocs.org/projects/black/ Build URL (if applicable): https://readthedocs.org/projects/black/builds/15896411/ Read the Docs username (if applicable):...
thank you!
cool, I should probably review this soon because I'm still thoroughly confused how this is supposed to work (which is going to be especially important for a diff-shades optimization I want to do one day)
I don't remember the discussion @ichard26 alludes to above. Could you provide some details on how existing tools (typed-ast, pyright, pyre, ...) interpret spaces in type comments?
I discovered https://github.com/pulls/review-requested and decided I should clear it out
basically typed-ast doesn't recognize stuff like # type : ignore so normalizing it to # type: ignore would change the meaning of the program to the type checker
although I can't find the discussion via discord search so I may have just made it all up 
maybe I didn't discuss it on discord but instead saw this diff and that's why I wrote the comment (although that has me concerned about my short-term memory)
#black-formatter message relevant bit
ah damn I missed it
thanks!
I would be redoing a psf/black#2527, breaking down the commit and making it a bit clean, should I keep the same style, or use what Felix proposed?
the problem, with the current method is that you can't use * in the path syntax
[tool.black-module.src.black.*] is invalid syntax
Describe the bug
If the user launching black doesn't have a home directory, black crashes
To Reproduce
$ docker run -u 1234 --rm -it python bash
I have no name!@9e8b6938d741:/$ python -m venv /tmp/venv
I have no name!@9e8b6938d741:/$ /tmp/venv/bin/python -m pip install black
WARNING: The directory '/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that direct...
Description
See #2813
Avoid crashing when the user has no homedir
Checklist - did you ...
- [x] Add a CHANGELOG entry if necessary?
- [ ] Add / update tests if necessary?
- [ ] Add new / update outdated documentation? < not applicable
Things left to discuss
Regarding the tests, I'm unsure what the best strategy is here. As far as I can tell, the current PermissionError path isn't tested, and the find_pyproject_toml function is not tested directly in the ...
Thanks for submitting!
If we wanted to be really careful, we could catch the error deeper and raise a custom one, since RuntimeError could result from other things as well. But because we print the message anyway it isn't a big deal.
But I wonder if we could write a test for this? Not sure what would be the best way though.
Nice. Love simple fixes and thanks for adding the explanations of the exceptions and what they normally mean.
We could test by writing a unit test and setting the os.eviron['HOME] = /not_exists and limit the test to only run when platform.system() == "Linux".
If that does not work mocking find_user_pyproject_toml() to throw a RuntimeError would also work ...
you mean flake8 W504s that? that's pretty clearly a bug in flake8
I think it's a joke 😅
ah, actually i thought it was black's
!pban 760540066656813067 racism
:incoming_envelope: :ok_hand: applied purge ban to @crude prairie permanently.
❯ set -x HOME /non-existent
thread 'main' panicked at 'Unable to create log dir "/non-existent/.cache/starship": Os { code: 13, kind: PermissionDenied, message: "Permission denied" }!', src/logger.rs:31:35
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
oops 
you're welcome for the suggestion
and now we can claim twitter driven development is a viable methodology :bird: :)
although minor note do we need to change the style docs or are we good? This feels minor so it probably doesn't need to be called out but then again completeness wouldn't hurt imo.
https://github.com/psf/black/pull/2549 is probably closable since your PR @dense jungle ?
yes, need to review it though
I think I'm going to have to edit the pyproject.toml on the fly to add diff-shades to the mypyc wheel build workflow to workaround pip build isolation issues, sigh
I've surprisingly never programmatically written TOML yet
sounds exciting
https://github.com/psf/black/pull/2572 could also use eyes!
I can't review it as I'm not familiar with this part of the codebase and honestly I'm also a bit pessmistic given Łukasz has spent countless hours trying to fix this instability and he hasn't been successful short of the run black twice hack.
I understand if this is disappointing but this is how it is personally. I too would like the run black twice hack to disappear but right now it just isn't my priority / what I want to spend my OSS time on.
sure, no worries! figured i'd mention, maybe some other maintainer has time to look at it. it does pass test cases and solves some issues… we could also merge the actual fix but keep the second pass around as backup if we're afraid of unknowns.
I just un-merge conflicted it and now we got a diff-shades report!
Like @bright glacier I'm a bit skeptical because Łukasz already spent a lot of time on this and decided it couldn't be done. But maybe he missed this approach! I'll have to spend some more time throwing more edge cases at it, but maybe we could use this to avoid the double run
Is it possible to use black t format my code while in GitHub actions?
Basically I want to have a GitHub actions that applies black to my code when a person pushed smth
pre-commit.ci can do that. it's set up that way in https://github.com/pycqa/flake8-pyi for example
I know it can but I'm looking for 2nd options
there was a proposed workflow that did this for PRs to psf/black (we never used it) https://github.com/psf/black/actions/runs/17913292/workflow
not sure if it still works @quartz magnet but it could be a good start
Pog
thanks
Fixes #2651. Fixes #2754. Fixes #2518.
This adds a test that lists a number of cases of unstable formatting
that we have seen in the issue tracker. Checking it in will ensure
that we don't regress on these cases.
do we need to actually call it torture?😄
something a bit more descriptive like "stability_torture" would be an improvement :)
"stability_stress_test" is also good
but nice we get to close three issues at once!
the sample from https://github.com/psf/black/issues/2563#issuecomment-950156159 is still unstable after two passes 😦
:O
We can merge psf/black#2799 now
I got to go offline, so if there's any new thing that pops up I'll be asleep by then
I'll merge it once it's green
that's very fun. looks like #2572 fixes it though!
https://github.com/psf/black/pull/2525 huh why is coveralls failing here, it says coverage dipped 
dipped by 30%
A Python autoformatter!
check the channel description :D
The uncompromising Python code formatter: https://black.rtfd.io/
Developers and users of Black are invited to use this channel for discussions on the development and usage of the tool.
Want to see Black in action? Try the "Black Playground" https://black.vercel.app/
Playground for Black, the uncompromising Python code formatter.
I'm having a look at the last failure
yeah
in the build it shows coverage increased
and then in the tree and stuff it says decreased
Maybe there's some merge weirdness
on top increased, and in change decreased
ye
Hmm, is there a button for rerunning all tests? I imagine we just send coverage info in our test runs
there is, one sec
or you can merge master real quick
or does the "rerun all jobs" run all other jobs, not just the ones in a particular action
ok yeah its just "rerun all jobs" which will rerun the workflow suite
you are rerunning or should i merge main?
if you're on, you can merge: that way we also rule out any some confusion by coveralls
done
fingers crossed
double commit
did i mess something up
still fails
I mean, it clearly has nothing to do with the PR
doesn't happen on main 🤷♂️
nor other recent PRs
curiously it is PyPy which fails
oh the nerves.... 😬 💦
git revert is always an option.
is it possible to run it locally?
the test?
yeah, will jsut run coverage locally
surely if you have pypy installed then yes
gotta setup pypy
weird, tox -e pypy3 crashes on my system 
how about coverage then?
yeah
wow
lol
damn
does anyone else use vscode + pylance and notice it taking up 100% cpu when working on black?
oh my, i just had the most confusing experience
nope, its just pypy acting weirdly when running test_blackd.py
so new ipython formats your repl using black (which y'know, bold choice)
but what was really confusing is i was using ipdb to put a breakpoint into black
and then getting totally, recursively flummoxed because ipdb was formatting my pdb prompts with black too!
bold move indeed
yeah, i've seen that issue and it is what it is 🤷♂️ but if i wasn't aware of it i think i'd be totally mystified right now. the symptoms were first seeing my breakpoint getting hit way more than i expected, and then seeing strings like 's\n' 'c\n' that didn't exist in my code
well they did say it is likely to get reverted
such an unfortunate discussion.. can't be nice to have a community pile on ya
anyway, now i know! don't use ipdb to debug any dependencies of ipdb! 😄
It turns out "simple_stmt" isn't that simple: it can contain multiple
statements separated by semicolons. Invisible parenthesis logic for
arithmetic expressions only looked at the first child of simple_stmt.
This causes instability in the presence of semicolons, since the next
run through the statement following the semicolon will be the first
child of another simple_stmt.
I believe this along with #2572 fix the known stability issues.
good morning folks 🌅
good morning richard :D, got buried up, if anyone figures this out, would be great
it happens locally also btw
with pypy3.7-7.3.7
Hmm, so it looks like we may have a stability fix but we're doing the stable release tomorrow and the stability fixes seem to change formatting quite a bit
technically we're in the clear as this would be a bug fix (which AFAIK is exempt from the stability policy) but to change formatting right after the stable release would not be a good look
!remind 1H fix changelog, there's a minor issue w/ py310
Your reminder will arrive on <t:1643386732:F>!
Yeah I'd excuse unintended style issues from stability
But what is it?
Could we get psf/black#2787 into the stable release if possible?
IMO no, it's exempt from the stability policy and I'd rather work on it properly.
yeah it is a exempt from the stability policy, but some pretty logs would be cool for a stable release
AFAIK Jelle has some concerns?
also fair :D
We've been waiting for two years for this stable release, I'd prefer if we don't rush things because they're cool
btw Richard, since you populated the stable project: would you like us to remove everything that doesn't make it, or have unfinished issues when we close the project?
Got to eat now but sure I can take a look later
jelle doesn't really have some concerns, it's just about the colour styling for one element, others are positive feedback
I can clean it, np, but just thought I'd ask
If you have anything against cleaning it up
fair enough my bad, I think it's just prudent to make sure we're not making black totally unreadable
I'll look into it today
we can't really take care of every possible configuration, we can possibly make the colours configurable though
well yeah I know, but I'd like to check the colors a little bit
yep 👍
I haven't reviewed the PR at all fwiw, only been following the email chain
Here's your reminder: fix changelog, there's a minor issue w/ py310
[Jump back to when you created the reminder](#black-formatter message)
Let's not do that. Stable formatting means stable formatting
We either make this change now or next January, that's the policy
(talking about the stability fix, the coloring thing can go in any time)
That's ok as well. I wanted to ask about that actually 😄 but this is the answer already. The stability policy is quite strictly worded.
yes, this is quite explicitly why I wrote it that way. If you upgrade Black within the same year, it will not reformat your codebase
The only exception is for code that it previously failed to format
We might want to introduce a "default" preview category then, so that we don't have a ton of features that we need to keep track of if we're sure that some change will be converted to stable
Like maybe halfway through this year we'll gain support for except* and that will be fine with the policy
ye
something that was unintended, but uncontroversial to add next year
Description
Closes #1256: I reworded our style docs to be more explicit about the style we're aiming for and how it is changed (or isn't).
Checklist - did you ...
- [x] N/A Add a CHANGELOG entry if necessary?
- [x] N/A Add / update tests if necessary?
- [x] Add new / update outdated documentation?
Description
Closes #2251: I've included a short Python support policy to our FAQ. TL;DR: we promise to support all non-EOL versions, but don't promise to keep old 3+ versions laying around if we decide to remove them at some point.
Checklist - did you ...
- [x] Add new / update outdated documentation?
Some discussion:
- Is the content fine? It's basically what we do now, or at least the least strict and most convenient version of it. We could promise a depre...
Nice. Agree with it all. Thanks!
Resolves #2784
Additionally tested against typeshed with black --diff ~/dev/typeshed
I added the new test cases in their own commit with the previous behaviour, to make it easy to see how these changes affect them.
is there a way to use single quote strings instead of double quoted?
Nope, you will have to use a fork.
ok thanks
df0aeee Formalise style preference description (#2818) - felix-hilden
I removed black-primer from CI in #2809 because it was causing annoying and useless CI failures, but kept the code around to avoid unnecessary changes around the stable release. I'd like to keep it around for at least one release that marks it as formally deprecated.
How long should we keep it? Is there any reason to keep it around for longer?
Also, removing the primer tests lost us some platform coverage, because black-primer used to run on lots of OS and Python version combinations an...
95e77cb Fix arithmetic stability issue (#2817) - hauntsaninja
Are we merging the other stability fix? I haven't looked at it all yet so I'd hope you have
probably. I was going to look at it some more next
just merged main into it and removed double formatting from the branch
let's see if it works on torture.py
I still need to fix a changelog entry fyi - I've just been distracted working on the ghstats website I've shown before
sure, we're not releasing yet 🙂
it doesn't actually
E +++ second pass
E @@ -23,13 +23,13 @@
E
E
E class A:
E def foo(self):
E for _ in range(10):
E - aaaaaaaaaaaaaaaaaaa = (
E - bbbbbbbbbbbbbbb.cccccccccc(xxxxxxxxxxxx) # pylint: disable=no-member
E - )
E + aaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbb.cccccccccc(
E + xxxxxxxxxxxx
E + ) # pylint: disable=no-member
https://ichard26.github.io/ghstats/ and here it is! @dense jungle you're hands down winning the race now
there's still 300 open issues that you can close 🙂
yeah, just gotta treat psf/black a full time job 
^ let's do this?
I mean, I'm still woefully underexperienced to properly review it but I can look over it at least
I don't actually know how Black works either
not a big fan of these formatting changes but then there's argubly improvements in other areas
this is nice imo.
yeah ok this one is pretty ugly but oh well
yes, I feel like our formatting in this area is pretty ad hoc in general
it's just different iterations of the logic coming out in different ways and making things a little worse or better
I understand why in hidesight Łukasz said the best thing would've been to avoid touching parenthesizes as much as possible - rather finicky to get "right"
unless I'm totally misquoting him 😅
#black-formatter message nope, I did not.
would wonder how that'll work with line breaking though since we still need to keep line length under control, but I guess all of this is ad hoc and this is an extension of it
I don't know if I agree with that sentiment, managing parentheses is an important job of a formatter
Btw, out of the context, but the psf/black#2795 is waiting for https://github.com/FFY00/python-resolver/pull/5 to be merged
nothing concerning jumps out to me other than those formatting changes I noted above so I guess time to trial it IRL and see how many issues we get
?
I am fine with the other two changes, not really liking this change though ^
I should probably stop looking at black now, I'm just getting frustrated for no good reason reading through all of the related discussion.
Maybe we could merge 2525 unless richard wants to have a look at it.
I mean, it doesn't matter eitherway at this point since I won't be rejecting it
still 100% confused how it works but when I get to fix bugs in this domain I'll get to understand it
the docs didn't help?
nope.
oh well, basically its like class inheritance, you have two files A and B, where A inherits B, so originally A is a clone of B, but then when you specify additional properties to A (in its file) it would overwrite the properties it got from B
say this is B ```toml
[tools.black]
color = false
line-length = 88
target-version = ['py36', 'py37', 'py38']
this is A ```toml
[tools.black]
config = "linked_config.toml"
this would result in a ditto clone of B
OK ok I get it, to be completely honest, I just want to ignore OSS work right now
I didn't actually read the updated docs
they're pretty clear although I have a minor suggestion
ok yeah, atleast you got it :D
yeah?
oh whelp, i forgot about the failing pypy coverage
no idea why that happens
lol yes, it happened again
the interesting thing is that in the header on coveralls site it shows increased but in the changed tab (on the site) it shows dipped
somehow it's failing consistently on this PR but not others though
hmmm
yeah
nope, i didn't get that earlier
okay now i am getting it
maybe report this to coveralls?
oops, sorry gtg
i don't understand the pypy coverage drop either
I did not do a hands-on test as I'm far too annoyed right now to do so but here's some initial feedback. We also need to check the pypy coverage drop.
OK, I'm actually signing off for at least the next 30 minutes.
Thanks!
(I realize I was wrong on Discord earlier, I was confusing this case with the other one. Sorry for that!)
the #2572 change doesn't affect too much code: 21 files reformatted, 14320 files left unchanged.
hey guys me and my friend have some ideas about web application we are thinking of making one so if anyone interested in joining
pls contact me
We originally need people who work on python,HTML5,css and JavaScript
(This is not a Job, and no one is getting paid )
this is not the channel for that mate
So where can I post this ?????
Not sure where (if anywhere on this server) it is appropriate, but this channel is for discussing Black's development
I can't believe this got fixed, I'm so happy about it!
I wonder how long it will take to get someone complaining about having to use —preview to get the latest formatting …
Let's create an issue for getting rid of the stability policy, shall we 😜
Description
Even people browsing PyPI using its search filter shall know Black is now stable 😎
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
The time has come. Long time since @ambv showed me black working on his laptop @ work in late 2017 or 2018?
8acb854 Update classifiers to reflect stable (#2823) - ichard26
we could also close 2188 since it would be included in the next stable release...
I think it's useful to keep open to track issues with the feature