#black-formatter

1 messages · Page 30 of 1

errant barn
#

because surely an empty dict can have an arbitrary mapping!

tired shard
#

so jelle and vivax suggested use of typeddict from typing extensions

errant barn
#

sure then :D

tired shard
#

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?

errant barn
#

dunno 🤔

tired shard
#

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

delicate marsh
#

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

tired shard
indigo dagger
#

Hey everyone!

#

Just wanted to ask if there's a compatibility matrix of black versions and python versions somewhere?

dense jungle
dense jungle
#

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

tired shard
indigo dagger
#

Any idea when 22/~stable~ is dropping?

dense jungle
#

before the end of the month. Felix tentatively suggested 1/29

indigo dagger
#

oh sweet

#

We've been stuck on 19.10 for no reason for, well, a while

tired shard
#

i had probably wait that PR until the last

dense jungle
#

yeah I might need to do it again

tired shard
#

so in case some other changelogs come they could be merged into that

dense jungle
#

happy to resolve any merge conflicts though

tired shard
#

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

tired shard
#

on psf/black#2360,

it treats SRC ... items as lines of code if --code was passed (new with this issue)
Does this basically mean that if --code flag is passed along with a SRC let's say code then it would just read the code from SRC and output the formatted code to stdout?

toxic stormBOT
tired shard
#

But wouldn't this become a bit unfriendly if we pass multiple SRCs?

#

CC @errant barn

plain atlas
delicate marsh
#

maybe, it was 1am

tired shard
#

just saw the issue

tired shard
#

that just partially addresses the issue

#

it doesn't handle the min version checker feature

#

probably worth opening a separate issue for tht

dense jungle
#

yes that's more of a nice to have. this is the thing we definitely need to do before the release

tired shard
dense jungle
#

having to maintain a separate min requirements file sounds fragile though

tired shard
#

yeah

#

I don't think someone has already built this, atleast from a quick google and github search

dense jungle
#

kind of surprising, it seems widely useful, maybe as a feature in tox or something

tired shard
#

related

dense jungle
#

here's your chance to build a widely used dev tool 🙂

tired shard
#

😄 Maybe

#

going to give it a shot, lets see

#

python-poetry/poetry#3527

tired shard
#

very related

#

pypa/pip#8085 👀

errant barn
#

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

flat krakenBOT
#

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?
bright glacier
#

gosh the contents sidebar is so nice in furo

flat krakenBOT
#

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...
neon loom
#

Are we going to remove the "beta" product this month?

bright glacier
#

Yeah, someone just needs to do that before we release, presumably the same time Jelle lands the changelog reorganisation.

neon loom
#

kk - See if I get time to get the PR ready today

bright glacier
#

!remind 3H assist mark with the stubs newline thingy

late dewBOT
#
Can do!

Your reminder will arrive on <t:1642818760:F>!

little parrot
#

gosh this is lovely @bright glacier

tired shard
late dewBOT
tired shard
#

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?

toxic stormBOT
flat krakenBOT
#

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...

tired shard
#

@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

dense jungle
tired shard
#

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

dense jungle
#

I wonder if we can move away from setup.py

#

e.g. use flit and configure in pyproject.toml

tired shard
#

move it to requirements.txt and read from it in setup.py, could also be an option

bright glacier
#

Probably not impossible but it sounds annoying but yeah I do wish we could use flit and pyproject.toml, so much nicer tooling

tired shard
#

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?

bright glacier
#

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)

bright glacier
#

core black doesn't have any but blackd does via aiohttp

#

oh yeah and the juypter has a bunch of transitive dependencies lemon_sweat

tired shard
#

they are part of extras right?

bright glacier
#

yeah I forgot to add the word 'extra'

#

it could be argued pinning transitive dependencies to their lowest bounds is not worth it fwiw

tired shard
#

other than pinning any downsides? pinning could be automated

bright glacier
#

what?

#

I was talking about we could either test the lowest versions of only direct dependencies or all dependencies

tired shard
#

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)

bright glacier
#

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

tired shard
#

ah right, i took it in a different way

tired shard
#

config PR 👉 👈

elder tusk
#

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?

dense jungle
tired shard
#

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

flat krakenBOT
elder tusk
#

^this PR shouldn't need a changelog entry. Do I add one anyway or is there a better way to make CI happy?

tired shard
#

skip news label could be added

#

(by the maintainers)

elder tusk
#

thanks! ^PR to mention that label in the CI action 🙂

flat krakenBOT
plain atlas
#

i am not a fan of the new docs theme

little parrot
#

Why?

bright glacier
#

hmm pithink

flat krakenBOT
#

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...

bright glacier
#

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.

little parrot
#

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?

little parrot
#

ah

bright glacier
#

for example some people with visual impairments need bigger fonts and indentation width can fall under that too

dense jungle
#

I feel like it should be possible to customize display for spaces too

bright glacier
dense jungle
#

but pretty much everyone indents with spaces, so surely tools for visually impaired coders need to deal with spaces?

bright glacier
#

Yeah.

#

I wonder if there's a VSCode extension for this, it sounds like something that would exist by now

plain atlas
#

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.

tired shard
#

that was fast

plain atlas
#

alabaster was better imo

bright glacier
#

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

silent apex
#

Really? I find furo a lot prettier than alabaster.

#

Not that it really matters.

bright glacier
#

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

sturdy radish
#

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

elder tusk
#

(mypy will never yell at you for line length, do you mean flake8 or something?)

sturdy radish
#

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.

elder tusk
#

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.

worn pier
#

hey, i am trying to use blackd but the command is not working, i have used pip install black[d] (windows 10)

elder tusk
#

you might need to quote black[d] to please your shell, e.g. pip install 'black[d]'

tired shard
worn pier
tired shard
#

psf/black#458 and psf/black#379

tired shard
worn pier
#
C:\Users\l4sti>pip install 'black[d]'
ERROR: Invalid requirement: "'black[d]'"

C:\Users\l4sti>
tired shard
#

and without the quotes? ideally it should be removing this quotes when it tries installing

worn pier
#

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.
tired shard
#

its black[d]

worn pier
#

same error

#
C:\Users\l4sti>black[d]
'black[d]' is not recognized as an internal or external command,
operable program or batch file.
tired shard
#

now you installed it with a b

#

do pip install black[d]

#

and then blackd should work

worn pier
#
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

tired shard
#

you use [] syntax to specify extras when installing with pip

worn pier
#

o okay, i read your message wrongly then before

tired shard
worn pier
#

but blackd doesnt work either

worn pier
#
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
tired shard
#

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.)

worn pier
#

a okay so that is fine, if i specify a port and stuff it should work?

worn pier
worn pier
tired shard
#

not sure, maybe @neon loom would know about this

worn pier
#

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)

worn pier
tired shard
#

python -m blackd --bind-port 9090 doesn't work?

worn pier
#

nope

worn pier
#

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

tired shard
#

oh screw that sorry,yeah it should be blackd --bind-port 9090, but you are saying it doesn't work even after restart pithink

worn pier
#

going to the blackd.exe and then running blackd.exe --bind-port port works but that aint the way, is it?

tired shard
#

it shouldn't be, not sure how windows binaries though

errant barn
#

Can't imagine why it isn't found if black is found

#

Is the error still the "not found" if you start "blackd"?

worn pier
#

if i type just black or blackd it does not work, only if i use python -m black works

errant barn
#

Oh!

worn pier
#
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

tired shard
#

yeah python -m won't work with blackd

errant barn
#

Do you use a virtualenv of some sort?

worn pier
#

i installed it system wide

tired shard
#

psf/black#1558 looks related (same issue)

toxic stormBOT
worn pier
#

just opened cmd, and entered pip install

tired shard
#

but the solution was -m

errant barn
#

Could you try using one so we can get an isolated install?

tired shard
#

richard has a different solution commented though, not sure if that would work, but worth a try ig

worn pier
#

sure, ill install it in a venv

tired shard
#

do any other cli applications work?

worn pier
#

all of them except i tried using patool but that one doesnt work

tired shard
#

weird, could you paste your $PATH

worn pier
#
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
errant barn
#

Hmm, I can't see Python in there

tired shard
#

yeah ^

errant barn
#

but running python works?

tired shard
#

which python what does this show

worn pier
#

blackd in venv does work

tired shard
#

yep, path issue

worn pier
#

which python does not work, but running python works

tired shard
#

python -m site --user-base what does this output?

worn pier
#

i think that is because i use the windows store installation and not the the one from python.org

tired shard
#

(Trying to get python location, so we can add it to path)

#

oh

#

no idea then

worn pier
#
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

errant barn
#

definitely try a conventional install then :D

tired shard
#

then go inside bin folder

#

and see blackd is present in it

#

if it is, add that path to $PATH

worn pier
#

blackd is present in scripts, i can run blackd.exe just fine

#

switching to a none windows store version solved all my issues

tired shard
#

awesome 👍

worn pier
#

thanks for the help guys!

tired shard
#

your welcome 😄

errant barn
#

gotta remember that's a thing then so we can recommend against it

worn pier
#

or microsoft just fixes it.. the easiest solution for the many

tired shard
#

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

errant barn
slow ibex
tired shard
#

oh well well smh 🤦

tired shard
errant barn
#

could they be the exponent of a power? or the whole expr?

tired shard
#

doesn't like exponents, see that screenshot i psoted, the statement is 5 .bit_count()

errant barn
#

"a ** (5).bit_count()"?

tired shard
#

no just that

errant barn
#

oh

#

honestly no idea

tired shard
#

oh wait, i can just check the grammar file

late dewBOT
#

src/blib2to3/Grammar.txt line 156

power: [AWAIT] atom trailer* ['**' factor]```
tired shard
#

ok yeah, its method calls and **

flat krakenBOT
tired shard
#

tada, done

bright glacier
#

Welcome to the confusing mess that is the blib2to3 grammar

neon loom
late dewBOT
#

Dockerfile line 9

&& pip install --user --no-cache-dir .[colorama,d]```
bright glacier
#

We should probably add __main__.py if it doesn't exist already

dense jungle
#

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 ...

little parrot
#

I'd also really like this

tired shard
#

Spent too much time trying out different methods but finally got stuck with regex

#

psf/black#2067

tired shard
#

oh wow, that issue was opened on a very very nice date

flat krakenBOT
bright glacier
#

if someone could test this locally python -m blackd --help that'd be wonderful since I made this change on the web.

bright glacier
#

although I have never used mindeps so I don't know if it works for our usecase

flat krakenBOT
tired shard
#

@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

dense jungle
tired shard
#

oh didn't you say it isn't needed for hexdecimals and exclusive complex numbers?

dense jungle
#

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

tired shard
#

umm, i am kinda inclined towards not having them, since they are really redundant, 0x10.real is pretty clear

dense jungle
#

sure

#

how about 10.5e273.real

tired shard
#

isn't that float?

#

yep

dense jungle
#

oh I guess that's like other floats

#

10.5.real is syntactically valid

tired shard
#

yep

dense jungle
#

it's just for ints you need the space or parens

tired shard
#

yeah

#

but like i said in my comment, its pretty confusing

#

the two dot operators

#

() are nice there

dense jungle
#

yes agree

tired shard
#

can't find the relevant section of code

dense jungle
#

I think blib2to3 nodes have a suffix or something?

#

sorry, bedtime for me

tired shard
#

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

tired shard
#

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 pithink

flat krakenBOT
errant barn
#

Nice! How's the help output?

tired shard
flat krakenBOT
tired shard
#

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)

errant barn
#

Well I'd argue that if we do this then why not do it for other flags as well :D

tired shard
#

hmm yeah, but i would need to patch click for that 🙃

errant barn
#

What do you mean? For the invisible aliases?

tired shard
#

yeah

errant barn
#

oh, then might not be worth it

tired shard
#

but it isn't really hacky, i will give it a shot tomorrow, gtg for now 👋

flat krakenBOT
proper oyster
#

is this channel for hacking?

errant barn
#

It's for the Black formatter, see channel info!

proper oyster
#

oh

gusty grail
#
  1. Optionally, run Black on every file save:
    Im referring to this part btw
errant barn
#

Hmm, isn't it right there?

#

6.1

gusty grail
#

oh wait, my bad

#

chronic case of being blind

#

sorry

errant barn
#

feel ya, my man

gusty grail
#

I shall now retreat to my shame cave

tired shard
flat krakenBOT
#

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...

golden swallow
#

yo how do i disable single quotes from turning into double quotes, auto editor changes it every time i run

errant barn
#

the editor, or black does? 😅

golden swallow
#

black i think

errant barn
#

we have black -S

#

which skips the normalisation

golden swallow
#

aight ill try that

#

thanks

#

:)

slow ibex
#

why black is converting hex literals to uppercase? 0xaa -> 0xAA for example
what is the reason?

errant barn
#

I think it's a common convention to write hex in uppercase

lament crow
#

0xDEADBEEF

dense jungle
#

we did change our mind on this a few times, you can look it up in the tracker

dense jungle
#

running the hug_power_ops branch on our codebase now

bright glacier
#

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 😄

dense jungle
#
+    unsigned_cases = [2**63, 2**64 - 1, (2**64 - 1, 0, 0, 2**64 - 1)]
#

pretty nice

bright glacier
#

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)

dense jungle
#

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

bright glacier
#

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

dense jungle
#

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
    
bright glacier
#

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.

dense jungle
#

yes, probably not worth changing

dense jungle
#
+            negative_feedback_penalty**negative_feedback_count
bright glacier
#

Gosh, I am no fan of referencing 10s of sources at once, this is going to take a while to fill out 😔

bright glacier
dense jungle
#

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

bright glacier
#

Yeah no, I'm very against that too.

dense jungle
#

ok it's done 135 files changed, 251 insertions(+), 251 deletions(-)

#

let's land the change

bright glacier
#

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.

dense jungle
#

wait I can

#

caused by the power hug change

dense jungle
#

but now my test for the fix hits a different stability bug 😦

bright glacier
#

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

dense jungle
#

yeah I'm fixing it properly now

bright glacier
#

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

dense jungle
#

doesn't seem to break anything

bright glacier
#

hmm I wonder if my checkout was dirty then

dense jungle
#

possibly because I only fixed opening_bracket and not bracket_depth

bright glacier
#

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

flat krakenBOT
bright glacier
#

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

dense jungle
#

yes 😦

dense jungle
#

it seems to also only happen if the transformer runs and the line gets split up

bright glacier
#

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
bright glacier
#

I only somewhat wrapped my head around it today 🙂

dense jungle
#

hm the magic trailing comma hack where we format twice doesn't really work, it doesn't actually output the twice-formatted code

bright glacier
#

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

dense jungle
#

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

bright glacier
#

what are these changes for? I'm just wondering if this could change formatting

#

oh wait probably mypy pleasing

dense jungle
#

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

bright glacier
#

Hmm, can't reproduce the secondary failure.

#

I probably broke my install somehow.

dense jungle
#

should happen if you remove the fast=False from the test I added

flat krakenBOT
bright glacier
#

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.

dense jungle
#

this diff shouldn't change performance, we were already doing the second pass but throwing away the result

bright glacier
#

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

dense jungle
#

format_str doesn't call check_ast_and_stability, it's further up

bright glacier
#

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
dense jungle
#

oh yes, it would call it another time in assert_stable

#

we could probably avoid that if we really wanted

bright glacier
#

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

unique mulch
#
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

unique mulch
errant barn
#

Yep!

errant barn
#

@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.

toxic stormBOT
dense jungle
errant barn
#

currently I mean

#

Maybe I'm still misunderstanding

dense jungle
#

no, because of the way the stable check is currently written

errant barn
#

But to me "internal error" -> bug report is better than masking them

#

oh!

dense jungle
#

we don't abort if it's stable after the second format

errant barn
#

OH

dense jungle
#

so right now we just produce unstable output silently

errant barn
#

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

dense jungle
#

yes. and I'm pretty sure we meant to actually run it twice

errant barn
#

right, so then this is indeed better

#

but not better than truly just running once :D

dense jungle
#

psf/black#2126

dense jungle
errant barn
#

yeah that's the rub isn't it :D but now we at least can make this change

flat krakenBOT
#

<!--
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:

  1. Update Black's version if a newer release exists: pip install -U black
  2. Use the online formatter at , which will use
    the latest main branch.
  3. 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 `...
outer musk
#

qq - Can I mark a directory to be ignored by black for formatting? Some special .black or something that lives along with the code?

dense jungle
flat krakenBOT
#

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.

dense jungle
#

!remind 8h make a PR that adds unit tests to black based on the code that changed in the diff-shades output for #2807

late dewBOT
#
I'll allow it.

Your reminder will arrive on <t:1643171583:F>!

muted haven
#

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)

bright glacier
#

lemme check my local benchmark data and calcuate the ratios

#

.., because yes I do have this information just laying around 😅

muted haven
#

haha, amazing! I was going to do it by myself, but just wondered in case you or Jelle knows this already.

bright glacier
#
                    [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)

dense jungle
#

interesting, so in general parsing is ~50% of total time?

errant barn
#

Interesting, so about 30-50 % parsing

bright glacier
#

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.

silent apex
#

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?

bright glacier
#

probably LibCST, which we may end up switching to as our main parser and CST but that be a full rewrite of the project 😔

muted haven
# bright glacier most of the overhead in the parser is in addtoken which is why I made a lot of c...

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).

GitHub

The previous PRs successfully optimized the backtracking in the factor of 4X. It might make some sense to profile and see whether there are still other potential bottlenecks.

bright glacier
#

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)

silent apex
muted haven
#

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)

bright glacier
dense jungle
#

that feels a little risky, in case the parse tree doesn't properly roundtrip with the source code

bright glacier
muted haven
dense jungle
bright glacier
#

well we do ignore parenthesizing del targets right as it changes the AST IIRC?

dense jungle
#

actually I think this should be safe, if there's a bug the later stability and equivalence checks will catch it

dense jungle
bright glacier
#

yeah I just remembered that, sigh

muted haven
muted haven
bright glacier
#

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)

dense jungle
#

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

bright glacier
#

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 🙂 )

dense jungle
#

it's great, it was helpful to see a few changes from the run-twice PR

bright glacier
#

@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).

muted haven
dense jungle
#

what do we still need primer for again?

bright glacier
#

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

dense jungle
#

I'd much prefer that over having to change true to false in primer.json every so often 🙂

neon loom
#

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

flat krakenBOT
flat krakenBOT
#

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.

bright glacier
#

nice work :)

neon loom
#

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 👌

bright glacier
#

as if you didn't need more home automation, mr. "I have too many IoT devices" lemon_sweat

#

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!

dense jungle
#

^ sorry I changed my mind

bright glacier
#

!remind 18H review psf/black#2799 and that bugfix for your (broken) power hugging code

late dewBOT
#
Absolutely!

Your reminder will arrive on <t:1643235799:F>!

late dewBOT
flat krakenBOT
#

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...

potent remnant
#

ooops sorry just read the channel description

errant barn
#

no worries!

tired shard
#

Uhh there is a bug with primer

#

two processes using the same file

#

if i am reading that correctly

flat krakenBOT
tired shard
#

!e

print(len("        yield from self._iterable_class(self, chunked_fetch=use_chunked_fetch, chunk_size=chunk_size)"))
late dewBOT
#

@tired shard :white_check_mark: Your eval job has completed with return code 0.

101
tired shard
#

running black timed out pithink 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 😕

errant barn
#

psf/black#2809 to the rescue 😅

toxic stormBOT
tired shard
#

nice, closing this then

errant barn
#

yeah it'll probably be merged soon

flat krakenBOT
mint barn
#

I love black

#

its amazing

#

thanks to whoever put any work into it

flat krakenBOT
#

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.

bright glacier
flat krakenBOT
flat krakenBOT
bright glacier
dense jungle
bright glacier
#

checking the documentation build logs right now

bright glacier
#

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

dense jungle
#

maybe because I put the pip install -e in the uvloop test

#

though how does that affect RTD?

bright glacier
#

I have no idea, I suspect it's a setuptools-scm issue

#

orr a problem with recent setuptools 60 release?

dense jungle
#

their last release was Jan 16

bright glacier
#

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

dense jungle
#
      65
#

also we never updated the stable tag from 21.11b1 to 21.12b0

bright glacier
#

what's weird is that RTD logs show it only broke two days ago

tired shard
dense jungle
dense jungle
#

no it literally says 50

bright glacier
#

if you check the log, it says --depth 50 pithink

dense jungle
#

updated the stable tag

bright glacier
#

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.

bright glacier
dense jungle
#

I'll open an issue

#

v

bright glacier
#

thank you!

bright glacier
#

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)

flat krakenBOT
dense jungle
bright glacier
#

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 pithink

#

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)

frigid grotto
bright glacier
#

ah damn I missed it

dense jungle
#

thanks!

tired shard
#

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?

toxic stormBOT
tired shard
#

the problem, with the current method is that you can't use * in the path syntax

#

[tool.black-module.src.black.*] is invalid syntax

flat krakenBOT
#

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...
flat krakenBOT
#

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 ...

flat krakenBOT
flat krakenBOT
errant barn
#

Wait, how?

#

Oh the slash :D

dense jungle
#

you mean flake8 W504s that? that's pretty clearly a bug in flake8

errant barn
#

I think it's a joke 😅

plain atlas
glacial gate
#

!pban 760540066656813067 racism

late dewBOT
#

:incoming_envelope: :ok_hand: applied purge ban to @crude prairie permanently.

bright glacier
#
❯ 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 lemon_sweat

dense jungle
flat krakenBOT
bright glacier
bright glacier
#

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

dense jungle
#

sounds exciting

elder tusk
bright glacier
#

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.

elder tusk
#

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.

dense jungle
#

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

quartz magnet
#

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

dense jungle
quartz magnet
#

I know it can but I'm looking for 2nd options

bright glacier
#

not sure if it still works @quartz magnet but it could be a good start

quartz magnet
#

Pog py_guido thanks

flat krakenBOT
bright glacier
#

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!

dense jungle
bright glacier
#

:O

tired shard
#

We can merge psf/black#2799 now

tired shard
#

once the check parses

#

thanks for the reviews guys :D

bright glacier
#

I got to go offline, so if there's any new thing that pops up I'll be asleep by then

dense jungle
tired shard
#

yep thanks

#

oh also richard asked about the style docs

elder tusk
tired shard
#

dipped by 30%

flat krakenBOT
frail aspen
#

What is this?

#

What is a black formatter

errant barn
#

A Python autoformatter!

tired shard
#

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.

errant barn
#

I'm having a look at the last failure

tired shard
#

even i did, couldn't figure it out 😔

#

try running that workflow again

errant barn
#

"Coverage increased" xD

#

What a failure.

tired shard
#

yeah

#

in the build it shows coverage increased

#

and then in the tree and stuff it says decreased

errant barn
#

Maybe there's some merge weirdness

tired shard
#

on top increased, and in change decreased

errant barn
#

ye

#

Hmm, is there a button for rerunning all tests? I imagine we just send coverage info in our test runs

tired shard
#

there is, one sec

errant barn
#

or you can merge master real quick

errant barn
tired shard
#

ok yeah its just "rerun all jobs" which will rerun the workflow suite

#

you are rerunning or should i merge main?

errant barn
#

if you're on, you can merge: that way we also rule out any some confusion by coveralls

tired shard
#

done

errant barn
#

fingers crossed

tired shard
#

double commit pithink did i mess something up

errant barn
#

wait, what 😄

#

well the changes look identical, so we're aight

tired shard
#

still fails

errant barn
#

I mean, it clearly has nothing to do with the PR

tired shard
#

doesn't happen on main 🤷‍♂️

errant barn
#

nor other recent PRs

#

curiously it is PyPy which fails

#

oh the nerves.... 😬 💦

#

git revert is always an option.

tired shard
#

is it possible to run it locally?

errant barn
#

the test?

tired shard
#

yeah, will jsut run coverage locally

errant barn
#

surely if you have pypy installed then yes

tired shard
#

gotta setup pypy

tired shard
#

weird, tox -e pypy3 crashes on my system pithink

errant barn
#

does pytest work?

#

I mean testing outside of tox

tired shard
#

yeah it works when running manually

#

ok seems like -n auto was incorrectly detected

errant barn
#

how about coverage then?

tired shard
#

yeah checking that rn

#

falls to 63%

errant barn
#

oh yikes

#

and the test result is fine?

tired shard
#

yeah

errant barn
#

wow

tired shard
#

lol

errant barn
#

damn

tired shard
#

gonna run pytest on main once

#

comparing the coverage result

elder tusk
#

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

tired shard
elder tusk
#

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!

errant barn
#

bold move indeed

tired shard
elder tusk
#

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

errant barn
#

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

elder tusk
#

anyway, now i know! don't use ipdb to debug any dependencies of ipdb! 😄

flat krakenBOT
#

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.

flat krakenBOT
bright glacier
#

good morning folks 🌅

tired shard
#

it happens locally also btw

#

with pypy3.7-7.3.7

bright glacier
#

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

late dewBOT
#
Of course!

Your reminder will arrive on <t:1643386732:F>!

errant barn
#

But what is it?

tired shard
#

Could we get psf/black#2787 into the stable release if possible?

toxic stormBOT
errant barn
#

Yeah that'd be cool

#

I'm on for tonight, so it's time for final additions

bright glacier
#

IMO no, it's exempt from the stability policy and I'd rather work on it properly.

tired shard
#

yeah it is a exempt from the stability policy, but some pretty logs would be cool for a stable release

bright glacier
#

AFAIK Jelle has some concerns?

bright glacier
errant barn
#

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?

bright glacier
#

Got to eat now but sure I can take a look later

tired shard
#

jelle doesn't really have some concerns, it's just about the colour styling for one element, others are positive feedback

errant barn
#

I can clean it, np, but just thought I'd ask

#

If you have anything against cleaning it up

bright glacier
#

I'll look into it today

tired shard
#

we can't really take care of every possible configuration, we can possibly make the colours configurable though

bright glacier
#

well yeah I know, but I'd like to check the colors a little bit

tired shard
#

yep 👍

bright glacier
#

I haven't reviewed the PR at all fwiw, only been following the email chain

late dewBOT
obsidian gale
#

Helloo

#

What is this project

dense jungle
#

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)

errant barn
dense jungle
#

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

errant barn
#

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

dense jungle
#

Like maybe halfway through this year we'll gain support for except* and that will be fine with the policy

errant barn
#

ye

errant barn
flat krakenBOT
flat krakenBOT
#

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...
flat krakenBOT
green radish
#

is there a way to use single quote strings instead of double quoted?

bright glacier
#

Nope, you will have to use a fork.

green radish
#

ok thanks

flat krakenBOT
#

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...

bright glacier
#

Are we merging the other stability fix? I haven't looked at it all yet so I'd hope you have

dense jungle
#

probably. I was going to look at it some more next

#

just merged main into it and removed double formatting from the branch

bright glacier
#

I still need to fix a changelog entry fyi - I've just been distracted working on the ghstats website I've shown before

dense jungle
#

sure, we're not releasing yet 🙂

dense jungle
#
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
bright glacier
dense jungle
bright glacier
#

yeah, just gotta treat psf/black a full time job lemon_sweat

dense jungle
#

^ let's do this?

bright glacier
#

I mean, I'm still woefully underexperienced to properly review it but I can look over it at least

dense jungle
#

I don't actually know how Black works either

bright glacier
#

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

dense jungle
#

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

bright glacier
#

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 😅

#

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

dense jungle
#

I don't know if I agree with that sentiment, managing parentheses is an important job of a formatter

tired shard
bright glacier
# dense jungle ^ let's do this?

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 ducky_yellow ?

tired shard
bright glacier
#

I should probably stop looking at black now, I'm just getting frustrated for no good reason reading through all of the related discussion.

tired shard
#

Maybe we could merge 2525 unless richard wants to have a look at it.

bright glacier
#

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

tired shard
#

the docs didn't help?

bright glacier
#

nope.

tired shard
#

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

bright glacier
#

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

tired shard
#

ok yeah, atleast you got it :D

tired shard
#

oh whelp, i forgot about the failing pypy coverage

#

no idea why that happens

dense jungle
#

lol yes, it happened again

tired shard
#

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

bright glacier
#

as long no tests failed on pypy I wouldn't worry too about it

#

coverage is messy

dense jungle
#

somehow it's failing consistently on this PR but not others though

bright glacier
#

hmmm

tired shard
#

yeah

dense jungle
#

do you also see this?

tired shard
#

nope, i didn't get that earlier

#

okay now i am getting it

#

maybe report this to coveralls?

#

oops, sorry gtg

bright glacier
#

i don't understand the pypy coverage drop either

flat krakenBOT
bright glacier
#

OK, I'm actually signing off for at least the next 30 minutes.

flat krakenBOT
dense jungle
#

the #2572 change doesn't affect too much code: 21 files reformatted, 14320 files left unchanged.

mint barn
#

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 )

errant barn
mint barn
#

So where can I post this ?????

errant barn
#

Not sure where (if anywhere on this server) it is appropriate, but this channel is for discussing Black's development

red sedge
# flat kraken

I can't believe this got fixed, I'm so happy about it!

neon loom
#

I wonder how long it will take to get someone complaining about having to use —preview to get the latest formatting …

errant barn
#

Let's create an issue for getting rid of the stability policy, shall we 😜

flat krakenBOT
tired shard
#

we could also close 2188 since it would be included in the next stable release...

dense jungle