#black-formatter
1 messages ยท Page 28 of 1
actually no, i think it can be done in a short way, got a new method
ig its gonna be abit hacky
ok i think i got a way this can work, but not sure if it will be fully accurate
hmm, maybe i found a bug with diff, or I messed up something
richard ping me you come online
also do you want me to add line numbers?
nah, I think the line numbers already present in the diff are good enough and should have no room for misinterpretation given how common they are
hmm I don't like those red/green colours but I guess that's just your terminal's color palette haha
that's a random green/red i chose just so that it is working
i got a bug/problem while testing hence asked you to ping, but now am too tired to talk about it
using the standard red/green markup should be good enough, we don't need any fancy RGB based colours lol
feel free to push your changes and I can take a look later
but thank you for working on this! maybe with enough hacky code we can make this work
(future me is going hate me for writing unmaintainable code :p)
... hopefully not!
not really a bug with testing, but with the current code, basically there is a diff on this two JSONs but the diff doesn't show any diff
(putting them in dms)
well, it is not all hacky now, i basically syntax highlight each line separately, shortcut
like the whole JSON?
the analysis output, not sure what you mean
there's some metadata in each analysis's JSON
that's why the code compares them by checking each ProjectResults dictionary within the Analysis object
yeah, ik that
basically the syntax highlighters don't depend on the earlier code whlie highlighting so it won't make a difference if they are highlighted separately
Here's your reminder: it mayyy be worth doing a security audit of the current workflow setup
[Jump back to when you created the reminder](#black-formatter message)
Here's your reminder: have you done something yet?
[Jump back to when you created the reminder](#black-formatter message)
yes :D
@tired shard OK, so I was going to approve your verbose PR (after doing some cleanup and pushing 'em to your branch) but there's a case where the PR makes the output worse IMO
Here's your reminder: See referenced message.
[Jump back to when you created the reminder](#black-formatter message)
while it's more informative in that it's clear the configuration is coming from the project root -- it's not indicated what the project root is
@errant barn since your feedback has been so useful at pushing Shivansh's PR it'd be super kind of you if you could re-review the PR soon! I'm happy with it (barring some minor stuff) and I won't block the merge on your review but it'd be nice haha. Happy Christmas by the way ๐ !
Obviously any holiday celebrations / family time should take priority over OSS work ๐
Hmmm, IMO while formatting code there should be option - if you want it to follow your config or not since sometimes i use black to format code generally and not always according to my config.
Also merry christmas ๐
Yeah Felix opened an issue to add a flag of something like --isolated (I don't remember the name he gave it) to disable autousage of configuration
if that's the case, we could add the project root if its not isolated, and remove config/root if its isolated
it's Christmas Eve where I am right now -- though that will change in less than 30 minutes ๐
If we implement that issue this sounds reasonable to me!
nope, lemme find it
hmm, so block this pr until that is implemented or add some basic handling for now and fix it along with that pr?
psf/black#2537
hmm, seems a short pr
well no one has approved it yet lol
that's where you come in ๐
Merry Christmas to you too! And to everyone here ๐ And I'm sorry that I won't be reviewing it at least until the 27th, but I think I'll be on then! If you're not in a hurry ๐
๐ help I ended up reviewing a github actions workflow today
Sometimes you need a break from family
lol
Oh 100% take your time off 
โฏ git merge main
Auto-merging .github/ISSUE_TEMPLATE/bug_report.md
CONFLICT (content): Merge conflict in .github/ISSUE_TEMPLATE/bug_report.md
Auto-merging pyproject.toml
Auto-merging setup.py
CONFLICT (content): Merge conflict in setup.py
Auto-merging src/black/__init__.py
Auto-merging src/black/linegen.py
CONFLICT (content): Merge conflict in src/black/linegen.py
Auto-merging src/black/mode.py
CONFLICT (content): Merge conflict in src/black/mode.py
Auto-merging src/black/nodes.py
CONFLICT (content): Merge conflict in src/black/nodes.py
Auto-merging src/black/parsing.py
CONFLICT (content): Merge conflict in src/black/parsing.py
Auto-merging src/black/strings.py
CONFLICT (content): Merge conflict in src/black/strings.py
Auto-merging tests/test_black.py
CONFLICT (content): Merge conflict in tests/test_black.py
Auto-merging tests/test_format.py
CONFLICT (content): Merge conflict in tests/test_format.py
Auto-merging tox.ini
Automatic merge failed; fix conflicts and then commit the result.
well this is fun.
Honestly it might just be easier to recreate the branch instead of fixing all of ese merge conflicts.
actually, fixing merge conflicts in vscode is so much nicer than using vim
Is this the mypyc branch?
No an old branch that drops all of the Python two code :)
We're planning on dropping Python two support in January 2022 haha
Do you guys know how can I get single quotes instead of double quotes?
I mean, not force it, but prefer single quotes
You can't force black to replace double quotes with single quotes but you can use the --skip-string-normalization / -S to disable black from touching your quotes. Otherwise use a fork of black on PyPI.
๐
or edit the source everywhere that needs to be edited yourself ๐ฅฒ
not that i recommend that
I really don't get the decision making behind the idea of double quotes, it's really ugly
!pep 8
I just execute a macro in vim, but it's really annoying
oh actually pep 8 doesn't pick a stance, nvm
I couldn't leave a review?
I won't be submitting it as a PR until later as we might do another release (or two) with Python 2 support still there
tldr why drop py2 detection, that should probably still stay so we can tell the user it's unsupported
....
genuine review comment lol
src/black/parsing.py lines 117 to 122
if matches_grammar(src_txt, pygram.python_grammar) or matches_grammar(
src_txt, pygram.python_grammar_no_print_statement
):
original_msg = exc.args[0]
msg = f"{original_msg}\n{PY2_HINT}"
raise InvalidInput(msg) from None```
also read the commit message lol
nice approves
I tried to not review anything today
instead I signed off on a pre-commit workflow to a very used open source project that uses isort and black
I'm working on a bunch of maintenance stuff I left on the back burner for psf/black. First the removal of Python two support, and now the transition to nox
lol
I'm not 100% decided on moving away from tox to nox but overall I like nox way more sooo
I do :)
โฏ nox -l
Sessions defined in /home/ichard26/programming/oss/black/noxfile.py:
* lint
* tests-3.6
* tests-3.7
* tests-3.8
* tests-3.9
* tests-3.10
* tests-pypy3
* docs
* docs-live
* fuzz
sessions marked with * are selected, sessions marked with - are skipped.

How is this related to the black autoformatter project?
then maybe don't post it here as right now it'd be considered as spam
that's fine, just don't dump random images without context -- you might be able to get away with it in the off-topic channels but this is not one of 'em.
join the communist party of donger
OK, please stop -- this is off topic here.
what is this black formatter?
@hollow gazelle @cursive ravine guys, this is not that kind of server/channel.
sorry
In goes python code, out comes neatly formatted python code.
what is formatting?
try out this website, input code goes on the left and output code goes on the right https://black.vercel.app/
Playground for Black, the uncompromising Python code formatter.
so it cleans op your code
Yeah, but just visually, it won't touch the meaning of your code.
Sorta like how you can make text bold in some editors, it doesn't affect the meaning (well usually) but it can make it easier to parse / read
How to change the line length of black?
Thanks
Also, is there any way to stop black from changing this long list into a column?
# fmt: skip ? it's pretty buggy so you might have to use the more battle tested # fmt: off and # fmt: on pair
Could you elaborate on where I have to put these?
fmt: skip would go at the end of the line
fmt: off/on surround a block of code to disable formatting for
a = 1 # fmt: skip
# OR
# fmt: off
a = 1
# fmt: on
that worked, thanks!
Description
Since power operators almost always have the highest binding power in expressions, it's often more readable to hug it with its operands. The main exception to this is when its operands are non-trivial in which case the power operator will not hug, the rule for this is the following:
For power ops, an operand is considered "simple" if it's only a NAME, numeric CONSTANT, or attribute access (chained attribute access is allowed), with or without a preceding unary operator...
first time I'm hearing "hug" as a term for no whitespace around the operator ๐
wow CI is quite red tonight 
ahh I pressed the wrong keybinding
10/10
done that before
no worries
also you have manage message perms, you can hide your mistakes
sweep them under a rug
OK interpreted black is really slow on my machine ๐ฆ
yay
I was working on the speedup against -t py310 and seems like it moved somewhere from 'awfully slow' to 'somewhat acceptable' in my eye.
[black main -tpy39] Mean +- std dev: 7.30 ms +- 0.26 ms
[black main -tpy310] Mean +- std dev: 39.8 ms +- 1.7 ms
[some experimental branch -tpy310] Mean +- std dev: 13.5 ms +- 0.6 ms
Though no promises on when (or even if) it will be a PR. The branch that I have this optimization is still a mess (fusing 20 years old lib2to3 code with dark magic doesn't look great), and since it got speed up noticeably I wonder whether there are any edge cases we are missing. If there are none, I'll clean it up and make it more presentable ๐
The current revision of the new backtracking parser (that gets enabled with -t py310) is kind of slow.
For regular inputs that only use match/case without using the pattern matching statements, it is somewhere between 3 to 4 X slower at the moment (going up to 6 or 7 on hand crafted inputs). On some inputs (like Lib/test/test_patma.py) that contain match/case hundreds of times, with new PEP 634 statements, it...
Resolves #2727
Core Idea
The current parser; even when it is backtracking, builds nodes which is a terrible waste of time since every time we see a match or case, we need to copy the whole stack over and over in order to preserve the actual structure and not do any modifications on top of it. This is obviously not cheap.
The following implementation does something very similar to old school state machines, where the parser is temporarily converted into a structure that tells you...
@muted haven wait is this change testable without the 3.10 grammar?
I can configure diff-shades to use --target-version 3.10 but I was curious to the scope of this change
oh brilliant mypyc is broken on main as well because we introduced AnyStr to resolve some type ignores
Nop. It only changes stuff when we are under -t py310.
OK, sounds good.
But what I am curious is that, whether it will break any regular parsing of re.match() or case = blabla etc.
since I think I pretty much covered all PEP 634 syntax, and it can also parse as much of the stdlib as it can previously parse
Yeah, I suspect lots of hand testing will also be required but running it against https://github.com/ichard26/diff-shades/blob/ca6ea0f4bfbe42135cfa75a182e31fa3c4d97aa2/src/diff_shades/config.py#L35-L72 should help too
Hmm, gh api "https://api.github.com/repos/ichard26/black/commits/f5a202d0d29556719ff9464d64c75a04aceda2f8" doesn't return a 404, I might be able to run diff-shades from my fork to test out your PR upstream which would be ideal cause my laptop is painfully slow
This feels like the sort of cross repo access that shouldn't be allowed but I'm not complaining (unless this is due to my API key)
It seems to be a public API, I can access it without any authentication.
Hmm cloning performance seems to be miserable right now, diff-shades keeps on getting stuck on cloning the projects and sometimes even crashing - I might have to investigate other ways of pulling down projects (maybe github.com/**/archive/*.zip ?)
Actually GitHub Actions in general seems to be suffering poor performance
In case it turns out to be this, sometimes GitHub lower your bandwidth when you make an excessive number of clones through git.
I was writing a benchmark script for a project, which got a fresh clone every time we run it to compare the results in case the main in the local user was not up-to-date. Then we noticed clones got substainally slower (from 2-3 MB/s to 50kb/s), which GitHub seem to be lowering bandwidth for our IP.
primer easily does way more clones than what diff-shades is doing on my fork given it's a matrix build
I wonder if my fork has less "allocated" resources for a lack of a better way of describing it
If the target repo's are not getting constantly upgraded, perhaps you can do actions/cache on them for a week or so.
seems to working now though so that's good: https://github.com/ichard26/black/runs/4637476560?check_suite_focus=true
Hmm I did not know this, interesting!
Yeah I decided against caching the repos themselves given diff-shades is going to be mostly ran on GitHub infra so I expected performance to be solid but if this is the case it mayyy be worth it
It does seem like --target-version py310 is much slower on main, the project after hypothesis (edit: it's pandas) should not take more than 5 minutes
Weird, I'll try to hand verify it
You realize this is main right? not your PR don't worry lol
Ah, ok. I thought my branch was slower compared to main lol
main is so slow that by now a normal (i.e. the target-version configuration is pulled from each project instead of getting overwritten) run of this workflow should be done ๐
yeah it's the downside of trying to quantify performance improvements, often getting the baseline data is horribly slow (especially when the speed up is up to 50x haha)
indeed 
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Summary โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ File breakdown Project breakdown โ
โ Result # of files Result # of projects โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ nothing-changed 8263 nothing-changed 13 โ
โ reformatted 1782 reformatted 10 โ
โ failed 0 failed 0 โ
โ โ
โ # of lines: 2 057 627 โ
โ # of files: 10045 125 479 changes in total โ
โ # of projects: 23 84 727 additions - 40 752 deletions โ
โ โญโโโโโโโโโโโโโโโโโโโโโโ [custom arguments] โโโโโโโโโโโโโโโโโโโโโโโฎ โ
โ โ --target-version py310 โ โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ โ
โฐโโโโโโโโโโโโโ black 21.12b0 - Dec 26 2021 19:33:56 UTC โโโโโโโโโโโโโโฏ
``` my laptop would be so mad at me if I tried doing this - for reference a normal run of primer (which has the same project set as diff-shades) takes 25-35 minutes 
can't imagine how long that will take with -t py310 then
very nice very very nice
I'm proud of you ๐
no that's not sarcasm
is that for isidentical or me lol
okay maybe a little sarcasm
I don't know isidentical well enough to be proud of them smh
Wow okay the shade /hj
diff-shades
I've never seen you break black ever.
well, not yet I guess ๐
You can clone with a depth of like 1 - that will grab the repository with only the latest commit.
It is doing that and it was still crashing https://github.com/ichard26/black/runs/4637436255?check_suite_focus=true#step:9:104
Yeah it's been bad today
Some comments still! Did you have a look at the test Richard requested? Or maybe they are the old tests you modified and I'm just reading things wrong. Anyways, thanks again for the changes and let's give it a push once more ๐ I can't believe this conversation is already like 30 comments long, seems like no change is small in a project this big :D thanks for holding up
Sorry to bother you, I'm new and I need help because I looked at wiki and Google and didn't get a workaround, I couldn't install Blackd. PIP doesn't have this option, I tried Py3.9.7 and Py3.10 and failed.
What install command did you use specifically? Your comment makes me wonder if you tried pip install blackd instead of the correct black[d]
sorry.
Did it work? ๐
Perfect! It's known as an install extra. Lots of libraries have them, like httpx[http2].
As you might have guessed already, they enable some extra functionality, like for us the Black server!
actually on this note I made a logo for diff-shades
it needs a minor fix but other than that I like it
oh that's nice
this border needs work but it should be easy to fix
fwiw I did this 100% via google drawings ๐
Actually, Felix, have you looked at the diff-shades CI integration I posted four (three?) days ago? Just wondering if you're totally lost at what diff-shades is 
Yeah I know what it does, but I haven't had a thorough look ๐ I don't really know that much about primer either
But everything you've presented has looked nice
Ah alright, I just didn't want to shove a project (logo) in your face without context haha
Well I couldn't have missed it since you have been working at it for quite a while now!
me: *shows felix a logo*
felix: "that's nice"
also felix: *what the heck am I looking at?*
this is what I was trying to avoid ๐
Nice logos are nice though, even in isolation
Having a glance at your PR now: those bot comments look really useful
Pycharm? you might have better luck with a help channel (see #โ๏ฝhow-to-get-help ) or #editors-ides
It's not perfect given sometimes we need to run black with specific arguments which the PR mode doesn't allow for configuration but in those cases the manual workflow_dispatch event should do
(I bring that up since the first PR I used the workflow on was a case that needed --target-version py310 haha)
right :D
If we start with "correctly" formatted code
my_dict = {
something_long.SomethingLong.SOMETHING_LONG:
lambda e: something_really_long.SomethingReallyLong.some_function_with_long_name(
some_argument
),
}
and then run Black, we get lines that over 120 characters in length
my_dict = {
something_long.SomethingLong.SOMETHING_LONG: lambda e: something_really_long.SomethingReallyLong.some_function_with_long_name(
some_argument
...
Hi, would love feedback on pull #2721 and also would like to know if it would ever be merged or not. Thanks ๐
I'm interested in what the pull request review process looks like for a project as big as black.
well it depends really on the maintainer story of the project -- psf/black is fortunate enough to have quite a few active maintainers (four usually) but even then reviews are the main bottleneck
Felix and I are the only active maintainers of lately due to holidays and vacations the rest of the core team are enjoying -- and unfortunately I haven't been interested in reviewing something as major as your PR.
I wrote some python code . like:
seed = {
"genesis_block": {
"BlockId": "65b3d55b-73b5-4d13-9550-4d37d53ec7d3",
"GroupId": "89703dbe-93c6-4be0-ba26-dce563181194",
"ProducerPubKey": "CAISIQPTrmj7NOYeFFXgxe5dHuEqQ5dEtL5WIvFD5i6jD2He+w==",
"Hash": "16wubZBYp8jWpYZtAy73WsfeR3vRDADOEqIfrfi74/g=",
"Signature": "MEUCIQD5UUyFPx2CzFFwCnFLN7gxfV30zQBmjS2jybSUls8yLgIgOvhOJdsGh5wrb0FmG5mGxdChSaINdyTpUZE6JVYE5hI=",
"TimeStamp": "1640423797361990300"
},
...
Is this related to a problem? Please describe.
The newer versions of the WingIDE, (8.x) have an option to use automatic formatting with black. The current documentation only mentions manually running Black from within Wing by executing a command line and linking that to a key binding.
Describe the solution you'd like
Mention the mechanism for enabling black auto-formatting in Wing IDE.
In docs/integrations/editors.md add that - for Wing IDE versions >8 you can enable Bla...
can I suggest them to use the json module 
!e
s = '''H'i'hdks' '''
r = s.replace("'",'"')
t = s.replace("'", '\"')
print(r)
print(t)
@plain atlas :white_check_mark: Your eval job has completed with return code 0.
001 | H"i"hdks"
002 | H"i"hdks"
@errant barn in response to your comment, yes they are the same
Yeah that was more rethoric(al?) than an actual question :D I remember at least one identical issue closed earlier
re. psf/black# 2721 - There's also a problem with the --docs and --ipynb flags as they don't mean the same thing
--ipynb (and --pyi for that matter) force all files to be treated as jupyter notebooks / stub files as far as I remember, but --docs enable documentation formatting. But I don't think we can sanely default to formatting documentation given people call black with . and it's not gated by an extra dependency
It mayyy be better just to leave --docs (although I'd prefer --md) as the "force all inputs to be documentation" flag as per usual and then let users configure their include configuration to include documentation files
It does beg the question of maybe it would be better to just have a --force-type (feel free to bikeshed this name) choice option with pyi, jupyter, md, and so on as the possible values in the long run
also apparently I messed up the issue ref. psf/black#2721
But yeah the fact documentation is so vast does worry me how much complexity the project might take on
Oh you're right! Only changing input mode could be a cleaner solution. Although that would require multiple runs of Black. But letting these be other libraries might be an even better solution once we define a Python API! I'm not sure what we should do to our ipynb things in that case. psf/black-ext anyone? :P
yeah our "just let the extensions handle it" would be a more much more compelling case if we had a stable API :p
Describe the bug
pre-commit hook fails to format code with the Structural Pattern Matching PEP 0622.
To Reproduce
Files
.pre-commit-config.yaml:
repos:
- repo: https://github.com/psf/black
rev: 21.12b0
hooks:
- id: black
pyproject.toml:
[tool.black]
target-version = ["py310"]
file_with_310_features.py
match "this":
case "that":
print(1 + ...
!mute 856241202005016626 ๐
:incoming_envelope: :ok_hand: applied mute to @cursive ravine until <t:1640823936:f> (59 minutes and 59 seconds).
ok sherlock homes
could you delete this too now that it's been taken care of?
(they have internal logs so it's fine to delet)
noice thx
Description
Update documentation about Wing IDE integrations in the 8.0+ version. In the new version Wing IDE have special global and per-project setting for reformatter like black and yapf.
for #2731 hope it help :)
Checklist - did you ...
- [x] Add a CHANGELOG entry if necessary?
- [x] Add / update tests if necessary?
- [x] Add new / update outdated documentation?
Note
I don't think docs need changelog, Also thank you so much to black contributor and ma...
[NSFW]
...what?
there's definitely someone working in a formal setting who's intentionally unformatted
Overall looks great, just a minor issue and a typo :slightly_smiling_face: thank you!
b8df7e4 Drop upper version bounds on dependencies (GH-2... - JelleZijlstra
I'm opening too many PRs with no one else to review 'em haha
The rest of the core team seems to be on holidays / taking a break from OSS for the most part, except for Felix and maybe Cooper
To Reproduce
For example, take this code:
def a():
CompiledSQL(
"addresses.id AS addresses_id, "
"addresses.email_address AS addresses_email_address "
# note the comma-separated FROM clause
"IN (__[POSTCOMPILE_primary_keys]) "
"AND addresses.id = anon_1.id ORDER BY addresses.id",
["hmm"]
)
And run it with these arguments:
$ black file.py --experimental-string-processing
The resulting...
Description
We don't need primer to fail on every single build at this point. Let's ignore it until we can properly look into and fix it. Tracked in GH-2734.
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
4f5268a Primer: exclude crashing sqlalchemy file for no... - ichard26
Description
Fixes https://github.com/psf/black/issues/2706.
diff-shades result comparing this PR to 21.12b0:
โญโโโโโโโโโโโโโโโโโโโโโโโ Summary โโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ 0 projects & 0 files changed / 0 changes [+0/-0] โ
โ โ
โ ... out of 2 057 623 lines, 10 045 files & 23 projects โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ...
Describe the style change
I am a first time user and ran black on code generated by Cookiecutter and noticed that a string literal that was split across lines was joined, but the extra quotes were left in and so this I feel will reduce readability. Here is the original code:
click.echo("Replace this message by putting your code into "
"testproject.cli.main")
Examples in the current Black style
click.echo("Replace this me...
I'm writing tests for diff-shades and man is it annoying starting from scratch, so much easier to write tests for black because the infra is already there
hmm, I'm getting /home/ichard26/programming/tools/diff-shades/tests/test_suite.py:105: DeprecationWarning: invalid escape sequence \ for something like
assert diff == textwrap.dedent("""\
--- 1.py
+++ 2.py
@@ -1,3 +1,3 @@
aaaa
-bbbb
-cccc
\ No newline at end of file
+BBBB
+cccc
""")
What's the 'correct' way of writing this inline multi-line string?
I thought this was a supported idiom but apparently not ๐ฆ
assert diff == textwrap.dedent("""
--- 1.py
+++ 2.py
@@ -1,3 +1,3 @@
aaaa
-bbbb
-cccc
\ No newline at end of file
+BBBB
+cccc
""".strip("\n"))
Maybe?
!eval
!eval
import textwrap
s = textwrap.dedent("""\
--- 1.py
aaaa
-bbbb
-cccc
+BBBB
""")
s2 = textwrap.dedent("""
--- 1.py
aaaa
-bbbb
-cccc
+BBBB
""".strip("\n"))
assert s == s2
@bright glacier :x: Your eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "<string>", line 16, in <module>
003 | AssertionError
!eval
import textwrap
s = textwrap.dedent("""\
--- 1.py
aaaa
-bbbb
-cccc
+BBBB
""")
s2 = textwrap.dedent("""
--- 1.py
aaaa
-bbbb
-cccc
+BBBB
""".lstrip("\n"))
assert s == s2
@bright glacier :warning: Your eval job has completed with return code 0.
[No output]
Yeah I guess so, just weird how even the example above is so common and yet raises a deprecation warning (which I can only reproduce on pytest ๐ )
Thanks
The reason for this one is because the trailing newline was also removed. The equivalent string would be ```python
textwrap.dedent("""
--- 1.py
aaaa
-bbbb
-cccc
+BBBB""")
*Or, in the style of backslashes*
```python
textwrap.dedent("""\
--- 1.py
aaaa
-bbbb
-cccc
+BBBB\
""")
That somehow didn't work when the whole thing was indented
@sour jay :white_check_mark: Your eval job has completed with return code 0.
'--- 1.py\n aaaa\n-bbbb\n-cccc\n+BBBB'
!eval
import textwrap
def a():
print(repr(textwrap.dedent("""\
--- 1.py
aaaa
-bbbb
-cccc
+BBBB\
""")))
a()
@bright glacier :white_check_mark: Your eval job has completed with return code 0.
'--- 1.py\n aaaa\n-bbbb\n-cccc\n+BBBB '
ah of course
Description
Fixes #2506
XDG_CACHE_HOME does not work on Windows. To allow for users to set a custom cache directory on all systems I added a new environment variable BLACK_CACHE_DIR to set the cache directory. The default remains the same so users will only notice a change if that environment variable is set.
The specific use case I have for this is I need to run black on in different processes at the same time. There is a race condition with the cache pickle file that ...
hi
Please use #bot-commands to run miscellaneous scripts.
Minor issues but nothing blocking the merge of this PR.
Thanks. This all makes sense to me and clean tested code, but, (and I didn't go looking) why can't we fix XDG_CACHE_HOME to work on Windows in platformdirs?
Description
Should unblock GH-2297 and mypyc.
Checklist - did you ...
- [x] Add a CHANGELOG entry if necessary?
- [x] Add / update tests if necessary?
- [x] Add new / update outdated documentation?
Review notes
Right now this PR uses 22.0 as the cutoff version but this is highly up to debate / subject to change. It might just be better to remove these references until we know for certain.
... and CI is broken, brilliant! /s
fmt: off I think?
you can also add a trailing comma, and it won't
IE ```py
foo = {
"a": 1,
"b": 2,
}
The comma on the last element
No problem!
It's referred to as the magic trailing comma in black for reference https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#the-magic-trailing-comma
No afaik
You can use # fmt: skip
But I'd argue this is harder to read than whatever black would format it as
Every line
Or use fmt: off and fmt: on
To disable it for a bulk amount of lines
Has anyone else here found code harder to read if it isn't formatted with black after using it for a long time?
mess around with the commans, it should be able to be left like the above mostly
could you paste this here so i can mess around with it?
Oh that's better
๐ค
All looks good to me and makes sense. Nothing stood out to not merge this. Thanks @ichard26 ! Thanks for pushing us and setting up for this PR for the last year or more.
oh that's why
its essentially because of tuples
in the source code:
this has a different meaning:
(5,)
than this:
(5)
so because of that, black does not apply magic trailing comma logic to single item tuples
a simple solution is just to use a list, since for what you're providing it to, I know that it can take lists
@pytest.mark.parametrize(
("input_data", "expected"),
[
(test_data, 26397),
],
)
yeah
for pytest at least, anyhow
@neon loom I thought we switched to platformdirs, why are we talking about appdirs?
So did I โฆ so I was right
Yeah ...
Correct us ๐ Iโm just dumb dumb
this server has a "ducky_australia" emoji by the way haha
where
psf/black#2739
Thank you so much for your contribution! This project is only possible by contributions like these :black_heart:. You're awesome, @gunungpw - congrats on your first contribution here! Feel free to share any feedback on your experience here in: #2238
8a84beb Documentation: include Wing IDE 8 integrations ... - gunungpw
Not sure if this is the right channel, or server, or at all appropriate ๐
!mute 911012248049291305 investigating
:incoming_envelope: :ok_hand: applied mute to @steady sail until <t:1641154995:f> (59 minutes and 59 seconds).
Whew ๐
I'm part of the staff team here, but you also have access to the #incidents channel to report stuff like this by the way ๐
though an @moderators ping here is helpful, too
if it's something you need attention with quickly
Oh true, I'll try to remember that
Looks good, but some nits and discussion. I'm still quite weak on the transform implementation, but I trust the tests, which are quite comprehensive ๐
๐ let's GO! Some minor or unrelated comments below. Everything looks sensible.
Poor Australia always upside down.
Describe the style change
I'd like to normalise raw strings with a capital R, like R"flowers" to lower case: r"flowers".
Additional context
Currently our reasoning for keeping "R" is that a syntax highlighter called MagicPython differentiates between the two. And because it is the default in GitHub and VS Code, we should be ca...
A small comment below, but the tests indicate that this is working as intended.
I have a .flake8 with constraints for formatting, is there any way I can use black against these constraints?
[flake8]
max-line-length = 95
max-complexity = 10
per-file-ignores =
cogs/utils/__init__.py:F401
cogs/weather.py:E501
black should respect the line length you set there out of the box
seems to be going for 98
as for file ignores, afaik you'll need to add a tool.black section to your pyproject with an extend-exclude line
Do you just want to set the line length?
sure, but I also need to follow all of the other rules in flake8 file so flake8 doesnt scream at me
we do provide ignores as Chris already said, but in terms of style knobs Black is very limited
401 seems unrelated to anything Black would do though
but you could disable formatting for a particular section
although that is discouraged ๐
What is max-complexity?
I'll probably just put this all in my pyproject.toml and ignore max-complexity if it really isn't that big of a deal
doesn't concern Black, it might have something to do with code complexity
right, that's that alley I was going down but still have no idea
in general Black should free you from linters complaining :D
well, I get the same output from flake8 . when I remove max-complexity so lets hope it's nothing important
Recent updates of black have introduced out-of-the-box support for Jupyter Notebooks, which is extremely helpful. As of #2630 only known python cell magics are processed (see e.g. here), which certainly makes sense. We have the use case that we have several custom python cell magics that we would also like to process.
This request is to allow configuration to support add...
โฌ๏ธ this post is about adding an extra configuration option for Jupyter support - how do the maintainers feel about adding an extra configuration option?
some magics are for non-Python code, e.g.
%%bash
mkdir my_dir
currently there's a hard-coded list of accepted ones https://github.com/psf/black/blob/8a84bebcfcabddfd5b82a8cff0b830a745999b6c/src/black/handle_ipynb_magics.py#L40
src/black/handle_ipynb_magics.py line 40
PYTHON_CELL_MAGICS = frozenset(```
What I was after was more like, can we get away with accepting arbitrary magics, or do the names have something to do with how they are processed?
ah, I see - the names don't affect how they're processed, no
If I'm reading this right, we need to determine which cells contain Python and format them.
src/black/__init__.py line 966
if src[:2] == "%%" and src.split()[0][2:] not in PYTHON_CELL_MAGICS:```
So we would indeed need a list of python cells that is extendable
yes, exactly - so, the user could extend the current PYTHON_CELL_MAGICS
Yep, it should definitely be configurable then ๐๐ฟ All of this brings back the discussion in psf/black#2712 of whether any of this should be in Black, so feel free to chime in Marco since you pretty much run the notebook thing here ๐
psf/black#2721 I mean
Yep, it should definitely be configurable then
๐
Cool, I'll wait to see if anyone has objections, and if not I'll ask the OP if they want to make a PR
yapf is better but black is nice
Did our issue comments get disabled to be shared here or is broken?
psf/black#2712
Seems to be a temporary outage / break of @toxic storm . If it happens again I guess we could ask #dev-contrib
I noticed that I'm not able to manage projects, and that Richard you started using the project and dropped the milestone. All fine, but we could add psf/black#2297 and psf/black#2726 in the nice to have
Wait, triagers can edit milestones?
Prolly just assign issues
oh yeah triagers do have access to milestones but not projects
moving everything to the project probably wasn't the best of idea then ..
Should be fine ๐ not like we're adding lots of items to stable requirements. But would be nice to fit in as many open PRs as possible, and close some too
๐ done. In general I do prefer milestones over projects but I didn't like the fact we just had a project for the stable release that wasn't in use
If I were starting from scratch I'd have stuck with a milestone.
They're quite adequate
and I'm bad enough at managing to-do lists I don't wanna have to manage projects lol
Also January 9th is closer than I previously thought!
I was thinking "oh I got time to prepare for the sprint" but not really now I think about it. Thankfully other than diff-shades and mypyc there's nothing that I'm truly responsible for.
Anything I should know about a sprint beyond "we just do more work then"?
the pydis staff lounge is currently called #the-pydis-mass-layoffs-lounge and that's pretty apt to be honest ๐
I have never done a sprint myself so I'm in the same ๐ฃ as you 
Well, let's just focus on getting something done then :D
Anything I could help with?
DS & mypyc wise
testing the wheels would be wonderful although they're a bit out of date now
I have a grand total of 2 user field reports 
Thanks, I'll have a go with them tomorrow
Name Stmts Miss Cover
-------------------------------------------------
src/diff_shades/__init__.py 3 0 100%
src/diff_shades/__main__.py 2 0 100%
src/diff_shades/analysis.py 144 62 57%
src/diff_shades/cli.py 258 155 40%
src/diff_shades/config.py 25 1 96%
src/diff_shades/output.py 111 43 61%
src/diff_shades/results.py 200 9 96%
tests/test_suite.py 225 11 95%
-------------------------------------------------
TOTAL 968 281 71%
other than my logging code being almost untestable this isn't actually too bad writing functional tests
testing is always nice for figuring out how crappy your APIs are ๐
I'll try test them too.
This is a great quote and I've used it ๐
Well something similar before.
Hard to test API, hard to use API, usually relate ๐ - Mocking is another story. But hard to mock can usually state some refactors might be nice.
More like a crawl then lol
Some procrastinators are creative there is some research to that
Dont forget the meetings in between the sprints not too sure if it is the stand up type lol
Describe the style change
Support for hanging indents
Examples in the current Black style
if (
is_interesting(attempt)
and len(attempt.record) <= len(source.record)
):
source = attempt
Desired style
if (is_interesting(attempt)
and len(attempt.record) <= len(source.record)):
source = attempt
This might not be the best example and in many cases I prefer blacks exploded syntax and in many I pref...
Description
Fixes #2742.
This PR adds the ability to configure additional python cell magics. This
will allow formatting cells in Jupyter Notebooks that are using custom (python)
magics.
Checklist - did you ...
- [x] Add a CHANGELOG entry if necessary?
- [x] Add / update tests if necessary?
- [x] Add new / update outdated documentation?
Thanks for submitting! The changes look good in general, but one discussion below.
Also, we'll need other maintainers to have look as well since they haven't voiced their opinions yet.
Nice work! Just got a comment about tests
Describe the bug
I am writing my own Concrete Syntax Tree parser/emitter in Python, but I am using black as my code formatter so I want black to ignore the 'fancy' Python syntax I am trying to support with my parser. So I've got a bunch of badly formatted Python code that I want to support with my parser.
To Reproduce
def add1(foo):
def adder(a: int, b: int) -> int:
# fmt: off
res: \
int \
= a + b
return res...
Describe the bug
When trying to run black on a file with a patter matching block where a case is a class pattern with an as pattern inside of it fails to format
To Reproduce
For example, take this code:
A stripped down example of file that was failing
from collections.abc import Callable
class Foo:
bb = 5
def aa(self):
...
bar1 = Foo()
match bar1:
case Foo(aa=Callable() as aa, bb=int()):
print(bar1.aa, b...
I finally managed to fix my first mypyc bug ๐ hopefully this means someday we'll be able to drop the "create nested function via type at runtime" hack :)
nuitka can speed up your code better than mypyc, and nuitka-compiled code is closer to pure python, than mypyc-compiled code
have you thought of using it?
IMO, nuitka is faster and easier than mypyc
have you thought of using it?
No because the codebase was already prepared (barring some issues that built up over ~2 years of delay) to integrate mypyc when I first took up the porject
I really don't want to restart from scratch this late in the game
you don't need to change the codebase to compile it with nuitka
maybe i will try it later
<!--
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];
...
${{ github.action_path }} doesn't point to the correct path when run in a docker container, you have to use the environmental variable GITHUB_ACTION_PATH
https://github.com/actions/runner/issues/716
Description
Checklist - did you ...
- [ ] Add a CHANGELOG entry if necessary?
- [ ] Add / update tests if necessary?
- [ ] Add new / update outdated documentation?
Suggestion:
Use artificial intelligence to find similar blocks of code and make them functions instead
For Black? ๐
pylint can do it
Black has a strict promise of not changing the meaning of the code, so while interesting, I think we'll leave that up to other libraries :D
I'm guessing this is for this: https://docs.github.com/en/actions/creating-actions/creating-a-docker-container-action
This breaks none of our CI so I see no reason to merge - will wait for @ichard26 to agree.
Can you just please add a Change Log entry please.
"no reason to not merge" perhaps
probably that as cooper is a master of typos
don't worry about it!
lol
"This looks great. 10/10 code. I see no reason to merge."
Approves
I'm continuously impressed at how unpolished the GitHub Actions product can be / feel like, but thank you!
i added this feature to my bot, to help make code easier to read for all of my users
Describe the bug
Black does not exclude the filefoo.py root when asked to exclude it with ^/foo.py
To Reproduce
Start with an empty directory
$ echo "s='test'" > foo.py
$ black --extend-exclude ^/foo.py
would reformat foo.py
Oh no! ๐ฅ ๐ ๐ฅ
1 file would be reformatted.
Same behavior using --exclude flag
Environment
- Black's version: 21.12b0
- OS and Python version: OSX 11.6, Python 3.9.6
I don't see any problems with this, just one minor suggestion. Thank you for filing the issue, researching the options AND submitting a PR - truly a rockstar!
As discussed in #2394, we'd like to shove disruptive style changes between major updates behind a --preview flag. And I think it should be created and available even if such changes have not been implemented yet, so that our CLI is consistent.
Perhaps:
- add the CLI option
- create a separate style docs section for describing the style
- from now on announce these kinds of changes under a "preview" header in our changelog
- document a consistent way of writing preview tests without d...
I am trying to find out what it passes to format_str on default by doing:
black -l120
I am trying to use black's format sytem except for a bot commands meant for reformatting code
I used to use yapf and autopep8 to format it, but i think using black this command and then
black
as a way to format strings would be useful
I was asked to ask in here, as black lacks an api
So you basically have a four choices: 1) create a temporary file and then call black in a subprocess on that, then read the file etc. etc., 2) pass the code via STDIN via the subprocess and read STDOUT, 3) import black and call black.main with the arguments you'd use on the command line (note you'd have to capture STDOUT / log STDERR manually), or 4) use black's informal unofficial APIs.
I would rather use the informal apis
alright - it should look something like this to use the "unstable" APIs properly
import black
src = "some code"
mode = black.Mode()
dst = black.format_str(src, mode=mode)
black.check_stability_and_equivalence(src, dst, mode=mode)
I quote unstable as it's highly unlikely we would ever be able to change these APIs without breaking the world as APIs will be created, regardless if it's by the authors or the users :p
!d black.Mode
class black.Mode(target_versions: Set[black.mode.TargetVersion] = <factory>, line_length: int = 88, string_normalization: bool = True, is_pyi: bool = False, ...)```
Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.10)")
!d black.format_str
black.format_str(src_contents: str, *, mode: black.mode.Mode) โ str```
Reformat a string and return new contents.
mode determines formatting options, such as how many characters per line are allowed. Example:
```py
>>> import black
>>> print(black.format_str("def f(arg:str='')->None:...", mode=black.Mode()))
def f(arg: str = "") -> None:
...
``` A more complex example...
I am trying to use black's format sytem except for a bot commands meant for reformatting code
#black-formatter message
why did no one ask me what i did smh
what's check_stability and equalivent for?
btw hi richard
so by default black runs two safety checks, the AST safety check i.e. the more important one where black checks that the AST of the source and output code match. There's also a check to make sure black's formatting is determinant and doesn't change depending how many format passes black does. For historical reasons I don't know (this project started in 2018, I only joined in 2020) format_str does not do these checks.
import black
src = "some code"
mode = black.Mode()
dst = black.format_str(src, mode=mode)
black.check_stability_and_equivalence(src, dst, mode=mode)
So this is the normal?
mode = black.Mode(line_length=120)
this for custom?
you don't have to call that function but there is a slight chance black will break the source code and you won't be clearly alerted
if performance is much more important you can drop it but I wouldn't recommend it
๐ค Well I can always run it in run_on_executor cause I am doing this for a discord Bot
mode = black.Mode(line_length=120)
Yeah that's how you'd configure the line_length
black -l120
same as this right?
Yup
If you want black to be at least AST safe, you can simply call black.assert_equivalent which is pretty cheap
๐ค does check_stability_and_equivalence check both or only one?
check_stability_and_equivalence does two checks, the AST check and the stability check
black.assert_equivalent just does the (more important) former
What does check_stability_and_equivalance do when the check fails?
it raises AssertionError
it also writes a log file on failure which isn't easy to disable unfortunately
I really don't want to log a failure lol
alright let's dive deeper in black's APIs \o/
lemme find the bit in the test suite where we patch out this behaviour
with unittest.mock.patch("black.dump_to_file", lambda *args, **kwargs: None):
# code ...
I don't think the playground has a public API either lol
and I'm pretty sure it doesn't delete / suppress the log files either
its hardcoded as two aws lambda urls
last updated quite a few months ago, sooooooo
i may or may not have gone for it
but yeah, feel free to overwrite black.dump_to_file with a stub callable and black won't write a log file when either check fails cc @glacial swan
does using try/except stop it?
Nope - for example assert_equivalent writes the log file before raising AssertionError https://github.com/psf/black/blob/dc8cdda8fdd6941103240ae3279034d2acdc69bc/src/black/__init__.py#L1299-L1307
src/black/__init__.py lines 1299 to 1307
try:
dst_ast = parse_ast(dst)
except Exception as exc:
log = dump_to_file("".join(traceback.format_tb(exc.__traceback__)), dst)
raise AssertionError(
f"INTERNAL ERROR: Black produced invalid code on pass {pass_num}: {exc}. "
"Please report a bug on https://github.com/psf/black/issues. "
f"This invalid output might be helpful: {log}"
) from None```
so I need to subclass the function for it to not override and to dump it to a file?
You can't subclass a function but you can overwrite the dump_to_file function with your own that does absolutely nothing
import black
src = "some code"
mode = black.Mode()
dst = black.format_str(src, mode=mode)
black.dump_to_file = lambda *args, **kwargs: None
black.check_stability_and_equivalence(src, dst, mode=mode)
this theoretically would work
Hmm
why are you using lamabda here?
because dump_to_file is an internal function, not a variable
ok
what's something that black will hate?
nvm found it out
like a crash reproducer?
def a():
# fmt: off
pass
def b():
pass
is a very old bug that's yet to be fixed
this would cause assert_equivalent to fail
well it appears it checks with import os,
thank your help has made it possible to do it in my bot
no problemo! ๐บ
From #2751: this PR creates a --preview flag for our disruptive style changes. It includes documentation (changes described under "future style"), tests (now empty skeleton) and the flag itself as a CLI option and added to Mode.
The name of the flag was originally --future in the stability policy, but I changed it to --preview based on the original discussion. While I like it more, it isn't really important. Which would y'all prefer?
Checklist
- [x] Add a CHANGELOG entry if...
Description
The CLI reference is a bit buried in the documentation. Hopefully, with this change it is at least a bit more visible. I put the important information first to not distract the reader and changed the summary line to match what a user would actually be looking for when browsing.
Checklist
- [x] Add a CHANGELOG entry if necessary? N/A
- [x] Add / update tests if necessary? N/A
- [x] Add new / update outdated documentation?
huh you're back early Jelle ๐
hello from Jordan ๐
668bace Improve CLI reference wording (#2753) - felix-hilden
Thanks, this is a great speed improvement. I think it's worth mentioning in the changelog.
05e1fbf Stubs: preserve blank line between attributes a... - ichard26
Thank you! A few tiny suggestions.
ea4c772 Action: Support running in a docker container (... - joshowen
e64949e Fix call patterns that contain as-expression on... - isidentical
wow that is a lot of stuff to come back to
Wow, lots of activity in black ๐
why is everything I'm working on blocked on removing Python 2 .. ahhhh only diff-shades and the integration is not blocked on it but it's still kinda blocked by the --preview flag
well OK I worked around the mypyc incompatibility temporarily so I could run diff-shades against my other PR actually mypyc is still broken
OK it's actually working now
this edit
reminds me of code I wrote
implements new feature
pushes and deploys
tries new feature
doesn't work
turns out it was broken
rewrites feature
it still doesn't work
changes enabled flag to true on prod
it works
- headers["User-Agent"] = (
- f"psf/black diff-shades workflow via urllib3/{urllib3.__version__}"
- )
+ headers[
+ "User-Agent"
+ ] = f"psf/black diff-shades workflow via urllib3/{urllib3.__version__}"
wtf black
it gets worse, mypyc is still broken after two hotfixes :/
is black formatted with black?
Yup!
nice
<!--
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];
...
<!--
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];
...
Going to land this once CI passes.
time to forget Python 2 ever existed
Get the glasses and shampagne!
we could remove 33, 34, 35, 36 also right? since 3.6 has reached eof (same for the others)?
There has been talk on the Python support policy issue, but not likely yet
We don't necessarily have to, and there's much less cost to keeping them around than for Python 2
there's much less cost to keeping them around than for Python 2
wdym by this
less special syntax differences
Python 3 minors are much more uniform, disregarding async/await and some others
yeah that's what i gussed
Also Jason have you had a look at the --verbose comments? (finally I can poke you instead of the other way around ๐ )
oh nice, relaxed?
smh don't poke jason that's my job to do when he's not poking me
don't poke fun at poking
don't poke my poker
CANTREADMY CANTREADMY I think I'm losing control of my chatting again, better continue work
will finish off my diff shades - rich diff PR and get back to verbose
also, one more question, i asked this to richrd in dms, thought of putting it here also, he hasn't answered yet
have there been any discussions regarding making the rich output/verbose logs more pretty, preferably by introducing rich to the project
s n e k
Not aware of any discussion. For what it's worth, I'm pretty hesitant to add new dependencies to Black.
hmm, we do have color, but what else does Rich do?
we have colour, but it is not as easy as rich to work with the colour we have lol
that's the only thing i was looking to have
that doesn't feel worth the cost of a new dependency
s n e k
!pypi rich
It's pretty easy with Click, no?
snek
nope, on mobile, let me see if i can come up with an example
uncreative its getting nnoying, could you stop, thanks
smh how many language codes is Russian now
their username does say they're uncreative ยฏ_(ใ)_/ยฏ
yeah, click only supports one style per string
Oh I see
like you can have something like this:
The [blue]**uncompromising**[/] [gold]Python[/] code formatter
That is pretty neat, but we could achieve this with a style submodule as well: f"The {s.blue('uncompromising')} {s.gold('Python')} code formatter"
wouldn't be too much imo
And I don't think it's often that we would want multiple colors on a single line. Or did you have something in mind already?
oh nice, i didn't know of that
that's perfect
Well I haven't ever used that, but surely I can echo a combination of strings ๐
And those would just be short cuts
Given rich has 3 subdependencies I do not believe it's worth it to require just for pretty output
yeah, like they said, i will see if what felix said works once i get the other stuff done
!remind 1w
Your reminder will arrive on <t:1642423945:F>!
Before you update the whole PR though ๐ it'd be better to discuss this with others as well. If our prints are significantly nicer looking and significantly nicer to write using the short cuts, we could do this to all prints.
i.e. could be worth it to submit another PR
different pr
yeah
not gonna postpone this more lol
But that could be cool, since we could define a few styles and just use them. Like def error(s): click.style(s, color="red", bold=True) or whatever
buuuut others might disagree
that's what i was planning to do, support raw and have few pre-defined styles also
after discussing with you guys ^^
ok, saw your review, regarding the tests, umm let me find the dicussion link
teh summary is that, the feature is basically using normalize_path_maybe_ignore which is already well tested, so there isn't a need to add more tests to it
right, good!
here #black-formatter message, will nothing much here changes in diff-shades dicussion pretty soon
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.
ok others are pretty straightforward, i will fix them, once i get back at my laptop
Your reminder must have a content and/or reply to a message.
!remind 2h
Your reminder will arrive on <t:1641826890:F>!
wait, doesn't your comment chain say that there are no tests for the function?
hmm, wait a second, afair i said there are some tests for it later, and then say those are enough
one sec
tests/test_black.py line 1400
normalized_path = black.normalize_path_maybe_ignore(path, root, report)```
oh kay ๐๐ฟ
did i just type out "ok"
the last comment is mine, so when everything is taken care of, I think an accept is next!
u did? y wood u due such a thing?
it was supposed to be "oh, okay" ๐
oo perfect, one more pr getting close
again, if others don't have further comments :D but as I said, it is starting to make sense now ๐๐ฟ
time for some more poking
That reminder has been deleted successfully!
oh now that I scroll down again I saw your planned style Enum, that actually looks good!
smh just write your own changelogger
haven't used it, nor maintained projects as big as this, but it seems pretty convenient
wait.
i was hinting towards the one i am writing at modmial lol
first get them convinced
could you link it, i forgot how it looks exactly
ah yes
If nothing else comes up and the stars align... ๐
workflow run approval :D
sry I'm only in my second evolution stage called "collaboratron" :D
we'll have to ask one of the "maintenauts"
well well, do the honours maintenauts
(how can this be made a thing, imagine evolving in FOSS)
i could write some sort of small utility parser to make rich like syntax be converted to this
Not sure if worth it ๐ let's start from applying the styles in the first place
Parsers sound like edge cases and weird bugs to me
Nevermind the fact that we're developing one ๐
I clicked the approve button, wish I could let more people click that button
I don't suppose GitHub lets owners assign individual rights to collaborators?
Damn.
probably
going afk, cya :D
I think it's a GitHub-level thing that only people with write access get to approve CI runs
right
and you have to do it again every single time they push to their first PR
you can change that now, you know
thaaat's annoying :D but after hearing about the secret leaks might be justified
like Jason is going to set up a bitcoin miner now in that PR after so many rounds of review
oh you can? I didn't check recently. Can you tell me more?
can yes, awake enough to? no
well, at least runs on forks work right?
meaning your own tests in e.g. felix/black
thanks! looks like I don't have access to repo settings for Black, I'll have to poke Lukasz to do this
thanks for your contribution @tired shard !
you're most welcome!
po-po-po-poking face
i was looking to get richard's review on that though
is that the nested config files? yeah I need to get around to that too
ye
yeah
but feel like I should focus on getting the stable release ready
hmmm, i let you go for now
Speaking of that, I think we should include ESP in the --preview flag for this release
makes sense ๐๐ฟ anything else on your personal wanted list?
esp is?
electronic signal processing --experimental-string-processing
I want to have a list of what we need to do before the release ๐ I think there's a list somewhere on GitHub?
Yep the GH stable project has been cleaned up by Richard!
Was just thinking that maybe you have something else in mind, to add there
ok thanks, I think only --preview there is essential
the ** spacing thing can wait
Fair
A preview flag is added in #2751, which could also contain experimental string processing. So shall we convert ESP there? Or are we still thinking about making it stable very soon?
Made an issue, perhaps this should be in the project as well
@dense jungle meaning that I can't assign it to the project ๐ so if you'd be so kind
done
thanks!
Jelle / Richard: are there any plans about the parser speed-up PR (whether it will go in this release or not)?
oh ideally it should. I wanted some more time to think about it or look into the code, but haven't had a chance to dive into it yet. I was wondering if we could implement this approach without monkeypatching.
I also thought about that before the PR, and it seem to be possible.
So instead of these 2 different functions overriding each other:
def shift(self, type: int, value: Text, newstate: int, context: Context) -> None:
"""Shift a token. (Internal)"""
dfa, state, node = self.stack[-1]
rawnode: RawNode = (type, value, context, None)
newnode = convert(self.grammar, rawnode)
assert node[-1] is not None
node[-1].append(newnode)
self.stack[-1] = (dfa, newstate, node)
def shift_safe(
self, type: int, value: Text, newstate: int, context: Context
) -> None:
"""Immutable (node-level) version of shift()"""
dfa, state, _ = self.stack[-1]
self.stack[-1] = (dfa, newstate, FAKE_NODE)
we would have a unified shift function:
def shift(self, type: int, value: Text, newstate: int, context: Context) -> None:
"""Shift a token. (Internal)"""
if self.back_tracking:
dfa, state, _ = self.stack[-1]
self.stack[-1] = (dfa, newstate, FAKE_NODE)
else:
dfa, state, node = self.stack[-1]
rawnode: RawNode = (type, value, context, None)
newnode = convert(self.grammar, rawnode)
assert node[-1] is not None
node[-1].append(newnode)
self.stack[-1] = (dfa, newstate, node)
If that makes more sense, I can convert my PR to that form. WDYT?
Could you link the PR? I'd love to take a read just for fun.
Sure thing!
Thank you!
Yes I would like that better. Thanks!
By way there's like two more mypyc breakages on main so it's hard to test the PR for compatibility when main is already broken :)
I know the fix for one of them but I haven't been able to fix the other, will probably have to do a git bisect .. which sounds tedious haha
what's the issue? I can help take a look
This should now be implemented.
Thanks, I have a couple of nits and I'd like to also see a changelog entry.
This was fast ๐
Now that the speed-up PR landed, it should be safe for us to enable pattern matching by default as the last grammar case to try. This would still make us initially test the 3.7+ and 3.0-3.6 grammars first before we try to run with the backtracking.
I've written something to try parsing a local copy of 4k python packages from PyPI with the regular lib2to3_parse and the 3.10 one. Will report back if there are inconsistencies
The regular parser ignores token.NL/token.COMMENT since the grammar assumes there can be any number of them during parsing. This is actually handled in the driver rather than parser, so when the parser got implemented initially we did not specifically instruct this. But seems like it is now needed.
This seem to only cover cases where a standalone match or `...
^ this is the only mismatch I've found
rapid fire :O
thanks for running this check!
@dense jungle I think I misunderstood your review. Would the change in the input (adding a trailing comma) produce the current output (without any trailing comma)
No, the output should be different too
weird, it is not ๐ค
Because if there's a trailing comma we should always explode
oh hm, that seems like a bug
we can track and fix it separately though, it doesn't have to hold up this PR
nop, seems like there are 2 identical match statements and I edited the wrong one ๐คฆโโ๏ธ
it is working now, sorry for the confusion
hmm I can't reproduce the second issue on current main, the other fix is still required but this surprises me. I suppose dropping Python 2 fixed other issues? I'm running a diff-shades run to check nothing's really broken .. somehow
Though we should probably try updating to mypy 0.931 to pull in the latest performance and compatibility fixes.
Let me try that
I got this when trying to run a mypyc-compiled black locally, have you seen it? ``` File "/Users/jelle/py/black/src/black/mode.py", line 126, in <module>
target_versions: Set[TargetVersion] = field(default_factory=set)
KeyError: 'set'
0.931
hmm did they introduce another breakage? I'mma check
I'd guess it's trying to read the set name in the class __dict__ as it seems eerily similar to that negative integer constant miscompilation issue. I'd have to check the generated C to know for sure though.
yeah I'm staring at that now, it looks right though
cpy_r_r684 = CPyStatics[744]; /* 'set' */
cpy_r_r685 = CPyObject_GetAttr(cpy_r_r683, cpy_r_r684);
huh.
oh wait there's another one
cpy_r_r676 = (PyObject *)&PyType_Type;
cpy_r_r677 = CPyStatic_mode___globals;
cpy_r_r678 = CPyStatics[744]; /* 'set' */
cpy_r_r679 = CPyDict_GetItem(cpy_r_r677, cpy_r_r678);
reproes with this ```from dataclasses import dataclass, field
from typing import Set
@dataclass
class X:
s: Set[str] = field(default_factory=set)
works on 0.920
(and on 0.930 mypyc is completely broken)
L20:
r59 = load_address PyType_Type
r60 = test.globals :: static
r61 = 'set'
r62 = CPyDict_GetItem(r60, r61)
if is_error(r62) goto L36 (error at <module>:7) else goto L21
L21:
r63 = 's'
r64 = CPyDict_SetItem(r58, r63, r62)
dec_ref r62
r65 = r64 >= 0 :: signed
if not r65 goto L36 (error at <module>:7) else goto L22 :: bool
L22:
r66 = builtins :: module
r67 = 'set'
r68 = CPyObject_GetAttr(r66, r67)
if is_error(r68) goto L36 (error at <module>:7) else goto L23
yeah the IR isn't right for that first lookup
I'll report a bug to mypyc
this one was known, someone forgot to mark mypyc/__main__.py as uncompilable which is important because ... something with __file__?
yeah it was fixed, I just wanted to check if it got broken between 0.930 and 0.931
Given this code: from dataclasses import dataclass, field from typing import Set @dataclass class X: s: Set[str] = field(default_factory=set) Compiling with mypyc setfield.py on 0.931 and then runn...
Unauthenticated git protocol was disabled recently by Github and should not be used anymore.
https://github.blog/2021-09-01-improving-git-protocol-security-github/#no-more-unauthenticated-git
The previous PRs successfully optimized the backtracking in the factor of 4X. It might make some sense to profile and see whether there are still other potential bottlenecks.
Sure. Thanks for helping people not get confused here!
4efb795 Change git url for pip installation in README (... - cbows
copy.deepcopy is still the most expensive part (75/100 of the extra overhead introduced by the backtracking parser). I initially assumed it was mutable (since it was represented as a tuple of lists), but seems like we only use it as a basic table and don't mutate it anywhere in the code.
-t py39 (main):: Mean +- std dev: 7.21 ms +- 0.25 ms
-t py310 (this branch):: Mean +- std dev: 13.8 ms +- 0.6 ms
-t py310 (this branch):: Mean +- std dev: 7.98 ms +- 0.24 ms
This reduces t...
The command for installing via pip no longer works due to changes in security protocols.
Changing the URL to an HTTPS address fixed this issue for me, i.e. pip install git+git://github.com/psf/black->pip install git+https://github.com/psf/black
I can't help but laugh lmao
Description
Change the installation link in /docs/getting_started.md to comply with new GH requirements that one use secure links. This resolves #2764.
Checklist - did you ...
- [x] Add a CHANGELOG entry if necessary?
- [x] Add / update tests if necessary?
- [x] Add new / update outdated documentation?
8954e58 Change installation url to comply with git secu... - jlazar17
Wanted to get some of your opinions on https://github.com/ichard26/diff-shades/pull/4#issuecomment-1010537573, also if someone has bettter colours pls tell, i just copied the current ones from delta-rs
what happens if you merge main
nothing, i will merge it once it is close to merge state
i think you'll find a good portion of conflicts if you try to merge
yep ๐ i do
submitted my contributing experience :)
lol yeah, some more coming up sometime soon, this time they are formatting based, the "ncie to have" issues
I have a dream of reaching 20 open PRs and 300 issues again
I've done that!
but gonna take sometime, getting familar with that section of code rn
lol, arl is very good at that
also what are your thoughts on teh two points i brought up
refactoring? yeah big up
nice nice
Wu-cash ลukasz refactored the infamous one-file Black a while ago, but it could definitely use some more work
and changelog manager, i had edited the comment
yeah I feel for Jelle whenever he merges main
how much overhead is there? say using towncrier (have you used it?)
but it is pretty similar to what i did above, so it is pretty okay
As @Shivansh-007 noted in https://github.com/psf/black/issues/2238#issuecomment-1010922392, our current CHANGES.md mechanism for the changelog is very prone to merge conflicts. Another problem is that when a release happens between the time a PR is opened and when it is merged, it's possible to have the changelog entry go into the wrong section.
I haven't looked in detail in this space, but I know that possibilities include:
- towncrier
- blurb, which is used by CPython
- writing our ow...
aye :D
one more pr coming from then
lol
basically the own at modmail, is a mixture of blurb and towncrier
i coul possibly make that a separate lib 
Have at it!
why can't modmail just use towncrier or blurb?
I'd prefer Black doesn't have to maintain its own tool
It could be very useful, if not to us, then perhaps somebody else
I had a quick read, and seems like Towncrier somehow generates the news fragments, while blurb is just for combining existing news entries. But that was a quick glance so I might have misunderstood
hmm not exactly, i don't remember towncrier, but for blurb, it basically makes new fragments for each change into separate folders of that category and supports combining all the misc/news (where the fragments are stored) into one news file
nothing more
let me have a look at towncrier
yep exactly :D
towncrier does pretty much the same thing
although the large hurdle was that towncrier couldn't be configured to use md
ah yeah
also no gh validation
and doesn't integrate to eh same version log
makes a new one for each release
(both blurb and towncrier)
and the most important towncrier is dead
so is blurb
blurb is very much alive for use in CPython ๐
i am talking about maintenance, i saw it has some issues open last time i checked it but there hasn't been any progress on them
I'd much rather use towncrier than a custom built solution, I'll look into it later today
i left a comment on the issue about towncrier
I'm all for changing to rst though ๐
especially if it's the only thing keeping us from using towncrier
Honestly my hope is that we can use towncrier and then do some fancy sphinx extension stuff or something for auto linking
that's for you Felix btw, you asked for that didn't you haha
and automatic generation plugin
don't tell jason that I miiiight kill the custom built system for our project when i migrate to sphinx docs
not automation, just the linking part though :D
arl, as much as I like scripting I don't like maintaining a bunch of helper scripts
no, you can set up automatically creating towncrier changelog on build of the docs
well have fun
Yeah I know
!pypi sphinxcontrib-towncrier
I've seen Pip's workflow and I am stealing bits and parts of it
hence why I also want to introduce nox
damn, if we provide something to make the changelog fragment and link it, we could possibly use next-pr-number (or what was it) to supply the number so that a user doesn't have to worry about anything but the message itself
but not sure how hard it is to commit in actions
but this might be just superfluous, let's have the fragments first :D
I think there are restrictions on that because they're worried about infinite recursion. However, pre-commit.ci can do it, so maybe we could write a pre-commit hook that adds the PR number
right, makes sense
i mentioned some cons above btw
sphinx docs has changelog support?
oh well
well
||i h8 u||
Hey @fleet depot!
Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:
โข If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)
โข If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:
uuugh, and I have to retype my whole message smh
How annoying
Black seems to be misbehaving. When given one folder gluon/, it declares that some files need to be formatted. When provided two folders gluon/ and utilities/ it says all files would be unchanged. how??
Are there pyproject.toml files in either of them?
update black to main branch ๐ and enable verbose
yeah that too :)
missed this earlier, that would be something fun to implement, gonna give it a shot :D
!remind 16h ||how was your first paper ๐||
Your reminder will arrive on <t:1642059096:F>!
eh, I'm not sure if I like the idea
what's this channel for?
me too :D
basically, checks if changelog exists for current change, if not prompts if you want to create changelog, sees if a pr for this already exists if not get next pr (maybe again prompt?), follows normall news add process
that's what i thought
maybe helpful
whats the black-formatter?
pins, mate
it feels like overengineering too early
we don't even have news fragments, let's do that first and trial that
next-pr-number is in JS btw Felix
not decided yet, will look at towncrier before making a decision
it's a website too, right? ;)
well i am making mine a package also, so if you want you could look at that too, current just that PR
yeah but it's all client side, there's no API or whatever
oh damn
I haven't found any hosting options that I could afford (i.e. I have no spare funds)
vercel :D
so GitHub pages and client side code FTW
yeah prolly for the better
so Jason you said that your tool was an amalgamation of the other two options, could you tl;dr why did you make it?
- no gh validation
- no way to append the version changelog to the main one, towncrier makes a new one for every release
- towncrier is somewhat dead
- no markdown support
- no way to create two changelogs for the same PR
this is what i remember from top of my head
also, i think towncrier is based on issue numbers rather than PR numbers, not sure
reasonable
We force changelog entries to have PR numbers so it should be fine, though sometimes we do have multiple PRs for a single entey
uhh is that pointing to the last one? i meant the other way round
also, i don't think towncrier has a easy integration with pre-commit and actions, not really relevant but okay
I don't see why a pre-commit integration would be important as not all commits need a changelog entry
yeah, that's why i said "not really relevant"
oh I thought you were saying my opinion was not really relevant because towncrier has these other flaws / cons
I think the confusion started here
I still have no idea what you meant here
I think that changes can have multiple prs
its the other way round, you can't have 2 changelogs for the same pr
what is a black-formatter supposed to be about?
channel description
opposite of whiting your code
xD formatting your disk
so many people asking what is black
oh it wasn't a typo
okay i opened the wesbite and I still don't get it
I mean, atomic commits hopefully means this is rare? @plain atlas loves 'em btw
"The uncompromising Python code formatter" tldrs it
im blind ๐คฆโโ๏ธ
you have code, we make it beautiful
to be fair it looks like the same code in vscode
it is rare, but possible, i have seen cases on cpython
wdym by beautiful exactly?
good to look at?
Yes.
have a look at the style description, there's lots of examples!
and reasoning
alright alright
atomic commits are awesome
so @tired shard you mean that with your version we could have 2 news entries for a single PR? I'm still a bit confused :D
I'd assume that'd be useful in cases where an unrelated change fixes two bugs or something
yeh
i think towncrier can have multiple changes for a pr?
Great, you two are now arguing what cons town crier has

and tl;dr it's an autoformatter!