#black-formatter
1 messages ยท Page 26 of 1
I'm not even done the feature that powers those reports -- I just whipped up something quick and dirty in my site-packages install of diff-shades ๐
Yeah my development practices might not be the best when it comes to personal projects :p
i- i see
How helpful are the reports I'm attaching by the way @dense jungle ? Is there something you'd like as a fellow maintainer? If I can get the data backend performant enough I plan on adding line count, line additions, line deletions, and files changed statistics.
Anything from mypy-primer you'd like is also welcome ๐
they're great! that's basically exactly what I'd want
it's unfortunate that the conditional expressions report included the changes from the blank lines PR, I guess that's addressable with a better baseline
Yeah that's just me being lazy as each run take 20 minutes to do. I first compile black with mypyc (this ends up being a time saver in the long run!) and then run diff-shades taking 15 minutes.
so obviously a workflow would be great
Yea but I'm a busy human
16 cores?
the runners have at least that many
except for the ones used for the rest of CI
wdym?
diff-shades is configured with slightly more projects than black-primer which takes 8-12 minutes in CI - I don't understand what you mean each VM has 16 cores.
the extra projects are just my own :p
Linux and Windows VMs have 2 cores while the Mac ones have 3.
uhh
is this black from main?
you likely have a different syntax error elsewhere. because of that, black tries the 2.7 grammar which explodes on the print keyword
nope
try flake8 on the file
jelle's guess seems likely then
flake8 will tell you where your syntax error actually is
well then
the code works perfectly fine and no errors from pyright
can you hack parsing.py so it prints the errors for all grammars instead of just the last one
or try --target-version py310 or something
Oh do you have pattern matching / parenthesized with?
yep
Yeah that's locked under --target-version py310 at the moment.
Read the changelog :p
Nice work all. This will make black a much lighter and reliable install.
black can do 3.10 now?
Describe the bug
In python3.10 the case black can be written in the same line as the case keyword. However, this breaks black.
To Reproduce
Take this example code
# example.py
x = 5
match x:
case 5: print("it works")
It runs under python3.10:
python example.py
it works
However, black crashes:
black --target-version py310 example.py
error: cannot format example.py: INTERNAL ERROR: Black produced invalid code on pass 1: exp...
yes, but you need to pass --target-version py310 explicitly for match syntax to work
actually I do have an analysis from the blank line PR that I could use as the baseline for PR #2278's report - I just totally forgot about it ๐ฆ
let's make a new release soon
yay 21.12b1
I'd like to implement somebody's suggestion that we print a warning suggesting to use -t py310 if we detect match syntax
"it looks like you're playing with matches, would you like some help" ๐ฅ๐
This feels much better already @plain atlas :p
honestly nothing, I'm just playing with nox instead of tox
ohhhhh
my pc is lagging rn so if i'm slow to respond its because my pc is
tldr a windows service has a memory leak
okay killed
yeah, I haven't looked at nox much
I'm a bit excited to try it, however
given that its fairly nice, and allows the user to test on multiple environments locally
Okay, so... I can't figure out if I'm seeing something that is new -- because I can't find a corresponding issue for this.
Black formats this file as:
"""This is a subpackage because the directory is on sys.path for _in_process.py.
The subpackage should stay as empty as possible to avoid shadowing modules that
the backend might import.
"""
from contextlib import contextmanager
from os.path import abspath, dirname
from os.path import join as pjoin
try:
import importlib.resources as resources
def _in_proc_script_path():
return resources.path(__package__, "_in_process.py")
except ImportError:
@contextmanager
def _in_proc_script_path():
yield pjoin(dirname(abspath(__file__)), "_in_process.py")
All this additional whitespace seems excessive, to the point of hurting readability.
For me there's only one space before except on the playground. Would you suggest that the space before contextmanager is removed?
What version of black are you using? I'm seeing this on the latest stable release.
Playground for Black, the uncompromising Python code formatter.
Ah, main has this fixed somehow.
But what do you think of the spacing otherwise?
I think what main does is reasonable!
Agreed, although I probably would get rid of the space before the function.
But that seems to be discussed in psf/black#450
Input:
match a, *b(), c:
case d, *f, g:
pass
Expected:
match a, *b(), c:
case d, *f, g:
pass
Got:
match a, * b(), c:
case d, *f, g:
pass
Maybe it's counting that as an operation ยฏ\_(ใ)_/ยฏ
@muted haven i was just thinking that you would submit a fix, lol

I left a review ^^
neither comment of which actually applied to the code change itself ๐
thanks though I don't necessarily know how to respond to this
https://github.com/psf/black/pull/2667#discussion_r761979694
I just add patma related changes end-to-end I guess, not sure if there is an order to follow ๐
yep Richard got you covered
tldr no one cares 
which makes sense, by putting it anywhere in that block, it can slightly reduce merge conflicts
I might reorganize the changelog a bit before the release
136930f Make star-expression spacing consistent in matc... - isidentical
lgtm!
Thanks for being patient with my suggested changes... which weren't even needed at all!
we'll be doing a release soon so just stay patient with us :)
@plain atlas what do you think of using this?
.github/workflows/ci.yml lines 14 to 16
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true```
.github/workflows/lint_test.yml lines 15 to 17
concurrency:
group: ${{ github.workflow }}-${{ github.repository }}-${{ github.ref }}
cancel-in-progress: true```
basically the idea is that if we rapidly update a PR, the older CI runs would be autocancelled
!remind 10M double check this
Your reminder will arrive on <t:1638562494:F>!
Here's your reminder: double check this
[Jump back to when you created the reminder](#black-formatter message)
Thinking about it, it should work, although I would consider using github.ref instead of sha. The sha means it will always run on every commit, and continue to run, unless there is a pull request.
However, that may be desired behavior, as using a mix would mean that it would cancel checks if two consecutive pulls were merged to main.
I suppose my point above is be careful which workflows you put it on ๐
Additionally, I would consider github.sha vs github.ref, I have made a context dump here: https://github.com/onerandomusername/context/actions/runs/1536895896
Thank you I'll look at it later as I'm helping out in the help channels ATM
I honestly have no idea
!src remind
Commands for managing your reminders.
config-default.yml lines 261 to 264
reminder_whitelist:
- *BOT_CMD
- *DEV_CONTRIB
- *BLACK_FORMATTER```
how do we want to detect when the line the parser fails on is probably a match statement? .startswith("match") but that's a bit imprecise :)
oh I was going to just try parsing the file with the match grammar
oh that works too
I'll leave the PR for you to do then as I rather not implement that change - not for technical reasons, I just don't feel like it.
sure, writing the code now
You're so fast compared to me it surprises me every time ๐
just procrastinating from doing real work
I finished most of my work today, I just have some notes to fill out and I should be good to go for today.
that period after match ... looks weird but I don't know whether that's pre-existing or not. I'm not sure whether the backticks are necessary - but they do look weird imo as we don't use backticks as part of our UI language so far.
These are just nitpicks, the overall idea seems fine to me.
thanks, I'll take out the backticks
I put the period in, feel like we need something to separate the code from the message. Maybe I should put in a newline instead
Oh yeah a newline would work better IMO. I thought you had used a newline but it turns out my viewport is just the right size to make it seem like that :p
also apparently we support parenthesized with before 3.10 too? ```(black) jelle@mbpt-root black % black -t py38 -c 'with (x as y, y as z): pass'
with (x as y, y as z):
pass
Yup, we only use a single grammar and the support for parenthesized with was implemented in the grammar itself. On the other hand pattern matching requires adding some names to the grammar object at runtime (on top of the grammar changes) so the parser knows whether to treat match / case a soft keyword
oh interesting, I thought parenthesized with also required backtracking/PEG
PY310_HINT: Final[
str
] = "Consider using --target-version py310 to parse Python 3.10 code."
I guess this is what the 25+ issues about splitting on the RHS vs LHS is all about because damn this is not pretty.
agree
ditto agreeee
Pretty happy with this, now time to implement the rest of the show and compare command ๐
yeah from what you showed me it looks great
I recall there was a benchmark suite for black @bright glacier, would it be possible to run it with -tpy310 to get some profiling data?
I plan to do some improvements over performance today, but it would be nice to learn how slow it is already ๐
Seems good to me, thanks!
@tanvimoharir hey sorry for such the long wait. The tests you added were good but the second one wasn't necessary as we already have tests that cover that area. I made the first (still relevant) test a bit more of an unit test so changes to --code don't affect it down the line.
Finally I tweaked the error message opting to reuse the message already stored in the TokenError, and fixed the merge conflict. Thank you so much and my apologies once again!
What's the status on the TOML bare CR situation btw?
!remind 1D look into doing more outreach in regards to testing the mypyc wheels
Your reminder will arrive on <t:1638740499:F>!
not part of the scope, the issue on toml-lang was closed
the issue on pypa/pipis still open
you've probably already checked them, since it's been 2 hours
It's still open unless you mean a different one.
I think you just pass bytes to tomli and let it decide
Yeah I suppose
@dense jungle how you feel about running the 3.10 grammar check in a thread that has a timeout? https://github.com/psf/black/pull/2668#issuecomment-985982856
I feel like it won't be worth it especially there are files passed to black IRL that are massive
I guess it's a nice additional safety but not sure it's really worth it
I vote nay then as I don't want to deal with multithreading with mypyc or 3.6. It's on the error path anyway so I doubt it'll be a problem IRL.
I believe it would be useful to split up the long list of changes a bit more.
Specific changes:
- Removed the entry for new flake8 plugins; this is purely internal and not of interest to users
- Put regex in the packaging section
- New section for Jupyter Notebook
- New section for Python 3.10, mostly match/case stuff
Happy to change this though if others have a different opinion.
for the longest time i thought lgtm meant 'looks good to merge'
and then i learned it meant 'looks good to me'
you got 3 words out of 4, not bad :P
true
I heard 'let's get this merged' abbreviation in the past too
makes sense
I love it! :tada:
Time to do another release?
@bright glacier we could do another release now, or maybe wait for Batuhan's possible perf improvements?
then again, that could just go into the next one
OH yeah
I guess it doesn't hurt to wait a little bit.
This release candidate is quite packed with changes and it's only been 17 days 
lgtm
lol, do you have a source?
Had to do a bit of searching but I think this is the original source:
https://twitter.com/jschauma/status/1019410471999467525?t=Nan8j9m00u7jKQRJO2ME6g&s=19
It turns out 1) blackbench sucks - I had to hack the source code to support this usecase, and 2) the included benchmarks don't really have any usage of match surprisingly enough.
โฏ pyperf compare_to main-9424e795b-normal.bench.json main-9424e795b-py310.bench.json -G
Slower (1):
- parse-black/strings: 74.8 ms +- 7.3 ms -> 231 ms +- 32 ms: 3.08x slower
Benchmark hidden because not significant (16): parse-black/__init__, parse-black/brackets, parse-black/comments, parse-black/linegen, parse-black/lines, parse-black/mode, parse-black/nodes, parse-black/output, parse-comments, parse-dict-literal, parse-flit/install, parse-flit/sdist, parse-flit_core/config, parse-list-literal, parse-nested, parse-strings-list
Geometric mean: 1.07x slower
I think it's fine if they don't use match statements, if I understand correctly the worry was that it would slow down parsing other code that happens to use match as an identifier
is there a benchmark that calls re.match a lot?
also thanks for running this!
No, I meant literally any reference to match the word not the statement.
I grepped through all of the test files and only black/strings has any ...
https://paste.pythondiscord.com/lomazuhifi.py this is the only file that uses match as an identifier
โฏ blackbench dump black/strings | grep "match" --line-number
17: overlapping matches.
40: match = re.match(r"\s*\t+\s*(\S)", line)
41: if match:
42: first_non_whitespace_idx = match.start(1)
136: match = re.match(r"^([" + STRING_PREFIX_CHARS + r"]*)(.*)$", s, re.DOTALL)
137: assert match is not None, f"failed to match string {s!r}"
138: orig_prefix = match.group(1)
142: return f"{new_prefix}{match.group(2)}"
191: matches = re.findall(
200: for m in matches:
But yeah it does seem to slow down parsing a fair bit if match is used as an identifier
oh yeah ```...$ rm -rf ~/.cache/black/ && time black graphql_/schema/search/_definitions.py
All done! โจ ๐ฐ โจ
1 file left unchanged.
real 0m0.474s
user 0m0.440s
sys 0m0.028s
...$ rm -rf ~/.cache/black/ && time black -t py310 graphql_/schema/search/_definitions.py
All done! โจ ๐ฐ โจ
1 file left unchanged.
real 0m2.744s
user 0m2.692s
sys 0m0.048s
this file uses the variable name "match" like 60 times
I just hacked up a super simple micro benchmark and yeah it's not great
Mean +- std dev:
[main-9424e795b-normal.bench-mini] 20.6 ms +- 1.5 ms
[main-9424e795b-py310.bench-mini] 194 ms +- 25 ms
9.41x slower
This isn't much, but at least a good start (we did 3 overall copies, but seem like the initial one is unnecessary since we never touch that stack, so we do 2 of them now).
main:
$ touch t.py; time black -tpy310 --check t.py > /dev/null
would reformat t.py
Oh no! ๐ฅ ๐ ๐ฅ
1 file would be reformatted.
black -tpy310 --check t.py > /dev/null 0,33s user 0,02s system 99% cpu 0,358 total
this branch:
$ touch t.py; time black -tpy310 --check t.py > /dev/null
would reformat t.p...
whyy is the unexpected EOF test crashing ....
I have no idea ๐ค will check again
oh, CI is failing on main too :(
somehow https://github.com/psf/black/commit/dc8cdda8fdd6941103240ae3279034d2acdc69bc broke the previous commit
right, driver.parse_string can raise ParseError, TokenError, or even IndentationError
now why did CI not catch on jelle's PR? well to avoid (practically) duplicated workflows, one for the push and one for the pr event, we cancel workflows on psf/black for PR event
this means CI doesn't test the revision when the PR would be merged into main
Fix the regression of GH-2317 caused by GH-2668. I explicitly made this PR from my fork of psf/black so the workflows are triggered from the PR event which should catch post-merge issues.
- [x] Add a CHANGELOG entry if necessary? -> the regression hasn't been released yet
- [x] Add / update tests if necessary? -> CI will test this
- [x] Add new / update outdated documentation? -> n/a
@muted haven this should fix the failing test, sorry for the noise!
should we add a changelog entry for https://github.com/psf/black/pull/2670?
I did not include one since I though this wouldn't be the only speed-up we are trying to get but I am not sure at this point
if I can make more that targets this release
It depends how confident you are as we want to release soon :)
you could include one in this pull, and then append to it in the next pr, if it hasn't been released yet
I've looked into more holistic solutions (e.g determining token type on the tokenizer), but it seem very very hard to do so (primarily because of stuff like match ({a: b}) can be either a call to a function named match() or a real match statement). So it would probably require someone (possibly me, but who knows maybe someone else wants to do it) to take a look at my initial implementation for parso, which avoids stack copies at all (It pseduo-emulates the parser stack and DFA pushes).
I don't think I will have time during the week, so I'll try to give it a shot at the next weekend. No promises / expectations though ๐
@bright glacier btw how did you this benchmark?
I tried to run the given file with black on an isolated environment, and I've only observed a degredation of 1.6X;
root@bac268808ff0:/# hyperfine 'touch t.py;black --check t.py'
Benchmark 1: touch t.py;black --check t.py
Time (mean ยฑ ฯ): 158.5 ms ยฑ 2.5 ms [User: 146.0 ms, System: 12.4 ms]
Range (min โฆ max): 155.7 ms โฆ 165.6 ms 18 runs
root@bac268808ff0:/# hyperfine 'touch t.py;black -tpy310 --check t.py'
Benchmark 1: touch t.py;black -tpy310 --check t.py
Time (mean ยฑ ฯ): 243.3 ms ยฑ 4.8 ms [User: 222.7 ms, System: 20.2 ms]
Range (min โฆ max): 239.2 ms โฆ 254.9 ms 12 runs
root@bac268808ff0:/# black --version
black, 21.11b2.dev26+gd9eee31 (compiled: no)
Yeah I suspect it's probably due to black's startup time that the slowdown is less noticable
Possibly. So I assume you only benchmarked parse()?
Describe the style change
When passing dict as a function parameter I often prefer than the dict is split in multiple lines while keeping other parameters in the same line.
Original code:
db.insert('table', {'a': 10, 'b': 11})
Examples in the current Black style
Adding a trailing comma in the dict results in all parameters split, consuming 7 lines, which feel too excessive in the vertical space usage.
db.insert(
'table',
{
...
import tempfile
from pathlib import Path
import pyperf
import black
from blib2to3 import pygram
# First try the relevant function post-refactor in 21.5b1, and fallback
# to old function location.
try:
from black.parsing import lib2to3_parse
except ImportError:
from black import lib2to3_parse
runner = pyperf.Runner()
code = Path(r"{target}").read_text(encoding="utf8")
with tempfile.TemporaryDirectory(prefix="blackbench-parsing-") as path:
# Block the parser code from using any pre-existing cache.
pygram.initialize(path)
runner.bench_func("{name}", lib2to3_parse, code, set((black.TargetVersion.PY310,)))
it's effectively this script
good to know, thanks! (will definitely use this for the future PRs)
note that this script is a bit more complex because it has to handle old versions of black where the APIs changed
parse-black/strings
===================
Mean +- std dev: [uhh-default] 67.0 ms +- 2.0 ms -> [uhh-initial] 227 ms +- 27 ms: 3.39x slower
Mean +- std dev: [uhh-default] 67.0 ms +- 2.0 ms -> [uhh-speedup] 154 ms +- 3 ms: 2.30x slower
parse-match-identifiers
=======================
Mean +- std dev: [uhh-default] 21.8 ms +- 2.7 ms -> [uhh-initial] 196 ms +- 23 ms: 9.01x slower
Mean +- std dev: [uhh-default] 21.8 ms +- 2.7 ms -> [uhh-speedup] 135 ms +- 10 ms: 6.19x slower
Geometric mean
==============
uhh-initial: 5.53x slower
uhh-speedup: 3.77x slower
nice win @muted haven ๐
โฏ pyperf compare_to uhh-initial.json uhh-speedup.json -G
Faster (2):
- parse-black/strings: 227 ms +- 27 ms -> 154 ms +- 3 ms: 1.47x faster
- parse-match-identifiers: 196 ms +- 23 ms -> 135 ms +- 10 ms: 1.46x faster
Geometric mean: 1.47x faster
from a different perspective
Btw do you ship blib2to3 mypy-c compiled? @bright glacier
Not via PyPI yet, but I'm trying to community test the compiled wheels (all of black is compiled, not just blib2to3)
I should probably rebuild the current published set of wheels as main has a whole new set of features at this point ๐
I'll probably get ลukasz or something to tweet this issue out or something because right now I have one successful report for Linux 3.8 which is me ๐
ooh ooh ooh I can do this rn, brb
Worst come to worse I'll just ask the whole core team to help out as we do have all of the hardware necessary to do so
so wait, is the command just pip install black --extra-index-url https://ichard26.github.io/black-mypyc-index/simple/?
theoretically although you're the second person to try as far as I know
you might need the upgrade flag
It's hard hosting on your PyPI
installed fine for me, I think I'm good
I have black, 21.11b2.dev14+gb336b39 (compiled: yes)
Download the wheel and do pip install name_of_wheel.whl no?
๐คทโโ๏ธ I just tried to follow the instructions on https://ichard26.github.io/black-mypyc-index/
well you assume people know how to choose a wheel from a list of entries lol
that's why I hosted my own PyPI style index with github pages :p
Lol
good to know although please don't forget to open a field report as stated in that issue because my memory sucks L)
you don't have to do it now, just sometime after you feel confident in describing your experience with it
although the name of the game here is more about quantities of positive field reports because with enough people y'know someone's gonna manage to break your code 
err how do you clear black's cache? (I assume it does)
rm -r ~/.cache/black
ah fun
tyty
I honestly made myself a simple utility to do this because I run into the cache way too much while developing
wowowowow
black-compiled took half the time of regular black in formatting python-discord/bot
impressive, great job on this richard
neat
lovely! and it didn't crash once I presume?
not at all
phew
smooth sailing
I have filed a field report
and I shall test on WSL for another later
thank you :)
now test by formatting the stdlib
I've formatted it before
followed directly by git checkout .
sigh how do i installed compiled black
I'm doing it
can you wait a little bit
I have a new set of wheels
just gotta push them
dawn, you don't have to wait, but arl shall wait :)
just gotta pull cpython
no its pulled
formatting stdlib now, let's see how it goes
what's your OS, Python version, and arch?
fuck it broke
yeah that's expected
there's an issue on the tracker with various crashes for formatting cpython
ah okie
wsl, ubutnu, x64, and any of these versions
do you have a preference lol?
not really, no
pypy is not supported btw
ยฏ_(ใ)_/ยฏ
3.9.9 ig
or 3.10 because there's probably some random bug with 3.10 :kekw:
well here's the workflow while I unpack the zip to DM you the wheel
lmao
you can
i'll test in a moment, i'm working on my nuke discord bot
excuse me what ๐
wait-- that sounds bad, that's not what I mean
I've been testing slash commands and now i have a bunch of those that don't exist, so I need to clear them
d'ah
So I'm nuking my slash commands
the file is literally named nuke.py
okay done
they gone
did i lie to you?
no
I used 3.9 but the wheel is 3.10
its installed now
?
there
@dense jungle I prefer to do a release now with Batuhan's performance improvement merged so I can update the mypyc wheel index with a compiled release (instead of a development version for the time being). Batuhan said they'll need some time for additional performance wins.
Thoughts?
huh i got this error when formatting the stdlib
maximum recursion depth exceeded while calling a Python object
that's already known lol
lmfao was about to say, better not be expected
basically there's an assignment chain of 1000+ assignments
https://github.com/psf/black/issues/2407#issuecomment-906060619 <- I should probably update this with our new 3.10 support
Lib/test/test_exceptions.py line 1758
# Mutating locals() is unreliable, so we need to do it by hand```
lmfao
Yeah talk about unreasonable input
@bright glacier I ran it, do you want the good or bad news first
bad news first
i didn't run it with time
...why
because the "did you mean" feature of NameError / AttributeError shouldn't slow it down too much, so if there's too many locals the feature is disabled
did it feel faster?
idk i walked away from my pc
:>
oh come on!
Also I think we should consider the fact that we crash on that function with 800 locals to be a feature.
- Jelle
not totally unreasonable ๐
do the crashes look similar to these ones https://github.com/psf/black/issues/2407#issuecomment-906060619
if not then it sounds like I have a mypyc bug to deal with
!remind 40M back from thing i have to do, now do other thing and other thing, but not confused with thing a or b
Your reminder will arrive on <t:1638736121:F>!
I'll update you when I'm done with thing cffc41bd
uh no I don't think so
I'll get you them in text in ~20 minutes
fyi I'm using 3.10 as the runner, and cpython main as the stdlib to format
with this wheel
from this build
afk
nvm, I got it now https://paste.pythondiscord.com/ubolabuqac.coffeescript
err, maybe it's cause I cloned master but am using 3.9.9 rn?
I cloned master and am using 3.10
but black is supposed to be able to
OH
@silent apex specific -t py310 on the cl
oh frick
I didn't even look at your error lol
nope still dies
you need to be on 3.10
I'll install 3.10 and try then
I'mma try a newer revision of mypy actually
black shouldn't be showing that error to user
there's a performance win which inlines most of the refcnt operations
Stuff is still breaking, and now I get that the process pool is terminated as well
what happens if you try a pypi version of black?
You're not running black within cpython/lib right? because then imports would use stuff from your checkout which might not go so well
That is exactly what I was doing, woops
Here's your reminder: back from thing i have to do, now do other thing and other thing, but not confused with thing a or b
[Jump back to when you created the reminder](#black-formatter message)
yeah let's do a release
do you want to do it?
Sure, playing gartic phone with the staff here atm though =p
what
oh nvm a simple mistake nvm nvm
I think you most likely have an empty black directory on your PYTHONPATH somewhere
so it interprets it as a namespace package
that's close enough to what happened, yeah
I guess not necessarily empty
plz review psf/black#2670, thanks
yeah, its black's repo lmao
I can do the release this time
thanks, sounds good!
also we've been running mypyc black at Quora since last week or so and everything has been smooth, I should submit a report
oh! ๐
First release without regex in a loooong time. Let's hope we haven't broken anything this release as man did we have lots of experimental changes.
Checklist - did you ...
- [x] Add a CHANGELOG entry if necessary? -> I think the changes will speak for themselves :)
- [x] Add / update tests if necessary?
- [x] Add new / update outdated documentation?
Sorry for the delay by the way, it turns out I underestimated how much time I had left before I was up to play with staff oops.
@dense junglehttps://github.com/psf/black/releases/edit/untagged-9e05f026ee64102be3a9 looks good?
I'm totally down to remove that contributors part if you'd like
I saw the "auto-generate changelog" button and was curious to what it does ... then played around with its output :p
wait, do github releases now include this by default? cause my extra effort is useless then
Doesn't seem like it, probably due to me tagging them
<@&831776746206265384>
I filed an incident already but alright :)
half expected a scam link after that
when they didn't send, I was like, "fuck i should have dmed modmail"
oh, you deleted it...?
I didn't
but the staff team have filed an incident for the mods to take a look at
ah
I like it, it's a nice touch
looks like I missed all the moderation fun
!remind 1D update docs for stable revision
Your reminder will arrive on <t:1638830768:F>!
hmmm
I want to make a workflow that will be triggered by someone manually running it to trigger a new stable docs build
this means that all maintainers can update the stable docs, just as they can update the tag
worth making, perhaps?
that seems unnecessarily complicated
also this shouldn't be necessary as RTD should theoretically pick up the updated stable tag but doesn't
its not, its a few lines, to use curl and a token to trigger a build
oh right i meant to actually make it trigger on the tag update
which wouldn't be complicated, either
not when a maintainer triggers it as that's already being trigger--
wait a sec brb
i-
i think the problem is on black's end
on this page, https://github.com/psf/black/settings/hooks, there should be a rtd webhook
no the webhook is being fired, it's just picking up the wrong revision somehow
you sure?
nice
nice, new wheels showed up at https://ichard26.github.io/black-mypyc-index/simple/black/ ๐
how did you notice?
Yeah that's because I have to trigger the build and upload the wheels manually.
Describe the bug
Black adds unexpected indent to docstrings when previous lines contains a zero-width space character.
To Reproduce
Run Black on the following code:
class Test:
def test(self) -> None:
"""Test.
Testing...
โ
Testing...
โ
Testing...
"""
This results in the following formatting:
class Test:
def test(self) -> None:
"""Test.
Tes...
Do you guys a GitHub action out to automatically run black on code in a commit or PR?
there's both an action and a pre--dang it jelle :D
perfect
Here's your reminder: update docs for stable release
[Jump back to when you created the reminder](#black-formatter message)
Damn, compiled black really is faster - I just ran it against the pip project and it's probably twice as fast
that is stupid fast startup with compiled black ๐
.. and there's literally a faster startup PR for black (not blackd) so this could get faster (although it does some things I'm uneasy with)
Description
It's been a while since I last checked these pins.
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? -> seems fine to me.
Should we add pre-commit + one of the requirements updaters to hit these files? (Can be separate PR)
pre-commit.ci might not like our local black hook fwiw for autoupdating
I'm going to try to pick up psf/black#2095 and rewrite it (while addressing feedback) and hopefully drive it to completion
hmm, I don't like the existing infrastructure for running transformers - I mayy try to clean it up although I'm nervous I might break something
... is it defined what makes an exponent / base "complex"? https://github.com/psf/black/pull/2095#discussion_r619853433
It might need discussion but I'd say everything but a bare name or literal is complex
And maybe unary operators on non-complex expressions are still non-complex
2**-2 vs. 2 ** -2
though https://github.com/psf/black/issues/538#issuecomment-962448644 wants no spacing for more complex operators
@bright glacier could you edit the title to __b__ump?
I fucked up the commit title too
aw
Oh haha I did not realize I swore in a public channel (not that it matters but in general I try to not do that publicly)
you're grounded for 6 months 
lol yeah
<!--
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];
...
Describe the bug
When using #fmt: skip, if there is no space between the # and f then black fails to format due to different result in the second pass.
To Reproduce
For example, take this code:
def test():
x = 1 #fmt: skip
Wow. Crazy of me not expecting changes here - I don't think django uses black.
So a question about formatting items like function definitions/calls with arguments. Say I have something like this:
def some_really_long_name(some_big_arg, another_big_arg):
# do something
Now if black sees that the function definition line exceeds the line length I set, it'll format it like this:
def some_really_long_name(
some_big_arg,
another_big_arg,
):
# do something
My question is if it's possible to force black to format all functions one way or the other, not have a mix-and-match approach to it? I would like to keep the styling the same for readability, so going with the latter option for all my function definitions and calls would be preferable over the former
I'm afraid not, we'll fit it onto one line if it can!
Only in one direction. If you add a comma at the end the magic trailing comma will split it up
Although, you could use
But I feel like that's pretty ugly for one-argument functions.
Oh for one argument functions I'd be keeping it on a single line
My minor issue was when I would have some heavily indented piece of code where one function call would be formatted in a single line, but a following function call right below would just exceed the line length limit and split into multiple lines, which makes everything hard to read
But hey that tip to add a comma to the last argument works like a charm, thank you!
woah did django land black?
failed mypy when running pre-commit run -a from the basics of trying to setup the repo for black, here's a screenshot:
should this be an immediate concern?
Probably related to your version of pytest. Would be good to get this fixed.
yeah I found my issue https://github.com/python-gitlab/python-gitlab/issues/1539
that looks unrelated, totally different error
When I update black I keep seeing following message:
[2021-12-07 22:35:45 driver.py:266 - load_grammar()] Generating grammar tables from /home/alper/venv/lib/python3.8/site-packages/blib2to3/Grammar.txt
[2021-12-07 22:35:45 driver.py:269 - load_grammar()] Writing grammar tables to /home/alper/.cache/black/21.11b1/Grammar3.8.10.final.0.pickle
[2021-12-07 22:35:45 driver.py:273 - load_grammar()] Writing failed: [Errno 2] No such file or d...
I've made a .pre-commit-config.yaml with:
default_language_version:
python: python3.9
repos:
- repo: https://github.com/psf/black
rev: 21.12b0
hooks:
- id: black
I run pre-commit run --all-files.
Get error in file "black\cache.py", line 13": ModuleNotFoundError: No module named '_black_version'
I've tried reinstalling everything and cleaning pre-commit. Anyone have a clue?
I can't reproduce that @steady plaza , it works fine for me
perhaps try updating pre-commit?
Overall, this must be a positive. All of these dynamic imports makes me a bit iffy style-wise, but if the performance gains are deemed worth it, then it's fine by me ๐ Some comments mostly about the ignore handling below.
Tried in another environment and it works. So weird. I think _black_version.py should be created when setup.py is run but _black_version.py does not exist in my .cache for pre-commit.
How would I go about running a coverage test with my own test for black? I see something called .coveragerc is this something we are suppose to use?
Do you mean that you have written custom tests for Black and would like to measure coverage?
actually, I was just about to write my own test case for black
it has to do with testing the # skip format
but i'm not sure where I would actually add that test case
Oh I see
So adding tests in general
There are a bunch of test files here: https://github.com/psf/black/tree/main/tests/data They have a specific (although simple) structure of input and expected output separated by # output
Yeah it can be a bit hard to parse what's going on ๐
no problem, i greatly appreciate the guidance
it probably saved me quite a bit of time
so i just added a test in data called fmtskip7
the outside files evaluate these different source files so I have to add the string "fmtskip7" to SIMPLE_CASES in test_format.py
If you created the file, yes. But if it was already there, then not needed!
actually, i'll try testing this out right now instead.
sorry if i'm asking a lot of questions..how would I run the specific unit test I created with coverage?
Yikes that might be a bit difficult ๐ since the tests are generated on the fly. There might be a pytest syntax for that but at least I'm not familiar with it.
tox -e py
Isn't it enough to run overall coverage?
Yep this performs the whole test run
and prints coverage info as well
a user reported this bug here regarding the # fmtskip generating an error if it's put together
is this something we need to resolve? Becausei n documentation, we have # fmt skip which has a clear space between the hashtag and fmt
Definitely, either we fix the comment and then ignore, or accept the ignore without a space. An internal failure is not an option ๐
yeah i replicated the error on my machine
Nicely done
and added a test fmtskip7
I'll respond to the issue as well
a, b = 1, 2
c = 6 #fmt: skip
d = 5
yeah test_format.py loses coverage
if you're going to be responding to this issue, do you mind assisting me a bit? This is my first repository i'm trying to make contributions to, and I'd like to become more independent
Sure!
Yep, verified here too!
?
the format is corrected for the comment
I have not used them
fmt off and on i believe are for blocks
that much I know :D
Oh, they need to be in the same level of indentation and start a block, so I guess inline comments are not handled at all
so we're good ๐
so we just need to fix the issue with #fmt skip
im looking at the comments.py
FMT_SKIP: Final = {"# fmt: skip", "# fmt:skip"}
it can't be as easy as just...
It's probably that easy ๐ but what about #fmt: skip etc.
so basically we want to check the format and correct it
I think let's hear from other maintainers on the issue for now, because they might disagree with my preference
I'd say 1) don't fix 2) accept arbitrary spacing
yeah it seems if you add any amount of spacing the internal error dissapears
Oh! So my example doesn't error?
but it renders the skip ineffective
no it does
but something like:
a=1
a=1 # fmt: skip
a=1
I see, so that's corrected to # fmt: skip and not formatted
then it could be possible to reformat other types as well!
Oh.
yeah that's what i meant
Nevermind ๐
And the comment isn't even fixed
the error specifically only happens when you have ```
#fmt: skip
but yeah it doesn't reformat in other cases of arbitrary space
Well this is a mess huh. Best to add this to the same issue, because this is definitely related.
I can make a seperate bug report and link to the old one
That's fine as well!
there's no way to generate a visible report from the test coverage either right?
like to see where certain LOC ran
Hi guys, how do I make when a person leaves their email on my site, then the bot will send him an email, information that he bought on my site? If you can help me, I'll pay
wrong channel, also against the rules my mate!
gamble: !rule 9
!rule 9
YES it worked
prior to the run with the test that has the buggy skip, test format was at 100% coverage
I'm sorry, but where do I find help
Try the lobby or general channels, or the help channels if you have specific questions ๐
now its at 96%
that function specifically?
Thanks
i think what might've happened is the internal error we suffer occurs prior to running these functions
You're not talking about the file test_format.py are you?
Maybe I've confused myself
yeah im referring to the test_format.py test coverage
Odd that adding a data test affects that..
anyway to debug?
Oooh unless, is the test failing with the internal error?
^ yes
Oh I see, the format tests are naturally expected to pass. So coverage isn't really valid
It's the coverage of Black source that matters
If the test suite itself fails, then we can't gather coverage information
So we'd need to first fix the issue, then make the test and finally measure coverage
Or make a test runner that expects the failure. But we'd rather fix the bug, right? ๐
yes
Although it's good to have failure tests as well for user errors, but that's beside the point.
this isn't doing its job I believe
def make_comment(content: str) -> str:
"""Return a consistently formatted comment from the given `content` string.
All comments (except for "##", "#!", "#:", '#'", "#%%") should have a single
space between the hash sign and the content.
If `content` didn't start with a hash sign, one is provided.
"""
Could very well be
i know this is a python server but can anyone help me with this java error in cmd
!ot
Off-topic channels
There are three off-topic channels:
โข #ot2-the-original-pubsta
โข #ot1-this-regex-is-impossible
โข #ot0-fear-of-python
Their names change randomly every 24 hours, but you can always find them under the OFF-TOPIC/GENERAL category in the channel list.
Please read our off-topic etiquette before participating in conversations.
man, I don't know how possible it is to check whether we're in a new expression with the line transformer based system
AFAICT all of the AST information is lost after the AST visitation logic and the visited line is compacted into a list of leaves >.<
what do you mean by "new expression"?
a = [x**y, x**y]
``` right now with the PR code, the lack of spaces between the power operator is allowed because the whole line has more than one hugging power operator
line.leaves=[Leaf(NAME, 'a'), Leaf(EQUAL, '='), Leaf(LPAR, ''), Leaf(LSQB, '['), Leaf(NAME, 'x'), Leaf(DOUBLESTAR, '**'), Leaf(NAME, 'y'), Leaf(COMMA, ','), Leaf(NAME, 'x'), Leaf(DOUBLESTAR, '**'), Leaf(NAME, 'y'), Leaf(RSQB, ']'), Leaf(RPAR, '')]
and this is what I'm working with ...
I feel like I'm missing something obvious though.
Is that bad? That example looks fine to me with no spaces
It's just inconsistent with return x ** y / return x**y, a**b for example
Maybe we shouldn't space that either? The rule could simply be that we never space ** with simple LHS and RHS
Apparently ambv and a few people agreed that a single power op should not hug but honestly I don't understand whyyy exactly
might be worth just having a discussion with some of the interested people about exactly what the rule should be
Thinking about it some more (actually, a lot more) it seems to me like the easiest improvement here is to do what @paugier was suggesting all along, especially clearly in his latest comment, with the following additional twist: if ** is the only operator in the expression, then don't hug.
https://github.com/psf/black/issues/538#issuecomment-593957202
yeah, I don't really see a strong argument there for special-casing single expressions
Description
Reasoning for change can be found here: https://github.com/psf/black/issues/2680
From running individual tests, it's seen that of all the formatting options, the inline option, or # fmt skip causes an internal error for black, when the comment should be reformatted like # fmt off. A proposal for this issue was made in the fmtskip_nospace branch which aims to hard code logic handling this bug within the make_comment function of comments.py.
Checklist - did you ...
...
this feels fragile but then again this entire part of the codebase is fragile :p
skip: skip was honestly quite undertested IMO
Could I get some more reviews on my PR?
Overall LGTM, sucks that we have to pass root around so much, but I guess there's no cleaner way either because having relative paths in the first place is problematic as well.
I could possibly add root to ctx.obj, it would require passing but would be less compared to root as some of the functions already take in ctx
Mjeh, could be worth a try, but let's see what the others think. I'm not sure what else the context is being used for
one thing can be done, make root a class variable for Report, and move find_project_root to teh main black cli function so we can pass root when we are making Report
Sounds possibly good as well ๐๐ฟ
ok @errant barn i tried doing the above change and it looks much much better, pushing the code, would make it easier to decide also :)
Thanks a bunch! I'll have a look right away
@tired shard psst, I think you didn't push it
Describe the bug
TLDR: Black produced code that is not equivalent to the source on pass 1 when processing a multiline format string in the first line of the body of the function.
While this is a proper doctoring:
def fun_1():
"""hello from docstring"""
this isn't:
greeting = "hello"
def fun_2():
f"""{greeting} from docstring (except not really)"""
Regardless, however, it is a valid python code, even though it might not produ...
INTERNAL ERROR: Black produced code that is not equivalent to the source on pass 1.
Describe the bug
--- src
+++ dst
@@ -8252,175 +8252,175 @@
id=
'IndeedXMLRenderer', # str
) # /Name
) # /List
) # /Assign
- FunctionDef(
- args=
- arguments(
- args=
- arg(
- annotation=
- None, # NoneType
-...
I'm a little confused at why we're normalizing the paths to be from the root when emitting the log messages
Right now the code is careful to not modify the passed in SRCs as much as possible so when we do log 'em it's clear they're from what the user passed in
for example, the fact they're prefixed with black/ strikes me as odd given I explicitly passed in src
Actually yeah that's not needed since we have already explicitly shown the project root and sources path
@errant barn pushed, i did push yest but the pre-commit failed, and then I never looked at it until now (wasn't at home)
this was surprisingly simple ๐ still got one major feature to add and a few minor ones
what's the best way to make black still exit with 0 if it couldn't reformat a specific file because of a match statement, but still exit with non zero if something got reformated?
Are you using latest version? Because there is basic support for 3.10 features added
I have 21.12b0
are you using target version 3.10?
as in, --target-version py310 in CLI arguments or this in pyproject.toml:
[tool.black]
target-version = ['py310']
no
Yeah, you need this to have 3.10 support for now as it's still experimental
This is a left-over from my initial comment at #2242. When you have a dict with the item as an blabla as blabla, black can't parse it;
match something:
case {
"key": key as key_1,
"password": PASS.ONE | PASS.TWO | PASS.THREE as password,
}:
pass
case {"maybe": something(complicated as this) as that}:
pass
hello guys , who knows how to connect MongoDB data base to a project using pythoin?
when ever I connect it it says err":{"name":"MongoError","message":"bad auth Authentication failed.","ok":0,"errmsg":"bad auth Authentication failed.","code":8000,"codeName":"AtlasError"}}
hey guys, im trying to make a really basic plugin to copy paste docstrings from pdf. i havent been able to find any resources on how to make a plugin like black for pycharm. can anyone point me in the right direction?
gonna move this to help channel also
!remind 1D do a more proper review on psf/black#2656
Your reminder will arrive on <t:1639434173:F>!
First review pass, nothing majorly wrong but I got quite a few questions.
I'll take a closer look at this tomorrow -- in particular I'll make sure this doesn't break compilation with mypyc which brings its own import time reductions :)
Thank you for working on this!
I implemented your mypy_primer feature request for diff-shades Jelle :)
I guess if we're using a github URL I could rewrite the URL to point to the tree at the recorded revision ๐ค
thanks this is great ๐
<@&831776746206265384>
!ban 898297969684660224 Racism
:incoming_envelope: :ok_hand: applied ban to @neon oasis permanently.
While handling fluent interfaces if the instruction is within parenthesis Black formats it this way:
- Original
(spark.read.parquet(path).select(columns).filter('column is not null').filter((f.size('id_list') > 1) & (f.col('operating_system') != 'iOS')))
- Formatted
(
spark.read.parquet(path)
.select(columns)
.filter("column is not null")
.filter((f.size("id_list") > 1) & (f.col("operating_system") != "iOS"))
)
However if the ins...
this is not a help channel #โ๏ฝhow-to-get-help
also the error message is pretty clear
Howdy y'all. I've been using Black forever, and I feel like it'd be a good time to give back. I'm gonna go through the contributing guide and try my best at some stuff. :'] Just wanted to say hello, etc, etc.
Yo, glad to hear and welcome! ๐
Here's your reminder: do a more proper review on psf/black#2656
[Jump back to when you created the reminder](#black-formatter message)
How do I tell vscode to use the black setting that I defined in the pyproject.toml?
idk if it's the right channel to ask, I started using Black a few weeks ago and one thing I noticed was the use of parenthesis in some cases (like backslashes)
I'm a bit confused about what those parenthesis are
# in:
if some_long_rule1 \
and some_long_rule2:
...
# out:
if (
some_long_rule1
and some_long_rule2
):
...```
is (some_long_rule1 and some_long_rule2) a tuple with a boolean in it ?
(<- python beginner)
In PEP8 [https://www.python.org/dev/peps/pep-0008/#indentation] they specify this as the preferred method to multiple lines for bool masks, args, etc.
(PEP8: "The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. Long lines can be broken over multiple lines by wrapping expressions in parentheses. These should be used in preference to using a backslash for line continuation.")
So, it's not a tuple, it's just syntax which wraps around stuff for multilines and the like. A one element tuple looks like this: (1,) instead of (1).
well i forgot i asked to do this issue
Black auto-explodes imports, collections, function calls, etc. when they contain a trailing comma: https://github.com/psf/black/blob/master/docs/the_black_code_style.md#the-magic-trailing-comma Thi...
!remind 2y actually finish that pr that makes black and isort conflict
Your reminder will arrive on <t:1702513889:F>!
2 years!?
๐ 
you could comment on the issue to get unassigned to not discourage potential contributors :P
i don't check my github notifications enough, figured i'd add some leeway ยฏ_(ใ)_/ยฏ
nah, I'm gonna try it right now
I get emails for GitHub notifications <.<
thought you were serious-ish with those 2 years and that you're not interested in working on it any time soon :P
Yes, it's why we have the --skip-trailing-comma flag
Thanks for explanation!
btw I'm kinda getting better at python (still beginner though), I'm still looking for a friendly open-source project that I can start contributing
is this a good idea to join this project? even if my contributions will be very limited?
Being an older project with a fair amount of cleanup needed there's quite a few rough edges to be honest but overall it's still a relatively easy project to contribute if you choose your issues the right way which I can help out with :)
Also, the core logic behind black is very tree (i.e. node and leaf) heavy so experience in those areas will be required if you want to make changes to the actual formatting -- FWIW when I first contributed I didn't have much experience with mangling tree structures but that didn't stop me from contributing in other ways
Well I watch some AnthonyWritesCode streams and I've done AoC21/day10, so I have some veeery basic notions about linters/parsing
I discovered thanks to AoC, graphs and DFS this week. Is a tree a kind of graph (or inverse)?
yeah kinda -- lemme pull up an example tree black could operate on (after parsing)
I'd be very happy to help on some "easy" issues, please feel free to suggest ๐
!paste
Pasting large amounts of code
If your code is too long to fit in a codeblock in discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.
with open("daylily.txt", encoding="utf-8") as f:
blob = f.read().splitlines()
that's the blib2to3 AST for this code 
https://github.com/psf/black/issues/2560
https://github.com/psf/black/issues/2492
https://github.com/psf/black/issues/2097
Is this related to a problem? Please describe. On Black's future style doc it talks about black handling a with with multiple context managers in a few ways (Python-version-dependent). Desc...
The documentation doesn't say anything about our PyInstaller binaries (or if it does I can't find it). Let's fix that.
Seems easy enough issues 
^ wow my hack fixed bugs instead of introducing bugs
we should have a regression test for this though, another easy issue
thanks! it's 1AM here, I'll have a look tomorrow ๐
you created a tag just for me (and other open-source beginners) โค๏ธ
very kind of you @bright glacier
I've made a "stable release" milestone fwiw: https://github.com/psf/black/milestone/1 -- I don't like using Projects as I find they take too much effort to manage and I end up forgetting about them (also the pre-existing stable project is in disorder), feel free to reorganize it Jelle
None of these are true blockers but they'd be nice to get in -- only formatting issues / PRs in this milestone would count as potential blockers due to the stability policy
Honestly should we aim to get ESP enabled by the stable release? Given there's some formatting changes I'd like to see made to ESP + that pesky performance penalty it feels optimistic that we'd be able to get it in.
Oh yeah, I suppose we should probably make a decision in regards to parenthesized withs by then too as those are gonna get more and more common
Could I get another review on psf/black#2525 and I have mentioned the changes in psf/black#2526
For is_type_comment issue, the formatting of type comments would go into https://github.com/psf/black/blob/1c6b3a3a6fbc50b651d4ac34247903041d3f6329/src/black/comments.py#L105 right?
src/black/comments.py line 105
def make_comment(content: str) -> str:```
<!--
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];
...
Describe the bug
Python 3.10 begins to throw a deprecation warning for the distutils package, which will be removed in Python 3.12. The recommended fix is to use setuptools or to check PEP 632 for alternatives.
This isn't a workflow blocking issue, as pressing Enter or typing a command brings you to vim as normal; its just an extra step when starting Vim, and a deprecation that should be fixed for Python 3.10 (and especially >=3.12) support.
To Reproduce
On a system wi...
.
Is black conflicting with flake8 ?
black autoformats my_list[i:i+1] into my_list[i : i + 1]
lol exactly the issue I had
I just switched to mypy but now I have another problem/question ( #help-pretzel )
!remind 2D mark that isort issue up for grabs ๐
Your reminder will arrive on <t:1639686283:F>!
I'm so happy we added a FAQ, I'd've been happy even if this was the only entry
i'd've -- I saw this once on a YouTube video and I love it now.
was not expecting to find that in the Collins English dictionary, nice! https://www.collinsdictionary.com/dictionary/english/idve
hmm I wonder if y'all'd've would be in there too ๐
no I'm not kidding ๐ I'm genuinely curious
I think we'd'ven't
'hank goodness
well this escalated quickly 
Uh kinda? I was born in Canada but my mother's tongue isn't English but then again I can't really speak my mother's tongue ..
Like I know French better than I do my family language :?
oh ๐ well close enough!
cause I've heard that there is no central authority on english language, so if it's in use, then it's correct ๐
especially if a (kinda) native says it
Wait, I might using "mother's tongue" incorrectly
I thought it was literally language your mother speaks but apparently means "native language"? Ugh I need to crack open a dictionary
Like I live in a non-English/French household but I can only speak languages of the place I live (which is English et le franรงais)
So technically if the bar for knowing a language is super duper low I'd count as a trilingual but practically I'd call myself 1.5 bilingual
well... that's awkward
Chinese in particular Mandarin
Can't write or read it all
oh shoot, cool
Je peux seulement รฉcrire /lire en franรงais ou anglais
My wife is kind of like that, her family is Chinese but she can barely speak it now
joo just nii, jep
I can't even read the latinized writing aka pinghi?
Romanization of Chinese (Chinese: ไธญๆๆไธๅ; pinyin: zhลngwรฉn lฤdฤซnghuร
well I was pretty wrong :p
now to guess what's the meaning of all those accents
It's fun knowing some French since I can now attach meaning to accents and seem more cool than I really am
it's tone, though don't ask me which tone ๐
Sure :D I only know basic umlauts, and the stress รฉ on my last name
I heard there's four ones, flat, rising, falling, and some wavy one ..?
No wait, I can hear my father disapproving from 300 kilometers, not a stress, but an acute accent ๐
un accent aigu ๐ฅ
I should probably do my french gรฉo homework now lol.
Every damn time I get French ads inbetween my background music, it's really something.
Beautiful language though, even though I'm quite clueless to its meaning
Resolves #1630. This PR adds the basic infrastructure for that, so the future PRs (e.g for print_function) can easily use it without touching the core logic.
https://github.com/psf/black/issues/2688#issuecomment-994116954 this is my best guess at what they're aiming for roughly ๐คท
Describe the bug To Reproduce For example, take this code: this = "code" And run it with these arguments: $ black file.py --target-version py39 The resulting error is: cannot form...
Description
So people with light themed terminals can still read 'em. Noticed the issue in GH-2688.
Checklist - did you ...
- [x] Add a CHANGELOG entry if necessary?
- [x] Add / update tests if necessary? -> I have no idea how to test this.
- [x] Add new / update outdated documentation? -> n/a
except the error message they posted says "cannot format file.py: INTERNAL ERROR"
unless that's from the template?
hmm it might be
So basically the whole main post is useless garbage while the comment they added is the actual issue, sigh.
right, I think you got the actual issue out though, thanks!
oh wow we actually assert that the right ANSI codes are expected in the output >.<
I was not expecting that at all.
that is the most comedic issue title i have seen
hmm I can't reproduce psf/black#2594
Given code like
assert "errors" in graphql_query(
"""
...long literal...
""",
).json()
Black insists on formatting it as
assert (
"errors"
in graphql_query(
"""
...long literal...
""",
).json()
)
which does not look like an improvement at all. Remove .json() and suddenly Black is happy with the code as is.
Thanks!
ah, typed-ast supports <> but not the built-in AST haha
Description
Resolves GH-2594.
Checklist - did you ...
- [x] Add a CHANGELOG entry if necessary?
- [x] Add / update tests if necessary?
- [x] Add new / update outdated documentation? -> n/a
man, honestly I might approve psf/black#2526 even though I don't understand the changes in regards to us printing the SRC
monorepos.
( or similar )
yeah I know I just hate myself for going back and forth on this PR so many times
basically I'mma give up on fighting for my opinion here since clearly it's dumb
flip is a command
heads approve it, tails deny it /s
@tired shard I'm so sorry for being so flip-floppy on this verbose PR, it looks good to me except now I realize why including the root in the log messages was a good idea (for the SRCs log mind you, I still disagree it's a good idea in the other logs).
Basically, my opinion here is use felix's output design because it's way better than what I can come up with but let's try to avoid touching the other printed paths in the logs since people are probably used to how it works
but overall, if it feels dumb, then ignore my opinion, I'm as done with this PR as you are most likely and I don't want to fight it anymore
PS. it crashes if you format a directory that doesn't share a common base within the project root
This is probably my fault and I'm sorry for this too.
also, it seems like felix's output has the "identified X as project root" line before the "using configuration from project root" line which seems better to me
all sources that are about to be formatted relative to the project root, meaning that if I'd run black . ../tests in one level into the project e.g. in project/src, I'd see something like about to format: project/src and about to format: project/tests
If my defeated ranty paragraphs were confusing, the TL;DR is to apply this comment to the sources line (and maybe the "reformatted X" lines too if just applying it to the SRCs line is dumb - i.e. revert my feedback).
[Feedback given on Discord](#black-formatter message).
https://github.com/psf/black/runs/4528535309, OK I'm done today
if someone wants to fix this I'd be happy but I'm not doing so right now.
gotcha covered, go take some time for yourself
# this is invalid code:
for x in f(lambda: i := 0,):
pass
# black formats it to:
for x in f(
lambda: i := 0,
):
pass
remove the ,
93701d2 use valid package-ecosystem key (#2694) - onerandomusername
3501cef Include underlying error when AST safety check ... - ichard26
https://github.com/psf/black/pull/2695 it works ๐
yeah thanks richard, I will look into your feedback and address it soon :D
Your reminder must have a content and/or reply to a message.
!remind 3d that
Your reminder will arrive on <t:1639794214:F>!
you can reply to a message and the bot will use the linked message as the content field if it's not provided explicitly
yeah, i was the one who created a issue for that lol
and I reviewed the contributing PR :)
Using black, 21.12b0 (installed with pip3) on Ubuntu 20.04, integrated with the atom-editor package.
The problem is black seems to be messing up working code, introducing duplicate definitions of well defined functions and putting bracket opens and close at random places that are throwing error.
Even if pylint was showing only warning and no error before applying black, the pylint itself is showing multiple errors after formatting with black.
I have been recommended python black r...
maybe their editor is doing something weird?
I am still printing them relative to root for SRCs log and I think I am using felix's message design just using confgi is before identified, i would do that change.
hmm but I do call .absolute() on it 
src/black/__init__.py lines 533 to 536
paths = '", "'.join(
str(Path(source).absolute().relative_to(root)) for source in src
)
out(f'Sources to be formatted: "{paths}"', fg="blue")```
Do you mean Path.resolve()?
doesn't absolute also do that 
You know, I thought it did, but looking at pathlib's documentation I cant see a reference to it ๐
I think there's a longstanding bug about clarifying the behavior of those two
Isn't one of them undocumented?
probably, well that works :D I will push the fix
The link was visited as well ๐
purple lol
Oh, from the discussion: Path.absolute() means exactly Path.cwd() / p
for this, we print out the srcs log in get_sources which called pretty later than the config log, so i am not sure if it is oky to move it down
felix had also probably suggested that
and i gave the same reasoning
here
pushed
man this conflicts
now you have .absolute().resolve() though
One option could be to only calculate the root once, maybe by caching or something.
Or pull the find_project_root out from find_pyproject_toml and just pass the found root there. Now it just directly calls it with the argument and it's only used there.
src/black/files.py line 74
path_project_root = find_project_root(path_search_start)```
oh right, that's not really needed, .resolve() would do that job
for moving the root log above config?
hmm, i could move find root and method to the main function and then cache them to ctx.obj[]
edit"
and richard review
which can then be used in get sources
That could be nice, a small performance gain as well ๐
not really, we only call find root once i think
That reminder has been deleted successfully!
ah yes
Hi, I've been using black for a while and want to contribute and was looking at https://github.com/psf/black/issues/2097
i see in the code comments that
All comments (except for "##", "#!", "#:", '#'", "#%%") should have a single
space between the hash sign and the content.
but the formatter only adds a space if there isn't one, and doesn't remove extra space
i was wondering if all comments should only have one space or should that only be for type comments
Only type comments I think. Otherwise we may mess up commented out blocks of code.
Description
Fixes #2097 and standardizes type comments to always have 1 space after the # and 1 space after the :
As per the issue, the functions is_type_comment() and contains_pragma_comment() have been modified to return true even with any extra spacing. Type comments without non-breaking spaces are now stripped of any extra spaces as well.
Checklist - did you ...
- [x] Add a CHANGELOG entry if necessary?
- [x] Add / update tests if necessary?
- [ ] Add...
ah i thought it was required to be type:
NOot sure
as long as we're fixing the comments, I think #\s*type\s*:\s*whatever is fine in my opinion, but worth it to check especially from Jelle
ok ngl when i wrote that i completely forgot regex existed
can change it to use it and make it a lot cleaner
#\s*type\s*:\s*(.*) and then rewrite it using the group
yup
let's discuss details in the issue
To Reproduce
Given input:
class ThisIsTrulyUnreasonablyExtremelyLongClassName:
pass
def frobnicate() -> "ThisIsTrulyUnreasonablyExtremelyLongClassName | list[ThisIsTrulyUnreasonablyExtremelyLongClassName]":
pass
Black does not split the long type hint of the function return type
Even if I explicitly attempt to split the string:
def frobnicate() -> "ThisIsTrulyUnreasonablyExtremelyLongClassName | " \
"list[ThisIsTrul...
This turned out hard to read after some working sessions.. I just removed the tool that I wrote which formats first with black and afterwards it makes tabs of size 2, now I'm just using black hahaha
Is there a list of which Black version is good for some specific Python version? I'm getting an error with black 21.12b0 and Pyhton 3.8
Traceback (most recent call last):
File "/opt/miniconda3/envs/<env>/bin/black", line 6, in <module>
from black import patched_main
File "/opt/miniconda3/envs/<env>/lib/python3.8/site-packages/black/__init__.py", line 49, in <module>
from black.files import find_project_root, find_pyproject_toml, parse_pyproject_toml
File "/opt/miniconda3/envs/<env>/lib/python3.8/site-packages/black/files.py", line 27, in <module>
from black.handle_ipynb_magics import jupyter_dependencies_are_installed
File "/opt/miniconda3/envs/<env>/lib/python3.8/site-packages/black/handle_ipynb_magics.py", line 15, in <module>
from typing_extensions import TypeGuard
ImportError: cannot import name 'TypeGuard' from 'typing_extensions' (/opt/miniconda3/envs/<env>/lib/python3.8/site-packages/typing_extensions.py)
Simply by running black __init__.py on an empty init file
The Python version is fine, your typing-extensions is too old
I see. So this is basically an issue with conda messing up. Thanks
yeah, we require typing-extensions 3.10.0.0 in setup.py, looks like you have an older version
https://github.com/psf/black/issues/2681 honestly, would it be better to just delete these log messages? I don't see much value having 'em and we keep getting new issues asking about them >.<
agree
technically the ideal option would be to integrate blib2to3's grammar caching with black's cache mechanism but that'd be complicated as this cache attempt occurs on import
actually no, it's not that complicated and I have a working implementation. Time to write a test (or two).
Description
This PR uses modern approaches for building wheel and source distributions.
According to the build docs:
build is roughly the equivalent of
setup.py sdist bdist_wheelbut with PEP 517 support
So the modern equivalent is simply:
python -m build
which builds a *.whl and *.tar.gz file in dist/. Setuptools and wheel do not need to be installe...
Yay for more modern packaging standards and tooling :)
thanks for noticing and fixing this!