#black-formatter
1 messages · Page 24 of 1
!d signal
This module provides mechanisms to use signal handlers in Python.
I honestly have never installed a custom signal handler
it's neat for cleanup (trapping SIGTERM and friends)
modmail/bot.py lines 117 to 122
try:
# adds signal handlers so the loop is safely stopped
loop.add_signal_handler(signal.SIGINT, lambda: loop.stop())
# this one we may want to get rid of, depending on certain things, and just hard stop instead.
loop.add_signal_handler(signal.SIGTERM, lambda: loop.stop())
except NotImplementedError:```
Aren't they Unix only sadly enough? I mean that's better then nothing, but it won't help scale in that case
there are different signals for windows ig. SIGBREAK (only for win)
modmail/bot.py lines 130 to 133
try:
loop.run_forever()
except KeyboardInterrupt:
self.logger.info("Received signal to terminate bot and event loop.")```
@bright glacier so it seems the redirect is only slightly working. If I redirect output into a file, I can see what it caught
I wonder if the multi processing is hitting some open file descriptor limits
perhaps using an in memory file like object would fix it
are you redirecting both stderr and stdout?
Yeah that's expected
or just redirecting stdout
I modified the suppression code to:
@contextmanager
def suppress_output() -> Iterator:
with open('x.temp', "w", encoding="utf-8") as blackhole:
with redirect_stdout(blackhole), redirect_stderr(blackhole):
yield
both
is that only valid on 3.10?
wut
the dual with
with redirect_stdout(blackhole), redirect_stderr(blackhole)
or is that able to be done on 3.9 and before?
definitly doable on python 3.9 (I'm also running this code on 3.9)
I'm not sure what's up with click
But it doesn't seem to be outputting to stderr at all
Which is not a bug I want to try and debug today
Though I didn't change anything in diff-lib aside from editing black to always emit warnings
One somewhat hacky, somewhat not, fix would be to patch the echo function and explicitly specify the file
replacing os.devnull with an actual file nets me this
I wonder why it isn't outputting for me then
I even set the process count to 12 thinking maybe it was something due to the higher open file handlers you'd have with a quad-core but nope!
that missingspace bothers me so much, is there a pr to add it?
yes it's already fixed in main
ah cool
something that is annoying with being on windows is that I can't push changes to github as my PAT is stored on an ext4 drive ....
personal access token
just make a new one that expires in a few days
yeah I guess but that's also annoying lol
Ok something interesting, click isn't picking up my terminal as windows
¯_(ツ)_/¯
wtf
So it's returning an incorrect file handler for stderror
are you using mginw bash / git bash on windows or something?
what script are you running to query click, lemme run it on my windows install
if i was more familar with click i could probably help better
haven't written the cli for my project that I intend to write some time
Nothing, just hopped into my site-pacakges, modified the if to print, and ran diff-shades lol
and it worked magically lol?
Well, yeah I saw my print in the output, benefits of modifying site
I wonder if patching at the file handler level would be work as a workaround to click's weird interaction with sys.std*
The thing is, I can copy the code click uses to determine os, and run it in a repl
But for some reason, it's returning False when running
You know what, ignore all what I said
I had my prints backwards lol
src/click/utils.py lines 249 to 253
if file is None:
if err:
file = _default_text_stderr()
else:
file = _default_text_stdout()```
src/click/_compat.py lines 610 to 612
_default_text_stdin = _make_cached_stream_func(lambda: sys.stdin, get_text_stdin)
_default_text_stdout = _make_cached_stream_func(lambda: sys.stdout, get_text_stdout)
_default_text_stderr = _make_cached_stream_func(lambda: sys.stderr, get_text_stderr)```
seems to be cached on initialization?
although this doesn't explain why it's working on linux and my windows
what windows version
10
10
Where are the days of print("ERROR: {e}") 
welp i'm going to go mess around with click now
even though i have 200 different things on my todo list
including one issue with github actions removing a new line that gets added locally....
pre-commit istg
so I guess what stream black.output.err ends up writing to is totally unaffected by the patching of sys.std*
only for you obviously
smh i can't get figure out why one would use click over argparse, both are equally annoying /srs /hj
What's the value for file in your click?
how am I supposed to check that?
(sorry, I haven't been paying much attention, been reading click's source code)
Well, one way would be doing what I did and manually modifying the the click code
actually, it seems like you can't write things like click can
I've only used click because it's what I've been exposed to first (from psf/black duh)
i've only used argparse because i was making scripts and didn't want to have many dependencies
yea I would use argparse for that too but click is already installed in the majority of my environments lol due to black
a never-ending cycle
lmao
i do have black installed in this environment, along with several other things that use click
i'm also gonna take the time to express my happiness for standardized editable installs
they're so awesome
but for my pre-commit scripts I want to keep dependencies to a minimum
I keep forgetting to run install after each change. Why can't pyproject projects be installed as editable 
they can!
Go on lol
flit has had support for pep 660 for quite a while now
and I use it in development of diff-shades
and poetry does that automatically lol
!pypi flit
kthxbai
Hadn't realized my pip is so out of date
brb #dev-contrib
pip install -U pip
what version are you on, scale
are they awesome 👀
which is why I was confused
also lemme actually run with the modified click, was too distracted. ..
i'm too distractable
@tribal thistle
seems like it picked up the right stream on mine
What did you print?
src/click/utils.py lines 249 to 255
if file is None:
if err:
file = _default_text_stderr()
else:
file = _default_text_stdout()
# Convert non bytes/text into the native string type.```
hm, interesting
wtf happened to @toxic storm
.ping
Gateway Latency: 115ms
I guess this means I'll have to monkeypatch click.echo for the time being until we (ever) figure out why click is holding on the original stderr stream like it's the last slice of cake on your machine
problem with flushing?
well assuming that functools.partial does what I expect lol
I doubt it as it's printing to the totally wrong (read: unexpected) stream after the monkeypatching
there's nothing printed before the redirection so the buffers should be empty
@bright glacier tldr click is a lot easier to use than argparse
for simple things, argparse seems the way to go, but add any complexity or subcommands then use click
sigh, sorry for dragging you into this mess, what a confusing adventure into streams / file handlers & descriptors and what a mess they are
although i can actually see argparse useful for discord bots and adding flags and such to bot commands lol
what's even weirder is that I use suppress_output in a different function and click's output is captured as expected
even for scale
mfw doesnt use discord.ext.commands.flags
r message: i don't like their syntax
Hey @delicate hatch!
It looks like you tried to attach file type(s) that we do not allow (.pdf). We currently allow the following file types: .gif, .jpg, .jpeg, .mov, .mp4, .mpg, .png, .mp3, .wav, .ogg, .webm, .webp, .flac, .m4a.
Feel free to ask in #community-meta if you think this is a mistake.
hi
Describe the style change
When a list contains a comment and a single expression (in that order), the expression seems to be broken into multiple lines regardless of length.
Surely short expressions should be kept on one line regardless of surrounding context?
Examples in the current Black style
# in:
[
# 1 + 2 + 3,
4 + 5 + 6,
]
# out:
[
# 1 + 2 + 3,
4
+ 5
+ 6,
]
Desired style
# in:
...
Actually developing in vscode is still rather annoying as 1) my laptop is too slow to run it smoothly, and 2) I have to use the mouse so much more >.< compared to fish + vim
LOL - I pasted the totally wrong PAT for the username field and yet GitHub let me in via the password field :p
ci is still broken, I guess time to pin coveralls somehow
pretty sure it's provided by a docker image the coveralls-upload action uses
You can use the coveralls package from pypi directly
It’s basically the same interface, ‘coveralls’
the last time I tried to resetup coveralls it was painful (when we had to move off travis)
I suppose it's worth trying again 😄
Actually when things last broke for us in pydis, we just disabled failures from that action somehow I can’t fully remember
It’s such a pain
The coveralls went down completely and we just completely yanked it
Probably more a viable solution here, but fun to think about
is there a way to allow failure of a specific job step?
Yes but it’ll still be marked red with the cross
the whole workflow / job?
Well, it’ll fail just that one step, but that’ll propagate to mark the entire workflow, test suite, commit, and PR as failing
cool, so it's not usable then
Basically it’s only good if you want to do the next step even if one fails
Yeah lol
People have requested something like that which does not fail the action, to which GitHub responded with ^
The people just loved that
"no." - probably
Actually I don’t think that’s an official GitHub representative
developing black's action has been painful due to github's lack of quality polish
If you want to allow failures, you might be able to do it on the execution level
Configure the failure exit code to be 0, or catch other codes in some other way
honestly I'm not sure the coverage action is that helpful anyway
the action's output is out of order 99% of the time and on top of that you have to explicitly pass environment variables to the action when a normal workflow doesn't need it
how often do we use the results?
uhhh usually when you break coverage jelle 😄 /lh
I broke it? 🙊
No, when you drop it to 0 because obviously your code is just so damn good it needs no tests 😉
it's a reference to an exchange in our old messenger chat :)
presumably it was actually due to a poisoned cache or something
oh yes
you can't iirc that's deprecated
wait what.
or maybe that's the codecov uploader
Uhh considering it had an update like a couple weeks ago
And the maintainer is answering issues
yeah confused with codecov
Show coverage stats online via coveralls.io
!pypi codecov
codecov's uploader is deprecated
not coveralls
right and the reason i don't use coveralls is because A- had problems with it and B- doesn't support coverage 6.0 yet
I use codecov for my personal projects as I've had a much better experience with it w/ pypa/bandersnatch
just checked it, it apparently does support coverage 6.0 now
tldr the codecov package is deprecated
!pypi codecov
I mean it’s not deprecated yet
.github/workflows/ci.yml lines 44 to 47
- name: Upload coverage to Codecov
# If pushed / is a pull request against main repo.
if: (github.event_name == 'push' && github.repository == 'pypa/bandersnatch') || (github.event.pull_request.base.repo.full_name == 'pypa/bandersnatch')
uses: codecov/codecov-action@v2.1.0```
Also it’s a matter of just a bit of housekeeping to upgrade
yes, codecov is deprecated
the package*
Dude, read:
On February 1, 2022 this uploader will be completely deprecated
and the rest of that sentence:
and will no longer be able to upload coverage to Codecov.
I really don’t see how that goes against “it’s not deprecated yet”…
Or any part of this conversation
because 4 months from now it'll stop working?
true
got the docs for this, btw
https://docs.github.com/en/actions/creating-actions/setting-exit-codes-for-actions#about-exit-codes
seems like there's an indirect solution
depending on how the action is being ran, it may be possible to use an echo to fix it
or something
like uh
# random thing, help me
name: Totally Random Thing
on:
pull_request:
types: [created]
jobs:
build:
name: Example
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Upload to coveralls
run: |
python -m coveralls ; exit 0
```*this workflow is not complete*
something like that
python -m coveralls & exit 0 or python -m coveralls & true is usually what I use
<!--
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,python2];
...
Since the pattern matching feature is very experimental at the moment, would it make sense to only change the parser when the target-version is explicitly set greater than 3.10?
probably
can black replace strings like
"abcded...<long string>\npqrs..."
to
"""abcded...
pqrs...
"""?
would be useful for my friend, he's getting tons of flake8 line too long warnings because he used \n 💀
it will eventually split strings but it will do it differently than how you suggested
Something like this (I wrote that manually so the split place might be wrong + it depends on the line length limit)
# before
text = "veeeeery long string that could not possibly fit the line length limit without being split in at least two parts"
# after
text = (
"veeeeery long string that could not possibly fit the line length limit"
" without being split in at least two parts"
)
Personally (as a user, I'm not a maintainer of this project nor do I have any power over what it chooses to do :) ) I would still like some improvements to string processing before it stops being experimental, for example:
https://github.com/psf/black/issues/1467
and there are still some known bugs iirc which is why it's still experimental
I might be wrong about there still being known bugs, I haven't really been paying attention lately
@muted haven sorry about failing CI, I'll look into it when I get back home
Ah, thanks!
No need to rush, but thanks!
Is your feature request related to a problem? Please describe.
"Trojan Source Attacks" https://www.trojansource.codes/trojan-source.pdf can create a discrepancy between how code looks to reviewers and how it is interpreted by python.
Describe the solution you'd like
black is used by many python projects. It would be great if black could replace "Bidi overrides" with the appropriate escape characters that are visible to humans.
**Describe alternatives you've considere...
Oh wow 😲
If you need to test writing code in arabic, well I've got a keyboard or two to help with that 😛
If I want to find all instances like [1, 2, 3] and then rewrite them to [ 1, 2, 3 ], is there a good way to get Black to do this? I find the latter to be vastly more readable:
- Easier to see what the data structure is (e.g. list, tuple, set, etc.)
- Easier to read the first and last elements
- Especially easier within the context of function calls, so that it's easier to see that my_func([ 1, 2, 3 ]) is accepting a list as one parameter, rather than three separate parameters.
The...
Is your feature request related to a problem? Please describe.
The typical situation where this would be useful:
- The code is formatted using Black
- This splits a parenthesized expression into multiple lines because it's too long.
- The code is refactored.
- The parenthesized expression would now fit on a single line.
- But Black won't do that change, out of fear the split is intentional.
- Each line of the code has to be checked manually to find such occurrences.
**Desc...
An easily findable exhaustive list of flags would be great.
Isn't that just the help command, which is also in the docs
it's currently not that easily findable in docs but yeah, it is
heads up, i ran black and uh
wait
nope, error is still there
(was on 21.8b0, but now on 21.10b0)
/home/aru/.cache/pypoetry/virtualenvs/modmail-lmlBH83T-py3.10/lib/python3.10/site-packages/black/init.py:668: DeprecationWarning: There is no current event loop
loop = asyncio.get_event_loop()
!d asyncio.get_event_loop
asyncio.get_event_loop()```
Get the current event loop.
If there is no current event loop set in the current OS thread, the OS thread is main, and [`set_event_loop()`](https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.set_event_loop "asyncio.set_event_loop") has not yet been called, asyncio will create a new event loop and set it as the current one.
Because this function has rather complex behavior (especially when custom event loop policies are in use), using the [`get_running_loop()`](https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.get_running_loop "asyncio.get_running_loop") function is preferred to [`get_event_loop()`](https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.get_event_loop "asyncio.get_event_loop") in coroutines and callbacks.
Consider also using the [`asyncio.run()`](https://docs.python.org/3/library/asyncio-task.html#asyncio.run "asyncio.run") function instead of using lower level functions to manually create and close an event loop.
Deprecated since version 3.10: Deprecation warning is emitted if there is no running event loop. In future Python releases, this function will be an alias of [`get_running_loop()`](https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.get_running_loop "asyncio.get_running_loop").
Deprecated since version 3.10: Deprecation warning is emitted if there is no running event loop. In future Python releases, this function will be an alias of get_running_loop().
seems like a fix would be:
try:
loop = asyncio.get_running_loop()
except RuntimeError:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
I feel like you're better trying asyncio.run first at this point
3.6 is EOLing in like two months anyways 👀
5 long years of service
In the meantime, could do a check for python version and go off that
I've got asyncio_backport with a copy of run
There's some issues with cancelling async generators though
<!--
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,python2];
...
is there any sort of sneaky way to have black change this
if not any(
expected in value for expected in self.bad_styles[style_name]
):
to something like this
if not any(
expected in value
for expected
in self.bad_styles[style_name]
):
Nope, Black is not configurable
If generator expression doesn't fit in one line (per line length limit), it will be split, though not in the way you've shown
so only line length can change how this is shown, right?
yep, but in your case the rest of the code would look quite ugly if you were to reduce it to, say 40
sad, i really dislike this sort of formatting and reducing line length doesnt always fix it
function(
super long line that cant be split with magic commas
)
``` is there possibly an issue about this
We do format things like that if the inner line is within the limit but the outer isn't
but no, an issue about making a toggle for that wouldn't be accepted, if you mean doing it earlier than the line length limit
hope you understand 😅 like Jack said, Black isn't really configurable
well not a toggle but a trailing comma forces parameters to their own line, i was wondering if theres an equivalent for this
I might have misunderstood then, could you ellaborate?
def pretty_print(
count: defaultdict[str, int],
) -> None:
``` this is well within the line limit
no what i mean is that adding that trailing comma changes the format even though the line is well within the line length limit
from
def pretty_print(count: defaultdict[str, int]) -> None:
to the above
so i dont understand why the line length thing is used as an argument here
i want something that would break a *-comprehension to multiple lines, even though its already within the line length limit
oh I get it, so something akin to the magic comma but for comprehensions
I don't think so
is it something you guys would be keen on exploring?
sadly I doubt that it would get accepted either, we are religiously against taking previous formatting into account, the comma being a very rare exception :D
sad but fair
yeah I know, thanks for understanding
Describe the style change
I write python modules that are configured by .yml files which look something like this:
Category_X:
Subcategory_Y:
Enable_Condition_Z: true
After reading them in, they are addressed like a nested dictionary (see below). Then I write if clauses that check if a condition is to be checked and if the condition is fulfilled. Black messes that up a bit.
Examples in the current Black style
def black_if_test():
...
Describe the bug
Thanks for a great library. When running the following command, black excludes the folders in the regex as expected:
black . --check --exclude 'build'
However, when running this, the exclude pattern is ignored:
black **/*.py --check --exclude 'build'
To Reproduce
In an empty folder:
echo 'print( 1)' >> test.py
mkdir build
echo 'print( 1)' >> build/foo.py
Then running black, gives this output:
# bl...
Type ignore are standard constructs in python code. I think it would be based if black formatted them
a: SUS = "AMONGUS" + 1 # type:ignore [name-defined , operator ,misc ]
Could be formatted to:
a: SUS = "AMONGUS" + 1 # type: ignore[name-defined, operator, misc]
man, it feels good to triage an issue well :)
review my 2 PRs, it would make you feel even better
how do u change the format
Could you elaborate?
Black doesn't really provide options to tweak the formatting, there's --line-length, --skip-magic-trailing-comma, --skip-string-normalization (ooh and --experimental-string-processing) and that's it
yea
What's the problem with it currently? Usually you don't see people asking tools to allow configuration of their console output fwiw :)
i just don't like the output colors but it's all cool
Yeah, unless there's a real functional problem I'm going to say no to a request to add knobs for the console output colors
true i see what you mean
it's not an unreasonable request but it wouldn't be worth the maintenance cost
The CI failure seems unrelated.
Description
looks like their project dev tooling uses some newer syntax or something
Checklist - did you ...
- [x] Add a CHANGELOG entry if necessary? -> n/a
- [x] Add / update tests if necessary? does primer count?
- [x] Add new / update outdated documentation? -> n/a
yes
link
seems like it isn't picking up the typed-ast dependency and hence why a bunch of python two tests are failing but I have no idea why
Is this because of the typed-ast saga?
did they do a release earlier today or something?
typed-ast is broken on Python 3.9.8 only because cpython dropped some private API function
----------- coverage: platform linux, python 3.9.8-final-0 -----------
seems like you're right lol
Shantanu is making a release today to get the fix out
for a month??
wait that's 6 days
;-;
i can't calendar
No offense to whoever works on typed-ast but I can't wait until we can drop Python 2 support fully
seems like it was a good call to drop Python 2 support soon :)
I am a typed-ast maintainer 😄
though I've been happy to leave most of the actual work to other people, I don't think I've ever really done anything on iit
Jelle you maintain like half the python ecosystem 😅
that's only half of what asottile maintains
/srs
i swear i see their github account on all of the repos i use
Has coveralls been fixed yet btw
pre-commit
flake8
pyflakes
isort
tzdata
pycodestyle
identify
pyupgrade
literally 95% of the pre-commit hooks and shit are maintained by asottile
I suppose waiting until the next release is the best course of action @dense jungle ?
I'd rather not pin and have it break on some future release of Python 3.10 or whatever
Ah it's been fixed two hours ago
when did it break again
also now pre-commit.ci too!
Whenever coverage 6.1 was released
Yes, if he doesn't do the release I'll pester him 🙂
oof, black should not use coveralls /hj
Or figure out how to do it myself
I thought you said you didn't have permissions, or do you just have file uploading permissions but no admin?
which is installed on all of the above repos IIRC
Are you asking about me and typed-ast?
I think I do have permission
oh wait I was getting confused with typing-extensions 😔
that's what happens when you [know] a power maintainer 😛
https://pypi.org/project/typed-ast/ see i'm there
haha of course
my internet connection hates me today :(
Not just you, I think it's just broken
setting up a new .venv be like:
pip install pdbpp ipdb bpython ipython ipykernel flake8 black isort
Oh? did the cache configuration break?
I thought it was my side as my internet is really slow today, even GitHub is loading slowly when it is usually super fast
the profile pictures are 504ing
i have not experienced that
Ah yeah that's their problem then
Also apparently fuzz on 3.9 is broken too .. although I honestly have given this workflow zero attention as I feel like we already have enough bugs to fix 😄
I think he has a brother which gets me confused lately when I get notifications from this PR lol
https://github.com/pypa/pip/pull/10625
unless it's just a coincidence they have same last name lol
both first names start with an A too!
my discord notifications 
and dms ^^
lmao ngl when i close an issue i legitimately listen for the discord ping
I continue to be impressed by how fast it is
Like it shows up in discord before the server request finishes
or when i merge, i listen for the sweet ping ping ping, of an issue being closed, a pr being closed, and commits being pushed
ikr?
i see the notification of "issue closed" "pr closed" "new commits" before the page even goes to a loading screen
By the way, did GitHub change how workflows are run for pull requests?
yes
plot twist: its not any faster, but the return result of a merge is actually slow
what changed?
nothing as far as I can tell
I just submitted my pr from a branch on my fork and that behaves differently with CI than I'm used to as I usually use branches on the main repo ever since becoming a maintainer ^^
typed-ast 1.5.0 has arrived
... did we just discover another CPython bug?
raise type(err)(
SystemError: compile('delA\\ \n#\n', '<string>', 'single') raised SystemError: Negative size passed to PyUnicode_New
```7
It's open on BPO, hitting it here too
I don't remember but i'm confident this has happen before
oh fair enough ^^
ah, before this channel
Hm, maybe not, are you using exec? I haven't actually looked too far into it, because the thing I hit it with was using it
wish i knew how to comment on that, since it happens on 3.9 too
Do you have a BPO account
no lol
The login, and signup is on the left
What ancient browser are you using lol
firefox dev edition smh
OH DARKTHEME
aight now it just looks ancient
bugs3.python.org when
Such as the issue tracker 🤡
fuck
...
i have some bigger issues now
for the fifteenth time
i have fucked up my PATH
noice
They're working on migrating issues to GitHub for what it's worth
Don't know when it'll happen
oooh nice
!remind 16H open an issue to deal with warnings and set up pytest to fail on new ones as we've gotten bit / close to bitten by missed deprecationwarnings :(
Your reminder will arrive on <t:1636739300:F>!
This is exciting!
If I remember correctly this also makes parenthesized with statements work thanks to parser magic. Should we add tests for that?
testing out the match pr 😎
Still slow?
nope.
Honestly I don't know, haven't been able to reproduce it 😅
happy to see the match PR isn't actually slowing black down noticeably
although I plan to do actual benchmarking so I'll know by then
benchmarking the benchmarking tool? But what benchmarks the benchmarks' benchmarks?
we make for a good maintainer duo @dense jungle 😄
@dense jungle I thought supporting parentheized with would also require hacking the tokenizer? .. at least with LL(1) parser tech
If I remember correctly Batuhan said earlier that this change would also support parenthesized with
I think because he made x as y a node
OK this is embarrassing ... I tried this to test it
with (
open("o-my", "w") as f:
):
f.wriet("YAY")
and didn't notice the trailing colon in the body >.<
I just assumed parser failure == no support for parenthesized with
That's probably also worth a call out in the docs
oh I also just realized that --safe doesn't work if you're running black on something that's not 3.10 and you try to parse a match statement
Yeah although it's the same with all newer syntax in regards to runtime requirements w/ black, no?
true, but it confused me for a while 🙂
Yup yup, for what it's worth I don't really have Python 3.10 on my machine
I mean, I do have a built version of CPython 3.10.0 but like it's soooooooooo slooww
I built it with the intention of quickly testing something so basically disabled all optimizations... turns out that's a bad idea even for quick testing.
In other news, sadly the deepcopy calls are breaking mypyc support for the PR
self._start_point = copy.deepcopy(self.parser.stack)
/opt/python3.8.5/lib/python3.8/copy.py:146: in deepcopy
y = copier(x, memo)
/opt/python3.8.5/lib/python3.8/copy.py:205: in _deepcopy_list
append(deepcopy(a, memo))
/opt/python3.8.5/lib/python3.8/copy.py:146: in deepcopy
y = copier(x, memo)
/opt/python3.8.5/lib/python3.8/copy.py:210: in _deepcopy_tuple
y = [deepcopy(a, memo) for a in x]
/opt/python3.8.5/lib/python3.8/copy.py:210: in <listcomp>
y = [deepcopy(a, memo) for a in x]
/opt/python3.8.5/lib/python3.8/copy.py:146: in deepcopy
y = copier(x, memo)
/opt/python3.8.5/lib/python3.8/copy.py:210: in _deepcopy_tuple
y = [deepcopy(a, memo) for a in x]
/opt/python3.8.5/lib/python3.8/copy.py:210: in <listcomp>
y = [deepcopy(a, memo) for a in x]
/opt/python3.8.5/lib/python3.8/copy.py:146: in deepcopy
y = copier(x, memo)
/opt/python3.8.5/lib/python3.8/copy.py:205: in _deepcopy_list
append(deepcopy(a, memo))
/opt/python3.8.5/lib/python3.8/copy.py:172: in deepcopy
y = _reconstruct(x, memo, *rv)
---------------------
def _reconstruct(x, memo, func, args,
state=None, listiter=None, dictiter=None,
deepcopy=deepcopy):
deep = memo is not None
if deep and args:
args = (deepcopy(arg, memo) for arg in args)
y = func(*args)
if deep:
memo[id(x)] = y
if state is not None:
if deep:
state = deepcopy(state, memo)
if hasattr(y, '__setstate__'):
> y.__setstate__(state)
E AttributeError: 'Leaf' object attribute '__hash__' is read-only
huh why is it trying to set __hash__
I have no idea 🤷
wait... don't we set __hash__ to None in the Leaf class for PyPy compatibility?
Shouldn't be an instance variable though
__hash__ = None # type: Any # For Py3 compatibility.
I think we can just remove that line. The class defines __eq__, which means it already implicitly has __hash__ = None
__hash__ inheritance is weird
also mypyc doesn't build for me 😦 ```/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/_stdio.h:93:16: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
unsigned char *_base;
^
which sounds like a very pedantic error
🤷 I don't use macos
fwiw I had to switch out gcc for clang to get it working on linux so you're not alone in the weird compiler errors
do you know if there's a way to control what compiler options get passed to the C compiler?
Python 3.8.5 (default, Sep 9 2020, 23:45:44)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import black.parsing
>>> node = black.parsing.lib2to3_parse("a")
>>> node.children[0].children[0]
Leaf(NAME, 'a')
>>> node.children[0].children[0].__mypyc_attrs__
('_prefix', 'bracket_depth', 'column', 'fixers_applied', 'lineno', 'opening_bracket', 'used_names', 'value', '__hash__', 'children', 'parent', 'type', 'was_changed', 'was_checked')
>>> node.children[0].children[0].__getstate__()
{'_prefix': '', 'column': 0, 'fixers_applied': [], 'lineno': 1, 'value': 'a', '__hash__': None, 'children': [], 'parent': Node(simple_stmt, [Leaf(NAME, 'a'), Leaf(NEWLINE, '\n')]), 'type': 1, 'was_changed': False, 'was_checked': False}
This is what I get with compiled black, seems like __hash__ is treated like a normal attribute?
yeah that makes sense with how mypy normally works
Not sure if it'd work with whatever compiler macos uses by default but I've found setting the CFLAGS environment variable to work
I'd recommend just removing the __hash__ = None
or maybe annotating it as a ClassVar will help
Ah that would make sense
this worked CFLAGS='-Wno-expansion-to-defined -Wno-nullability-completeness -Wno-undef-prefix' BLACK_USE_MYPYC=1 python setup.py build
Huh, interesting
also, typical Apple to have their compiler provide checks that fail on their own system headers
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/home/ichard26/.local/share/virtualenvs/black-Q9x7i-w-/lib/python3.8/site-packages/mypyc/lib-rt -Ibuild -I/home/ichard26/.local/share/virtualenvs/black-Q9x7i-w-/include -I/opt/python3.8.5/include/python3.8 -c build/__native_f4ee935d5338f3d318fb.c -o build/temp.linux-x86_64-3.8/build/__native_f4ee935d5338f3d318fb.o -O3 -Werror -Wno-unused-function -Wno-unused-label -Wno-unreachable-code -Wno-unused-variable -Wno-unused-command-line-argument -Wno-unknown-warning-option -Wno-unused-but-set-variable
build/__native_f4ee935d5338f3d318fb.c: In function ‘CPyDef_linegen___LineGenerator_____post_init__’:
build/__native_f4ee935d5338f3d318fb.c:98746:21: error: stray ‘\303’ in program
98746 | PyObject *cpy_r_��;
| ^
build/__native_f4ee935d5338f3d318fb.c:98746:22: error: stray ‘\230’ in program
98746 | PyObject *cpy_r_��;
| ^
build/__native_f4ee935d5338f3d318fb.c:99025:11: error: stray ‘\303’ in program
99025 | cpy_r_�� = cpy_r_r8;
| ^
build/__native_f4ee935d5338f3d318fb.c:99025:12: error: stray ‘\230’ in program
99025 | cpy_r_�� = cpy_r_r8;
| ^
build/__native_f4ee935d5338f3d318fb.c:99360:58: error: stray ‘\303’ in program
99360 | PyObject *cpy_r_r110[3] = {cpy_r_v, cpy_r_r98, cpy_r_��};
| ^
build/__native_f4ee935d5338f3d318fb.c:99360:59: error: stray ‘\230’ in program
99360 | PyObject *cpy_r_r110[3] = {cpy_r_v, cpy_r_r98, cpy_r_��};
| ^
build/__native_f4ee935d5338f3d318fb.c:99403:59: error: stray ‘\303’ in program
99403 | PyObject *cpy_r_r122[3] = {cpy_r_v, cpy_r_r116, cpy_r_��};
| ^
okayyy wow gcc really doesn't like mypyc's code
fun fact on macos gcc is actually clang
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 13.0.0 (clang-1300.0.29.3)
Target: x86_64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
to be fair those identifiers look suspicious as heck but if clang accepts it uhh it makes gcc look unforgiving :)
amazing
is that from where we use an empty set character as an identifier for the empty set?
yup
Pretty sure there's an issue on the mypyc tracker noting how gcc really hates unicode identifiers
diff --git a/src/black/nodes.py b/src/black/nodes.py
index 6e5c235..47c877f 100644
--- a/src/black/nodes.py
+++ b/src/black/nodes.py
@@ -20,6 +20,8 @@ if sys.version_info >= (3, 8):
else:
from typing_extensions import Final
+from mypy_extensions import mypyc_attr
+
# lib2to3 fork
from blib2to3.pytree import Node, Leaf, type_repr
from blib2to3 import pygram
@@ -142,6 +144,7 @@ ALWAYS_NO_SPACE: Final = CLOSING_BRACKETS | {token.COMMA, STANDALONE_COMMENT}
RARROW = 55
+@mypyc_attr(allow_intepreted_subclasses=True)
class Visitor(Generic[T]):
"""Basic lib2to3 visitor that yields things of type `T` on `visit()`."""
diff --git a/src/blib2to3/pytree.py b/src/blib2to3/pytree.py
index 3af2833..39ff481 100644
--- a/src/blib2to3/pytree.py
+++ b/src/blib2to3/pytree.py
@@ -91,8 +91,6 @@ class Base(object):
return NotImplemented
return self._eq(other)
- __hash__ = None # type: Any # For Py3 compatibility.
-
@property
def prefix(self) -> Text:
raise NotImplementedError
That's not bad as a fix 
wait a second, I typo-ed the mypyc_attr didn't I... how it working then?
eh, I'll continue with this tomorrow. Thanks @dense jungle for the help!
Hopefully we can land the match PR and mypyc PR soon 🤞 (this weekend is going to be busy as heck for me tho)
Hopefully! Saturday might be busy for me too but I'll probably have time on Sunday
hellllllo
hello
Describe the bug
Black thinks that a file containing a syntax error is well formatted.
To Reproduce
With a file containing just this code:
{
f"{",
}
Black does not give an error:
$ black bad.py
All done! ✨ 🍰 ✨
1 file left unchanged.
But there is a syntax error in the file:
$ python file.py
File "/home/inglesp/file.py", line 2
f"{",
^
SyntaxError: f-string: expecting '}'
**Expected beha...
Given that we'll be dropping Python 2 support in 2-3 months I don't think we'll need to do much in terms of letting folks know PyPy doesn't support Python 2. Perhaps we should notice when our built-in parser (which has excellent cross-version syntax support; ignoring parenthesized with and pattern matching -> #2586) falls back to the Python 2 grammar but we can deal with that later as isn't strictly related to PyPy compatibility.
Here's your reminder: open an issue to deal with warnings and set up pytest to fail on new ones as we've gotten bit / close to bitten by missed deprecationwarnings :(
[Jump back to when you created the reminder](#black-formatter message)
Description
Should fix GH-585.
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
i- ... how am I the most prolific contributor since May 2019 ?!
I very much don't remember making 72 commits :)
Where's the full documentation for all the configuration options in the pyproject.toml file for black?
I don't find it :/
For example, I want to configure the tab size
We don't have such a thing yet
running black --help nets 98% of the available options usable in pyproject.toml tho
.. although this is not one of them as it doesn't exist at all
Noooo, yikes!
We don't support configuring indentation size though, and we are not going to add it
Black is meant to be opinionated and non-configurable
Damn. My preferences are tab size 2. How come you don't want to make it so I'm able to set it to 2 instead
The main ethos and appeal behind Black is that it isn't configurable. Yapf is on the other side of the spectrum, it's rather configurable ^^
There's a lot of tools, I'm sure I can set it to 2 afterwards though, so I think it's not a big deal, now that I think of it
Hm, now I wonder how do I find such a tool. "Tool that looks in all your files and makes them tab size 2"
!pypi indentpy - perhaps?
hmmm
seems rather out of date in terms of packaging standards, it suggests installing from github even when it's on PyPI?
off topic from this discussion but what do people think of this issue form for collecting feedback on the compiled wheels? https://github.com/ichard26/black-mypyc-wheels/issues/new/choose
I still need to write up the document explaining how people can test the wheels but at least the feedback collection bit should be ready :)
Gotta say the new issue forms are looking pretty nice even if the UX creating them wasn't the easiest thing to get used to!
is formatting like this intentional? I don't quite get what it's trying to do
AHK_TEMPLATE = Template(
"""\
stdin := FileOpen("*", "r")
${hotkey}::
while not stdin.AtEof
{
system := Trim(stdin.ReadLine(),"`n ")
}
${user_script}
"""
)
I assume no? Pretty sure there's reports on the tracker about this
ah, I searched with a space in multiline
GitHub search is a mysterious thing sometimes 😄
I guess it's indenting the opening quotes because of the parentheses?
yeah and then it dedents the closing quotes because the logic probably assumes it'd be indented and broken up later i.e. fixed (except that's impossible for multiline string literals)
The closing quote is dedented because doing anything else would change the contents of the string literal
Anyways, THAT module did the job :D I installed it with PyPi and I'm currently working on a little tool to make it do what I want
pretty sure this got buried before y'all got a chance to read it; friendly bump
This looks great! One thing is that it talks about running diff-shades with no link; how would normal users know what diff-shades is or how to use it?
Yeah I still need to write those docs - good point on explaining what it is and linking to relevant docs
I might also give it less prominence in the form, perhaps I'll integrate it into the "additional commentary" bit
:incoming_envelope: :ok_hand: applied mute to @wide warren until <t:1636798652:f> (9 minutes and 58 seconds) (reason: duplicates rule: sent 4 duplicated messages in 10s).
Hey, might not be the place for this, but I'm a big fan of the black formatter, I recently started learning javascript, does anyone know if there's a similar tool for js? Not sure how to search for it haha
Prettier is pretty popular
^, or running eslint with the --fix cli option can be really nice, although it takes some configuration
Awesome to see 3.9 and 3.10 compatibility truly realized, thank you!
Is your feature request related to a problem? Please describe.
One of the reasons I use black is so that I can focus on code without having to focus on style. #1824 introduced a --skip-magic-trailing-comma flag to further control style. However, there's no way to set this flag in a config file, so the file format will change depending on whether or not a contributor uses the flag.
Describe the solution you'd like
I would like to be able to set this in a config file like `py...
hey can one of you help me figure out how to apple the finctions of import os and import os.path to my hw? thanks
When you have vim builded with Python 3.10 the black plugin will fail when running :BlackUpgrade or :Black
Error detected while processing /home/michal/.vim/bundle/black/autoload/black.vim:
line 201:
:5: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
I am able to fix the issue by removing from distutils.util import strtobool from autoload/black.vim and re-implementin...
caching is fun to implement :)
1e0ec54 black/parser: partial support for pattern match... - isidentical
Let's add this to the changelog
Should we test PyPy 3.8 or shall we do that later @dense jungle ?
it's unreleased, right?
Also related, how does requires_python work with PyPy?
need to read up on that
it's in beta
I have no idea
OK, then it seems fine to wait
Also I'm hoping to merge your mypyc PR too, looking at a few others right now
I'm just worried someone on PyPy 3.6 will attempt to install black and pip won't complain that we aren't compatible
Although it seems like PyPy 3.7 is the oldest series still supported by upstream so I guess it's fine regardless
Are we not compatible though? Honestly most of the time these things just work (though I have little experience with pypy)
It would probably take a lot of changes to fix the failures for pypy3.6. Since that wouldn't really be in the spirit of this PR I removed it from the list of targets.
Oh I see, was confused with 3.8
https://github.com/psf/black/pull/2431 has merge conflicts with the match PR, @bright glacier did you already resolve those?
locally yes
I'm not ready to start community testing yet but might as well merge it now to avoid more conflicts :)
yeah was just going to say that
even if the wheels still need some work it's good to get the PR in because we definitely want those changes
tldr switch the state of the pr to draft if you aren't ready
what?
Yea... but isn't this whole discussion all about merging the PR early to avoid conflicts?
i thought you meant push these local changes, and took that to mean merge it
Yeah please push the local changes to get it mergeable and then we can hit the big button
unrelated: I'm thinking of closing https://github.com/psf/black/pull/1715, I think most of just aren't excited about the prospect of outputting this XML format
I'm undecided but in general this seems way too niche
Also seems possible to write a tool that just calls black --diff and turns the output into the desired format
what's the value of adding a changelog entry to psf/black#2562 ?
Telling users that they can run black under 3.10
Fair although runtime support already existed and the 3.10 syntax is already in the changelog 😄
Man are the pypy tests slow on the already slow macos environment
lol the macos are ran on github's cloud
Isn't PyPy supposed to be faster overall? I wonder what's holding it back.. is the built-in ast module really slow or something?
although... technically azure and gh's cloud is the same owner
doesn't pypy only support up to 3.7 as of rn?
I think it's using JIT and it needs time to warm up, so CI probably won't show a lot of speed gains from pypy
Hmm to be fair the PyPy tests are running in a subprocess to work around a bug apparently
I wish github would sort the checks by their status so I don't have to scroll scroll scroll to find the one that's failing
hmm, this might be an #internals-and-peps question but how is jit faster if cpython compiles them to start with?
Wouldn't the short time wasted with compiling be faster once it starts running it?
I have basically no knowledge of JITs but given how much test data we throw at black during the test run I'd've assumed it would be warmed up enough
What is "them"?
them = the written code in python to be ran
Though broadly while CPython does have a compile step, it "compiles" to a very high-level language (CPython bytecode), while PyPy's JIT can compile to machine code
is there a way to apply a patch generated from git show HEAD -p? git am didn't like the file
I can always use git apply and then do a manual commit but the whole point of using the patch flag was so I didn't need to do that
git apply?
wow my github inbox is already spammed
what a lovely problem to have knowing what it signifies😄
https://github.com/psf/black/pull/1574 "@bright glacier ichard26 self-requested a review 2 months ago" so what about it 😄
Seems good to me now that Jelle got his edit in as well! So how bout a merge?

@dense jungle what pronouns?
I'm a man
👌
... ignoring the fact I completely forgot about this PR, in the timeframe it sat there there is now a line in the docs that talks about this already
gotcha
I guess it doesn't hurt merging the tiny PR
For some reason I'd feel really bad closing it myself :)
Re. psf/black#1879 I just assumed we would merge and enable the formatting this before the stable policy goes into effect but I'm OK with putting it under the --future(?) flag
im curious, what is a reason to use platform.python_implementation() over sys.implementation.name
Maybe I'm too hesitant to ever change formatting 🙂
Mostly because that means when I upgrade black at Quora I have to reformat a bunch of code
Ahaha that's fair no worries
I'm over here using # fmt: on/off more than I have ever used to so I'm on the other side of the spectrum
also did we not update the stable tag or is there some other reason I can't find the stability policy in https://black.readthedocs.io/en/stable/the_black_code_style/index.html
We just haven't yet
I was in the middle of doing that, but I got slowed down by 1) doing a clean clone, and 2) I totally forgot what git commands I had to run
You can mostly blame pipenv lock for why I do clean clones so much more often these days
I was opening it when you said "done" 😄
I suspect Shivansh-007's PRs might take a while to get reviewed and landed ... they touch more than I initially expected
We can maybe move forward with the --verbose one, I would want to look at it more before I do anything
Yeah that's my overall feeling too, seems good on paper but the implementation and design decisions probably need some work
While I'm happy we're still trying to fix the stability issue w/ trailing commas properly, I don't have high hopes for https://github.com/psf/black/pull/2572
oh for goodness sake the pypy PR caused more merge conflicts on the mypyc PR
oh no, I'm sorry 😦
I apparently forget to as-exprs when they happen inside call arguments, which have their own special mini-grammar to support stuff like walrus (higher precedence operators). This patch should resolve that issue.
Is this related to a problem? Please describe.
- macOS Monterey
- Chrome 95
- Chrome Canary 98
- Opera 71
- Firefox 93
The CSS uses hyphens: auto which inserts hyphens for some words, however with the Georgia font the hyphen shows as an empty box aka "tofu":

Description
Fixed #2607 by removing distutils import from autoload/black.vim, which is deprecated in Python 3.10, and by re-implementing the distutils.strtobool as suggested in PEP 632.
Checklist
- [ ] Add a CHANGELOG entry if necessary?
- [ ] Add / update tests if necessary?
- [ ] Add new / update outdated documentation?
Thanks for the PR!
Could you also add a changelog entry?
I mean, at this point I'm pretty good at resolving conflicts 😎
No worries :)
not sure if good or bad...
Uh what?
like
good: you can resolve conflicts fairly well
but at what cost
I think he was just referring to merge conflicts 🙂
The implementation of the new backtracking logic depends heavily on deepcopying the current state of the parser before seeing one of the new keywords, which by default is an very expensive operations. On my system, formatting these 3 files takes 1.3 seconds.
$ touch tests/data/pattern_matching_*; time python -m black -tpy310 tests/data/pattern_matching_* 19ms
All done! ✨ 🍰 ✨
3 files left unchanged.
python -m black -tpy310 tests/data/pattern_matching_* 2,09s user 0,04s...
Is your feature request related to a problem? Please describe.
I plan to start using Python 3.10 and wonder what I can specify as --target-version!?
Describe the solution you'd like
black --help shall list how I specify a Python 3.10 target version.
Describe alternatives you've considered
I installed Pyrhon 3.10 and the latest black version to see if black --help lists an appropriate target version.
Additional context
I looked through open issues h...
FWIW there's a hotfix for -t py310 we need to do before releasing 21.11b0
currently only the match statement is attached to that TargetVersion when a bunch more features need to be attached
hm what else? parenthesized with?
we also may not support PEP 614 (decorator syntax) but that was already in 3.9
~/programming/oss/black on main [$?⇡] via Python v3.8.5 (black)
❯ black test.py --diff --color -q
--- test.py 2021-11-15 21:31:38.652666 +0000
+++ test.py 2021-11-15 21:32:00.444694 +0000
@@ -1,2 +1,6 @@
-def daylily(this_is_a_long_parameter_name_because_i_am_testing, something, **related_to_target_version_py310):
+def daylily(
+ this_is_a_long_parameter_name_because_i_am_testing,
+ something,
+ **related_to_target_version_py310,
+):
pass
~/programming/oss/black on main [$?⇡] via Python v3.8.5 (black) took 427ms
❯ black test.py --diff --color -q -t py310
--- test.py 2021-11-15 21:31:38.652666 +0000
+++ test.py 2021-11-15 21:32:04.028799 +0000
@@ -1,2 +1,6 @@
-def daylily(this_is_a_long_parameter_name_because_i_am_testing, something, **related_to_target_version_py310):
+def daylily(
+ this_is_a_long_parameter_name_because_i_am_testing,
+ something,
+ **related_to_target_version_py310
+):
pass
notice how the second call with --target-version py310 doesn't add a trailing comma?
src/black/mode.py lines 102 to 115
TargetVersion.PY39: {
Feature.UNICODE_LITERALS,
Feature.F_STRINGS,
Feature.NUMERIC_UNDERSCORES,
Feature.TRAILING_COMMA_IN_CALL,
Feature.TRAILING_COMMA_IN_DEF,
Feature.ASYNC_KEYWORDS,
Feature.ASSIGNMENT_EXPRESSIONS,
Feature.RELAXED_DECORATORS,
Feature.POS_ONLY_ARGUMENTS,
},
TargetVersion.PY310: {
Feature.PATTERN_MATCHING,
},```
Oh I see, we should just add the 3.9 stuff in there too
Mhmm
POS_ONLY_ARGUMENTS is a humorous name
can black read from stdin / print to stdout?
nice, seems to work. I'm trying to work out a simpler integration with vim, since vim-black seems to break whenever I upgrade my python version
nnoremap <buffer> <F5> :%! black - --quiet 2>/dev/null <CR> this works, but it moves my cursor to the top of the buffer (understandable) so I'll try to tackle that next, but it's a vim question 🙂
sublack (black plugin for sublime text) with option "black_on_save": true, sometimes freezes sublime forever
with "black_on_save": false, everything is ok (sublime not freezes after formatting)
You should report this issue to the plugin author as it's not maintained by the same people that maintain Black
Btw, LSP can be used for auto-formatting too if you set it up with pylsp server
ok, i thought author of sublime plugin is here...
assuming you mean https://github.com/csurfer/sublime_black
I don't recall seeing them here
nope, that's not the package they were talking about
they were talking about this one
https://github.com/jgirardet/sublack
OK, anyway back in the right channel about #type-hinting message
I guess the main problem with emitting parenthesized withs starting from 3.9 would be that the code wouldn't be safe for other Python implementations as it was technically an implementation detail in that feature version. Otherwise I'd say ignoring the undocumented nature of it is probably fine.
We could keep the detection code and use it as a marker of 3.9+ but then don't emit parenthesized withs until -t 3.10 but that's rather hacky and I don't even know if we pass enough state for that to work.
yes. I guess that's mostly a theoretical problem since pypy is still working on 3.8
though I suspect they'd aim for bug-for-bug compatibility with CPython and support parenthesized with
They in general do aim for bug-for-bug compatibility but there's more implementations of Python than just PyPy and CPython at this point
What did you want me to review in particular w/ this by the way? I got distracted writing this detection code.. would've reviewed after.
oh yes I did and then forgot about it and merged anyway. mostly wanted to make sure this didn't interfere with any of your blib2to3 changes
I'll update 3.10's features to include the ones from 3.9 and then I'll check the mypyc branch and hopefully fix the PyPy issues as well
And then we merge it and make a release
sounds good to me
Jelle wdym by https://github.com/psf/black/pull/2525#discussion_r749860027
If we have test_replace.toml (root)
[tool.black]
config = "_black_config.toml"
verbose = 0
color = false
and _black_config.toml
[tool.black]
verbose = 1
color = true
The resulting owuld be verbose = 1 and color = True... that's what the comment says
I mean that we should do the opposiite
This is #2504 but I updated it locally to make sure the changelog ended up in the right place.
Fixes #2476. Closes #2504.
that's what me, richard and felix agreed with 🤷♂️
I don't know honestly, I haven't taken a look at your PRs in a long while and I've forgotten most of the context
Sorry, where was that discussed?
I'm struggling to see a good use case for the current behavior
hm I see. I feel like if we do this we're going to get bug reports about "Black is ignoring the option I put explicitly in my config file!" and requests to add a mechanism to warn about conflicting options
maybe we can document that behaviour in the docs?
Sigh, OK I do see Jelle's point now. It would be confusing at best
that's what i wrote on the PR 🙂 I still feel overwriting the other way makes more sense though, assuming it's not too hard to implement
To be honest I already have a hard enough time figuring out how our configuration system works and I didn't want to add another merge rule on top of all of it :p
we need a merge rule either way
nope.. not hard... should be 2 lines change
Fair. I guess if a config file contains --config PLUS other configuration, any configuration from --config overwrites the parent config?
I kinda need to make myself a diagram to check I'm not misunderstanding here 😅
that's the current behaviour
alright I'm just as confused then
.
So the original use case here was someone who has a ton of different Python projects in some sort of shared structure
They want a single shared config file for the megaproject, then just write config = ../parent/pyproject.toml in all the other subprojects
Then it seems most helpful to me that they can adjust some config options in the per-project config files
ok, i see your point... root config should be highest level in that case, yeah
OK, so merging all the way then I suppose
what's our current behavior when you have both a config file and a command-line option?
commnad line option is highest level
CLI -> project-root-config / CLI --config -> any nested --configs -> ... -> defaults
so this is the proposed flow, correct?
good, I feel like the behavior I'm proposing is consistent with that
the most specific config wins
yeah richard
Alright, fwiw I'm going to want some decent tests for this as there's a lot of ways this could go wrong :)
Yep and we should still document it
👍
Gosh I just realized this would get immensely confusing if we added automatic nested pyproject.toml support
hopefully we won't have to do that with nested configs but oh dear that'd suck
Well explicit nested configs wouldn't work as 100% complete workaround for implicit nested pyproject.toml support.
I was going to explain why it isn't a perfect workaround but I got too confused trying to explain it 😅
Can I add another argument to read_pyproject_config saying return_config_dict, which would return the config early (before setting it to ctx.default_map
it would make the implementation easier
ughhhh I'm soo confused about this feature
honestly don't ask me, I'm still trying to work out the details in various situations
anyway it's far too late for me to be thinking about this -- I'll think about this later when I'm not a little tired
I should get up and take a break from screens ... cya y'all for a little bit
cya
@dense jungle
Haven't looked at this code specifically but in general parameters that affect the return type are evil, better to split out the steps into separate functions
Oh yeah and I forgot we supported user level configuration
@dense jungle assuming the mainline tests succeed (not too worried about primer tbh) in particular the PyPy ones, let's merge psf/black#2431 for once and all
HOw do you make a note tag in the docs?
```{note}
```
You are not allowed to use that command here. Please use the #bot-commands channel instead.
smh
```{note}
```
k ty
I'll merge it tonight assuming CI is reasonably green
If you are using the linked configuration feature i.e. have `config` in your black configuration,
the root config values i.e. the config values found in the file which was containing the `config`
the key would overwrite them.
Sounds confusing... any way to word it better
I feel like we need a precise term for each of the two config files involved
Child and parent config?
Linked configuration sounds more obvious IMO
I was wondering, what should we do for CI once we start enforcing no formatting changes and support the --future flag? Ideally we would have two sets of jobs, one where it'd error out if any changes were detected between main and the PR, and another where it'd show the formatting changes if the --future flag was passed but given we're already maxing out our CI resources that would easily slowdown CI a lot.
and parent config for the root config containing the config value
The reason why I'm suggesting two sets and not two jobs or whatever is that Cooper likes to run primer (although in this case it'll be diff-shades) against the whole testing matrix if possible to discover environment-specific bugs. It's a fair argument and is generally doable for now, but doubling the job count / workload per job to support the two modes would suck.
I would be fine with dropping a few builds. Maybe we can drop the coveralls builds, and run macos/windows on only one Python version each.
It seems like the only workable solution for now. 20 free jobs is great, but kinda limiting for projects of our size unfortunately :(
Anyway this is one more thing to add to my list of "I need to think through this more and come with a more fleshed out proposal or summary" 😄
You delete the squashed commit message jelle?
it's not a big deal as no one will be reading that but it seems unnecessary to drop the context :)
Oh yes, I try to make the commit message sensible when I merge, sometimes I copy-paste the PR description in. But a long sequence of commit messages doesn't seem useful for the commit log.
Description
To avoid this situation:
~/programming/oss/black on main [$?⇡] via Python v3.8.5 (black)
❯ black test.py --diff --color -q
--- test.py 2021-11-15 21:31:38.652666 +0000
+++ test.py 2021-11-15 21:32:00.444694 +0000
@@ -1,2 +1,6 @@
-def daylily(this_is_a_long_parameter_name_because_i_am_testing, something, **related_to_target_version_py310):
+def daylily(
+ this_is_a_long_parameter_name_because_i_am_testing,
+ something,
+ **related_to_targ...
Is there anything else we need to merge or should we release 21.11b0 soon?
I can't think of anything important or useful-enough to warrant extra attention.
I don't think so. Let's do a release tomorrow?
Sure, I'll be rather busy for first half of the day tomorrow but I don't expect many fires for this release
jelle ^
what would be the term for the config file doing the linking?
config
what kind of configuration is this gonna be? wait-- use me as a fresh set of eyes on this when you have something that makes sense and i'll see if i can understand what it does 😛
ping me when you have it figured out
what do we call file A and file B when we explain the behavior?
A is the parent file and B is the linked configuration file
PyPy 3.9 will also have a PEG parser (and use the same grammar as CPython) if everything works as planned, so it should be safe for PyPy too!
@plain atlas Done, see the docs change of psf/black#2525
ah the whole toml CR thing is amazing
CR full form? (Google didn't help)
it's a problem if you open a file in text mode and pass it to tomli
because python normalized LF CRLF and CR to \n
i think and i would suggest python black is a more convinient package for black formatting in sublime text as it is quite fluent and fast package and quite active in development side as well
- Define a global for magic trailing comma (this was missed in #2613)
- Add py310 as an option
does black not support match case?
The main branch does 🙂 we'll do a release very soon that provides support
how do I update to the main branch?
you can pip install from git, don't remember the exact command though
pip install -U "black @ git+https://github.com/psf/black@main"
probably need to pip install wheel first
or just wait for tomorrow and install the new version of black
Shall we do it in 40 minutes or whenever I get home? 😄
apparently I broke the vim plugin, that PR needs to get merged
in a couple hours I can figure out how to install the plugin to test my fix
ah, fair enough - waiting for a review from a vim user?
yes
(and no I don't count as I've never really looked into vim plugins)
me neither but I just pattern matched the code 🙂
ok, @bright glacier release time?
sure!
I can prepare it
there it is https://pypi.org/project/black/21.11b0/#files
Our wheel sizes are getting so much bigger from what I remember
155 kb isn't too bad
not that it matters at sub-metabytes levels but :p
metabytes 😔
Probably a term used at FB
Thank you for doing the release by the way @dense jungle !
the instructions make it very easy
I was more hoping to remove the need to update to docs as well as the CHNAGES.md …
Maybe we should write a script for the releaser to run to change these versions everywhere … I was sad to learn about this last release.
Describe the bug
black failed to format all single quotes in the dict as double quotes
To Reproduce
For example, take this code:
xpath_dict = {
'login_page': '//*[@id="top_nav"]/nav/ul/li[5]',
'account': '//*[@id="dlg_login"]/form/div[1]/div[1]/table/tbody/tr[1]/td[2]/input',
'password': '//*[@id="dlg_login"]/form/div[1]/div[1]/table/tbody/tr[2]/td[2]/input',
'login': '//*[@id="dlg_login"]/form/div[1]/div[2]/input[1]',
'三楼北区': '//*[@id="item_...
Thanks to black, I can write my code as bad as I want
and black will turn it into this neat pile
thats bad?
pfft you should see my code
the original really doesn't look that bad, ye 
Not to say that if I had to look at that code, I wouldn't be a bit annoyed by its formatting :P
black is created to format code from #esoteric-python :D
So I've noticed black formats code like this ```py
my_code = """
... @whitelist.command(name="remove", aliases=("delete", "rm",))
... def foo(ham: int):
... pass
... """
from black import format_str, FileMode
print(format_str(my_code, mode=FileMode()))
@whitelist.command(
name="remove",
aliases=(
"delete",
"rm",
),
)
def foo(ham: int):
pass
Is this expected and/or configurable?
If the first question is yes I am guessing the second is no anyway 😄
aha, right, thanks 😄
The --skip-magic-trailing-comma argument turns this behavior off
Thanks 😄
Describe the style change
When using conditional imports, if the next line is on the same indentation level, should there be an indent? My experience has been that when I have used a conditional import, its normally followed by 1 or 2 lines, and I am always surprised when I see Black add a space between them.
Examples in the current Black style
if settings.ENABLE_DEBUG_TOOLBAR:
import debug_toolbar
urlpatterns.append(path('__debug__/', include(debug_t...
I like how each of the flags for black are arguments
wdym
Latest 21.11b01 release includes https://github.com/psf/black/commit/117891878e5be4d6b771ae5de299e51b679cea27#diff-431968a04535c5ee2570855fe3a3473527050ed0e6d5cb5a9544bcef254d0590 which references the regex.Pattern class.
But this was only added in regex==2021.4.4 and black depends on regex>=2020.1.8 so running with an older regex version gives..
AttributeError: module 'regex' has no attribute 'Pattern'
^ that seems worthy of a hotfix release
ignoring pipenv I suppose? lol
use poetry
That's not a short term solution arl
wdym
isn't that my point tho?
I don't have the time to look into something like that right now
yeah samething, it didn't load when I was typing for some reason
wow what happened to Pipfile.lock now in https://github.com/psf/black/pull/2621/files
aiohttp went to 3.8.1 from 3.8.0
attrs marker change
dataclasses downgrade from 0.8 to 0.6
packaging upgrade from 21.2 to 21.3
pyparsing 2.4.7 to 3.0.6
typing-extensions from 3.10.0.2 to 4.0.0
added appnope at v 0.1.2
added matplotlib-inline??
and a bunch more
thanks!
it's kind of the point. I guess it ensures a consistent dev environment
That's the entire point of a lockfile, is it not? To ensure consistency across dependency installs?
but to be honest I've never used it, and it doesn't really seem worth the pain it's causing
I'd argue given that black is for consumers, since its versions are not pinned strictly in the requirements.txt, it means that the dev environment is better than the actual consumer environment
right, but its not used for consumer installation from pypi
I can fix the pipenv changes.
It'll be annoying but I got the know how 😄
interesting issue https://github.com/pypa/pipenv/issues/598
looks mostly fixed, but that added these?
added appnope at v 0.1.2
added matplotlib-inline??
File "/home/ichard26/programming/oss/3.6venv/lib/python3.6/site-packages/pipenv/utils.py", line 917, in _get_hashes_from_pypi
session = _get_requests_session(self.project.s.PIPENV_MAX_RETRIES)
File "/home/ichard26/programming/oss/3.6venv/lib/python3.6/site-packages/pipenv/utils.py", line 66, in _get_requests_session
import requests
File "/home/ichard26/programming/oss/3.6venv/lib/python3.6/site-packages/pipenv/vendor/requests/__init__.py", line 48, in <module>
from pipenv.vendor.charset_normalizer import __version__ as charset_normalizer_version
File "/home/ichard26/programming/oss/3.6venv/lib/python3.6/site-packages/pipenv/vendor/charset_normalizer/__init__.py", line 30, in <module>
import pipenv.vendor.charset_normalizer.api as CharsetDetector
AttributeError: module 'pipenv.vendor' has no attribute 'charset_normalizer'
✘ Locking Failed!
nvm pipenv locking still sucks even w/ way too much experience
Pipenv is a pain but this looks good enough? Thank you for noticing the original issue by the way @rowanseymour!
@bright glacier @neon loom (and anybody else listening in) do you agree this is worthy of a hotfix release?
It's simple enough to do a release that I don't really care either way
Given how new of a regex we are now restricting to a hotfix seems like a good call tho.
Good old regex causing us “fun”
yay regex!!
To be fair this is more on me for not noticing the type class was only added in 2021.4.4
I see no problems releasing often personally but I have no context and I’ve just got home from the pub so I won’t be any help
ecf8c74 Bump regex dependency to 2021.4.4 to fix import... - rowanseymour
pypi will give you seconds if you're fast enough 🙂
oh dang
I'll warn you next time
<!--
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,python2];
...
Description
Upgrade regex to latest to avoid import error. Unfortunately 2021.11b1 didn't fix the issues present in 2021.11b0. Pipenv has updated a bunch of unrelated packages unfortuantely when updating the lock
Checklist - did you ...
- [ ] Add a CHANGELOG entry if necessary?
- [ ] Add / update tests if necessary?
- [ ] Add new / update outdated documentation?
~~Here you go: http://www.5z8.info/fake-gmail-login-page_c5g8lm_hack-outlook~~ ok this is not exactly helpful :D
hey @granite crown . I've deleted your question since it has nothing to do with this channel. You can re-ask your question in an off-topic channel.
the answer is about as off-topic to this channel as the question so seems like a proper response to me :D
oh wait, that link actually links to black 
not as off-topic then!
<!--
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,python2];
...
yes isokay !
i already asked and forgot to delete the message here , mb 
lol, okay
👌
Black violates PEP8: E203 (Whitespace before ':')
Tested on PyPi release: black-21.11b1 platformdirs-2.4.0 regex-2021.11.10 typing-extensions-4.0.0
Tested on Black Playground: Stable: 21.11b0 | Main: @d0b04d
Issue is present in all branches tested.
This only occurs in some situations in which list splicing contains an operator (see example below).
To reproduce:
Example code to be formatted with Black:
d...
I just noticed that this FAQ entry is slightly outdated, https://black.readthedocs.io/en/stable/faq.html#does-black-support-python-2, just wanted to let you know
There are no current plans to drop support, but most likely it is bound to happen. Sometime. Eventually.
This part, specifically
Unless deprecation doesn't signal that support will be dropped? If so, apologies, I'm terrible at these terms
Good point, we should change that
Oh yeah. There's still that issue though with the user claiming we need to pin regex even further
I tried on macos
it also worked on our company system, where I think we had regex 2021.8
while https://github.com/psf/black/issues/2623 claims we need 2021.11
2021.4.4 works for me on x86-64 Linux 🤷
yeah and looking at the regex code I don't think this should have any weird dependencies. it's just defined in the global namespace of the Python part of the library
Indeed. I'm a bit surprised by the three +1s on that issue. Maybe it's folks still on 21.11b0 getting confused?
that seems like a good explanation