#black-formatter
1 messages Β· Page 17 of 1
and we were forced to a bit when making changes that depends on python 2
not enough clearly
(nvm, I'm gonna go respond there so that you can point fingers at me and randos can argue with me there)
fun
I imagine you're going to say "drop Python 2 yesterday"? π
it's part of the maintainer experience π
Got to say. Once again, I'm quite excited about the fuss here!
I no longer use python 2, and so am unbiased.
Literally merged my pyupgrade PR yesterday
I feel like by the end of this year would be reasonable (or on stable release or the next one after that)
It's been ~two years since 2020
It's still march 2020 where I am
I have used Python 2 like two times only, I've avoided it as much as possible.
It's got some handy features like bytes in csv
Sounds great!
I guess Black is going through the late-stage growing pains process that like any major projects goes through eventually
I'mma just roll it up into maintaince
typos are great
C: maintenance I mean.
I thought django was adopting black when it goes stable?
No you're confused it's the other way around
Oh ok!
This happened for Python 3 btw
Hey, just posted a formatting question in #help-burrito regarding function declarations by #black-formatter and how I disagree with it if y'all are interested in discussing it. Understandable if not π
Sadly I don't have any concrete suggestions on how to make it better than it is now
Sharp words @drowsy sonnet!
No, it's "don't do it for free; because the main beneficiaries are $corps and those will happy extract value for free".
:)
Honestly, I really really want myself to be the last person who maintains support on EoL Python versions for an OSS thing in the ecosystem.
Do you maintain six?
it's Benjamin Peterson I think?
Yup.
There's a reason RedHat exists. :)
Yes, I know this will never be true. But the closer it is to that, the healthier it'll be for everyone involved.
oh my gosh I love this: https://pbs.twimg.com/media/CBoGfxZUAAA7sEW?format=jpg&name=small
I found that via the post about dropping python 2.6 support
:)
modernize still supports Python 2.7 as input
For now. ;)
Is that... A threat?
maybe a promise :)
https://github.com/psf/black/issues/2156 -- so... how can I help with this?
Progress is being made with blackbench!
Describe the bug
Running black before and after modifying a file doesn't produce the same formatting wrt trailing commas in argument lists.
To Reproduce
<!-- Steps to reproduce the behavior:
- Take this file https://hg.mozilla.org/mozilla-central/file/287995cabe8ebd9a29f2f56dde65a84678a38229/testing/mach_commands.py
- Run Black on it, it makes no change (double checked after an upgrade to 21.7b0).
- Apply the following patch:
@@ -683,7 +683,10 @@ class SpiderM...
For blackbench I have the following to-dos before I'll be releasing 21.7.dev2:
- Add metadata to the pyperf JSON results
- Print out the version of black being tested
- Significantly overhaul the documentation's content
Hopefully they don't take me too long (2 is literally a extra print statement, how hard could it be?).
There is a pull request for it, but Lukasz's comment here is pretty concerning: https://github.com/psf/black/pull/2237#issuecomment-850861722
Once 21.7.dev2 is released, I would be open to people actually exploring and using it (the docs aren't great right now so that's my main reason to holdback).
I do wish the skip-magic flags were enabled by default
the magic comma and proposed magic parentheses violate the "don't make me think" principal of black
Out of interest how much do you charge for a py27 pip release?
Pretty off-topic, but does anyone happen to know a Chrome (yes, I know Chrome ain't best, maybe one day I'll move to Firefox) extension that adds a nice easy to navigate file tree to PRs? I used to use https://chrome.google.com/webstore/detail/better-pull-request-for-g/nfhdjopbhlggibjlimhdbogflgmbiahc but it seems to have broken recently sadly π¦
Actually, nevermind, it seems to be working now (even though it hasn't had an update since Dec 2020 ...)
Ugh, gotta love writing smoke tests that aren't actually testing anything when you refactored the test suite 18 days ago.
I have no idea why my smoke test is broken :/
OH I see
So the test was completely ignoring the code I was trying to pass to it run and check because I misconfigured it (I did not bork the assertion logic as I previously assumed).
And that explains why the smoke tests were suspiciously fast ... ahhhhhhh
hmm, I'm considering to use technically internal APIs in my test suite
it's probably fine, other than then being a bad user, but like whatever, I'm a maintainer so it shouldn't be too bad
also blackbench already depends on internal APIs for production use soo whatever
So yeah, I "fixed" the performance issue caused by actually testing what I intended to test by using internal APIs
Subprocess calls are expensive man.
ahh just another normal day in OSS development: https://github.com/ichard26/blackbench/blob/c83d51dd23e83bfe099ad30084dcae2e306c6ca7/tests/smoke_tests.py#L29-L40
tests/smoke_tests.py lines 29 to 40
@pytest.mark.parametrize("target", resources.targets.values(), ids=lambda t: t.name)
def test_provided_targets(tmp_result: Path, run_cmd, target: Target):
# This is basically what the `βfmt`β task does, but without the huge subprocess overhead from
# `βblackbench.run_suite`β. It's not perfect, but smoke tests should be fast afterall. Oh and
# don't @ me about internal APIs and whatnot, it's fine (take it from a maintainer of black
# :P). Although seriously please try to avoid using Black's internal APIs as much as possible
# because their external usages makes maintenance harder :/
code = target.path.read_text("utf8")
try:
black.format_file_contents(code, fast=False, mode=black.Mode())
except black.NothingChanged:
pass```
I use Refined GitHub; and I'd highly recommend it.
Ahahah, it depends but it sure as heck won't be cheap. The last time I got paid to work on pip, it was at 150 USD/hr or so -- and that was a long-term project that I was interested in. This would be a short term thing I really don't wanna do. :)
Yea, well, that's exactly what it is.
Responded in the PR, asking what the next steps are.
Github refined is pretty good
Another why-did-it-do-that formatting question!
for installed_file in dist.get_metadata(
'installed-files.txt').splitlines():
Got changed to:
for installed_file in dist.get_metadata(
"installed-files.txt"
).splitlines():
Neither is good, and... well, IDK what black should do -- but why did it do what it did?
Single quotes?
The reflowing.
Gimme a few moments. It's from a PR I'm still writing the first commit of. :)
It's very deeply nested it seems
And also I'm used to black I guess, because it looks mostly fine
Black could wait until Monday evenings to release formatting changes, then everyone will have a full week to review the changes before autoupdatte day
everyone will have a full week to review the changes before autoupdatte day
the pre-commit.ci club, at least π
@drowsy sonnet while pinning helps, there needs to be a way to communicate the expected black version to black, as I use it in my editor and elsewhere so version mismatches cause me the most pain
If there were some way black could detect that a different version of black is being used in a project it could then abort and recommend the correct version
Eg the encode community projects all have different versions of black configured
There is one way! We have a required version configuration. That could be stored in pyproject for example
LOL
I mean... I only acted as translator for what was being said -- putting it in a less rhetorical form. That ain't the approach I want BUT it is a reasonable approach too.
Would be good if it supported pep621 version metadata in the pyproject.toml
And fell back to tool.black
does anything other than flit support pep 621 right now?
that's not to say that I don't think it's a good idea, just wondering how many users would be able to benefit from it if it were implemented right now
@jolly reef
I don't quite follow. The configuration is for other projects to specify Black's target version. How would metadata help us?
My guess is that graingert means the target-version is automatically set from [project].requires-python?
I have no clue
probably from project's dev dependencies
Oh yeah, that would require searching all of the extras (since dev is just one of the many names people use), it wouldn't even catch the dev-requirements.txt. Feels like a lot of work for too little gain, also sounds magical π
No I mean the version of black needed
ye, but it would be about supporting only pep 621
not any other ways of defining dependencies
Like ```
[tox]
minversion=3.12
But how does this interact with PEP 621 project metadata?
are you sure you mentioned the right pep then?
Or pytest minversion
Oh already?
Yep!
Indeed
TIL
You're welcome ;)
oh lol
That would save me some pain if people implemented it xD
Hopefully no one asks for range support (I'd probably reject it) π
I was confused because you responded to felix mentioning the required version thingie
and mentioned pep 621 rather than pep 517 :)
I was referring to this https://www.python.org/dev/peps/pep-0621/#dependencies-optional-dependencies
Originally the PEP wanted people to not put tool configuration in pyproject.toml but clearly that didn't happen π
ye okay, nvm
Black could read the required-version from
[project]
dependencies = ["black==21.b7"]
so??
[project.optional-dependencies]
dev = ["black == 21.7b0"]
means
[tool.black]
required-version = "21.7b0"
Right
hmm, does anyone else think that finding configuration options for black in its docs is now harder than it used to?
My usual process for finding them is complaining they don't exist until someone tells me they already do
Would an index help?
I'm guessing it's because you guys are hiding it now
The CMD output is a bit hard to spot yeah
We can get rid of the dropdown
it's just one big codeblock so that was my original concern π
it's hard to notice if you just want to quickly find the right configuration options
and scroll fast through it
I wonder if there would be an equivalent to sphinx-argparse for Click
I think there might be something
for generating a cleaner, indexable doc
Should that be its own page then?
well slap me sideways, that was quick
or is putting within the page still fine?
for context, people are (rightfully) saying that we should merge all of the usage and configuration pages into one
For me it was obvious that I'll find the config options in the "Usage and Configuration" page, I just was unable to spot where the options are once I opened it.
so I don't really mind if it's just long cli output or sectioned list of options
I think it would probably be nicer if it were a sectioned list of options but that's more effort
Or if we don't want to merge right now, maybe we could have another page right at the beginning: "CLI reference" or something like that
Alright, I'll look into sphinx-click then (TIL hopefully it works well)
The thing is that I really hate super duper long pages because it feels overwhelming
I like to be filter out the majority of the content by just skimming the headers
personally I just would appreciate some Table of Contents with a list of all options/flags so that I can jump right to the one I'm looking for
(to be clear this isn't a point against using sphinx-click, I am more talking about the general issue about the structure)
there's some issue on the tracker about it
Sow how about the "CLI reference" page then?
Since it's autogenerated I wouldn't mind
if it was not autogenerated, it would be a maintenance nightmare
I still need to get to the documentation again, there's a lot of improvements to be made sigh
"CLI reference" doesn't immediately jump out as a place where I would find how to configure black with a configuration file
oh yeah that sounds not great
(if you can't tell, I'm only like half-interested, I need to think about this more critically later)
I have too many projects on the go for black π
I'mma open an issue about sphinx-click tho
I'm not sure I entirely like how isort is doing it (might partially be because it's a lot more configurable than black which results in a very long list of options), but it does make it clear what is a config option in the file, what is the cli flag, what's the type of the config option (only needed for toml), and it describes the option nicely.
https://pycqa.github.io/isort/docs/configuration/options.html
and it's all listed in one place which makes it easy to search
I find their descriptions to be lacking a fair bit
In general, the documentation right now is more geared towards newer users, which wasn't really my main goal, but it shows. The README was massive but once learned, it was basically the easiest index-like page - and therefore really easy to use as a quick reference
as a returning user, I'm definitely not going to drop black because of annoying documentation which realistically I will look at very rarely so it makes sense to make it more appealing to new users who you would want to attract
there is an argument to be said that we already have a lot of users, soo maybe not ticking off the existing userbase would be better?
Maybe better naming of the pages would help
in hindsight the basics is not great
While it's accurate, it's useless if you're looking for something specific (unless you want to remember all of the weird ways things are named)
oh, I didn't notice the basics is its own page under usage and configuration
thought it's just all usage and configuration
I didn't really struggle with finding the right page though, I just struggled with finding stuff on that page
which did make me wonder if I'm on the right page though lol
People complained the docs now take too many clicks
which tbh I agree, just not sure how to fix it
https://github.com/click-contrib/sphinx-click
Also maybe do something to make this important piece of docs more searchable / findable for returning users.
This was suggested by https://github.com/jack1142.
perhaps "The basics" should just be the "Usage and Configuration" and the other documents should be in a different place
that would just require one click to get to the place you're looking for, assuming that you would get rid of the collapsible thingie
I just don't want to put too much stuff top-level again
for example it's unclear where blackd docs would go
Hmm, I'm starting to warm up to the idea of merging most of the usage and configuration content
sadly it's blackd that's an issue
This is also a lot of churn and I hate it
Any ideas on where blackd could go?
It's basically a whole another tool that has its own little usage and configuration docs so that makes it hard to just add to rest of black's usage docs
Not really. I want to say it could be top-level but it doesn't seem to fit it that well... "Integrations" kinda makes sense but when you look at actual documents in it, it doesn't make as much sense so I don't know
black-primer was fine since it's developer facing so hiding it under contributing was good enough
huh
the only other idea I had was putting blackd somewhere under guides
but that still doesn't make much sense
I feel like it makes sense under integrations because it's a tool for integrating black with your needs
I feel Integrations still makes the most sense even though unlike the most things there, blackd is suited more for developers that want to integrate some thing (i.e. editor) with Black rather than end user who wants to integrate a tool they use with it
"Guides" is a scope creep kinda
Yeah, although making blackd more user-friendly is an open idea
also, yeah my guides idea is dumb
let's ignore that
Although, blackd has been very stable and untouched these days so it changes down the road, dealing with the docs issue then is probably fine. I think I'm getting too caught up with longterm planning
as in, I don't find it obvious that the things that are in it rather than somewhere else. The Table of Contents on the index page does make it easier to find it though
OK, in summary in terms of structural changes:
- merge the usage and configuration content into one page
- move blackd to intergrations
- possibly change a few headers to be more descriptive
that sounds OK to me - will need a fair bit of redirects though to avoid so much churn
do you guys use RTD redirects?
We don't have any configured right now but I have RTD access so I can
I'm happy we stopped using GitHub as a secondary documentation host because redirects aren't really possible π
I guess another documentation thing that is worth discussion is the HTML theme
furo time? π
it's fine (and the proposed changes above don't clash with Alabaster) right now but mobile support is ... garbage
That would be my suggestion too (I use it for all of my own projects) but there is also the ReadTheDocs one
My main concern is it seems like Black is going for a more old styling? Like its logo is the Ford logo, the name is literal reference from many many years ago ... and ReadTheDocs / Furo are pretty modern in their design
was about to ask what's bad about it but then I decided to just open it on mobile and... yeah
P.S. https://sphinx-themes.org/ is a good gallery sort of page for many themes
yep!
You're not using the docs on mobile to say the least
also by Pradyun
I honestly don't understand why Alabaster is still the default Sphinx theme when mobile support is so big these days
I guess Python is still desktop focused so that's why.
https://sphinx-themes.org/sample-sites/furo/ is the new hotness afaik
You're the third person to mention that theme so yes, it is indeed hot π
I have my issues with it but it's generally awesome
mostly because I've been trying to apply it to a project with a rather big documentation
I personally find it a little frustrating when using on my laptop since the right sidebar TOC is hidden
works great for a smaller documentation I've been working on recently
although I fixed that by hiding my OS side task bar
indeed, https://blackbench.readthedocs.io/en/latest is one of mine (note: this project isn't ready for use yet)
mine is devguide-like documentation for a project I'm maintaining but I can't really link a full documentation as it's still all WIP with a bunch of PRs that each add different documents π
documenting and improving triaging process is fun...
haha can be annoying, maintainer docs are underratted tho!
yeah, there's so much stuff that maintainers do that isn't documented properly, making it rather dangerous if anything were to happen with those maintainers
Indeed, for example Εukasz isn't that active anymore but there was a time where only he knew the release process
that was one of the many reasons why we didn't release for so long
ye, I recently pretty much documented the whole release process, probably will have to automate it a bit further (though it is a already automated, just could be a bit more :))
We still depend on him for some admin stuff (he's the only admin on the repo) but in general we do just fine without his involvement (thanks to the 8 excluding-him person team we got)
I mean, in reality it's only really like 4 people who are consistently active, but that's still way better than a LOT of projects
I need to figure out how to automate releasing with a flit-based project still for blackbench
I recently automated a wheel building workflow and while there was a ton of head scratching (mostly at C buildchain stuff) it was indeed fun
Overengineering is a real threat to any of my projects' maintainability π
I bet for flit it's probably just "install flit and run flit publish", hopefully π€
I recently made the release workflow depend on the GitHub environment (so that I need to approve the run) after accidentally releasing from a wrong branch (which fortunately, did not contain any major changes, just resulted in an incomplete changelog)
I might play with that
Somehow I failed to switch Black's docs to Furo locally
I did remove a bunch of theme configuration without much thought, but it shouldn't be that broken?
this is what I've done basically to minimise human errors lol
jobs:
release_information:
if: github.repository == 'Cog-Creators/Red-DiscordBot'
name: GO HERE BEFORE APPROVING
runs-on: ubuntu-latest
steps:
# Print release information
- name: REVIEW OUTPUT OF THIS STEP BEFORE APPROVING
env:
TAG_BASE_BRANCH: ${{ github.event.base_ref }}
TAG_REF_NAME: ${{ github.ref }}
RELEASE_VERSION: ${{ steps.version_to_release.outputs.version }}
run: |
echo 'Release information:'
echo "- Branch the tag was based off: ${TAG_BASE_BRANCH#'refs/heads/'}"
echo "- Tag name: ${TAG_REF_NAME#'refs/tags/'}"
echo "- Release version: $RELEASE_VERSION"
release_to_pypi:
needs: release_information
environment: Release
name: Release to PyPI
# ...
I wish pypi did staged releases
I don't understand why this html is so broken
So you could upload it then approve it in the gui
there is an issue for draft releases or something like that
but no funding
yeah staged releases would be nice, sounds like money would have to be involved to get it done tho (unless there's an open PR for it already?)
hmm, perhaps there was even a PR π€ or maybe it was some other warehouse issue...
ah
I guess no funding was about some other issue I was looking at then
I don't remember what was the difference between draft vs staged releases, if there's any beyond naming
though I don't think this one has funding either
I'm going to try building a new environment from stratch, the theme clearly applied since the "built with the furo theme" line was added but the styles are very borked
what's weird is that there's no errors or warnings from sphinx
Right now, there are ways for package maintainers to test and share
draft versions of their upcoming releases, but they cause friction and
confusion. So we want to add staged releases -- a temporary state that a
release can be in, where PyPI has it and can evaluate it, but hasn't
published it yet.
We have also variously called this idea "unpublished releases",
"two-phase upload", "draft releases", and "package preview". This
feature will unblock a LOT of stuff we want to do -- see
https://wiki.python.org/psf/Fundable Packaging Improvements#Package_preview_feature_for_PyPI
for a list.
I guess it's the same then
I'm eagerly waiting for the static distribution metadata pep to be accepted and then implemented, it should cut down resolving times significantly
is it beneficial to pipenv or what is it about
So OK currently to get distribution metadata (so for example you could check for compatibility with the rest of the dependency tree) you need to pull down the whole wheel
which is wasteful if you're going to end up rejecting it
Sorry, I wasn't clear that the PEP I was referencing was about indexes, not some package metadata standard
googling told me it's about pypi serving this in its api, just was wondering if there was a party that would benefit from it the most (mostly because I recall something about pipenv or some other popular project needing more data in api to not be as slow as it is right now)
I guess any dependency resolver will benefit from it then
I believe it'd be useful for pip. The pip resolver needs to know information about many versions of packages you request
there's so many PEPs that it's easy to get them confused π
But right now it has to download the whole wheel to get metadata like dependency versions
Finally, I got the black docs to build with furo
So one thing that's painfully obvious is that logo PNG isn't transparent
there's this ugly white background
Oh for some reason there's two PNGs
ye
Oh yeah another plus of not using alabaster is that we get to get rid of the custom CSS I wrote π
surprisingly the CSS has not broken even though I'm no web dev
Anyway, time to write down the results of all of this discussion on the various related issues.
This Discord channel has been really useful for real-time communication lemme say! Discussions are 10 times easier here π
possibly poetry :)
https://python-poetry.org/
Python dependency management and packaging made easy
Basically anyone who needs to collect massive amounts of distribution metadata will benefit (that includes all dependency resolvers at least).
Very true
Whelp, I avoided using this extension because I felt like all of the many changes it makes would feel overwhelming but after some initial tweaking, it's pretty good! I'll probably need to disable quite a few more things but that's okay :) Thanks for nudging me to finally use it! ... although I still don't see a file tree for PRs :/
Refined GitHub doesn't provide a file tree for PRs
but please do use Refined GitHub :)
it's awesome
The one feature that you might want to be aware of is pr-branch-auto-delete, I think it's the only one that introduces surprising behavior
Apparently it's loading twice everywhere which isn't great
huh?
nothing seems to be broken other the home page activity box (but it's not a big deal)
refined-github.js:1924
Refined GitHub has been loaded twice. This may be because:
β’ You loaded the developer version, or
β’ The extension just updated
If you see this at every load, please open an issue mentioning the browser you're using and the URL where this appears.
that's actually a feature
wait what
hide-useless-newsfeed-events, hide-own-stars
eh, I like how they fill the space
then you can disable it :P
not useful by any means, but π
that's the beauty of it
there's even a nice bisect feature that allows you to find out which feature is making some change you don't like
Oh wow, I'm just using luck + the debug logs
this should indeed not happen though
bisect should be in everything tbh, vscode has it for extensions which is the first time ive seen it
It seems to have disappeared after a restart π
As far as I know, Black has stuck with the same old theme from day one. I'll admit it's nice and fits in nicely with the more rustic / old vibe the all of the branding has (eg. Ford-like logo, name based off quote that's quite old). Unfortunately there's a few hard-to-workaround issues:
- Phones or really any devices with small screens are not supported at all
- Due to limitations (ie. no scrolling support in the sidebar), there's custom CSS, see [
/docs/_static/custom.css](https://githu...
Oh and right as I click "post" it just hit me that I should include previews of the two other themes I mentioned
my thoughts are a mess :)
"as configurable as gofmt" means little to people who haven't used gofmt.
@dense jungle, are you sure Furo uses "+" for expanding the sections?
I'm just a little confused by that
Oops I swapped the two
Let me edit my comment
Sorry for that. I guess I opened the two tabs and then forgot which is which
Don't worry, just wanna to let you know to avoid confusion π
Much better! Thank you! Hopefully this sets the stage of what Black is all about (even as we're trying to figure out the consistency bit right now) a bit better.
I like the headings within a page better in RTD though.
Yeah the font of furo is quite basic, definitely less pleasant on the eyes even if I know readability was the reason why
But ultimately I think you should make the call as our informal docs owner :). I can talk about what looks better to me but that's all subjective
"JelleZijlstra-patch-1" I love this branch name π
that's just the default when you edit from the web UI. I was pretty proud of myself for writing prettier-clean docs in the web UI π
You almost fooled me into thinking you made a patch from your fork.
I'm more impressed the lint job didn't have any mean things to say at you
oh wait that was your comment
π€¦
Eventually one develops the ability to wrap a commit message properly to roughly 72 characters without a guideline in the GH merge box π
honest question: does it matter much?
line wrapping in commit messages you mean?
yep
eh maybe, it does keep text closer together (I always expand my terminal windows so it isn't a problem per se) just visually nice
hm, isnt the fact that 72 chars is pretty outdated the exact reason black uses more (88 iirc)?
Part of me wants to argue these two line lengths are different due to context, but I have nothing :)
aw sad winning by default is no fun 
I'm no fan of pointless arguments :-)
The docstrings PEP does say that strings should be wrapped at 72 characters I believe
... and there's a certain issue on the issue tracker related to that.
psf/black#2289
The template weren't applying the default labels ever since I renamed
the labels.
There has been enough issues about documentation opened recently so it's
probably worth a template for it.
And oh yeah PyDis exists as a communication method, let's advertise that :)
I would say that this is mostly due to tooling
GH will not show full commit header if it takes more than 72, and terminal has a standard 80x24 size
I would say that GH and other tools cutting it is bigger issue than it getting wrapped in terminal but I guess it could also screw up the view in something like a oneline git log
ohhhh
about this one
there's issue forms now
they're in public beta right now
You can define different input types, validations, default assignees, and default labels for your issue forms.
Yeah I don't think we are part of that beta right now
I'm not familiar with the etiquette in this server, do I just ping a random online mod to report these?
there's a partners channel that we have access to, @bright glacier already reported this person
I think you can DM @digital pilot ?
Yeah, not sure if that's less / more urgent but I've used the private channel we have access to before so eh
You can ping the moderators role if it's something that requires immediate attention
Otherwise you can also DM ModMail as mentioned
there was also this guy who pinged single person in a few channels
I reported them too :)
black is the top repo in https://github.com/topics/gofmt, https://github.com/topics/autopep8, https://github.com/topics/yapf, and even https://github.com/topics/code π
That's one way of beating out the competition I suppose?
The crash has been fixed for a little while now. Tentatively assuming
that this will lead to changes.
982e7fd Add ESP to sqlalchemy for black-primer (#2400) - ichard26
Hmm... I see my name. Why?
Oh yea. I might be biased, but I like how that looks. ;)
It's literally your system font; which is basically relying on all the work done by the designers that Microsoft, Apple, et al paid lots of money to make; and that has no "network impact". :)
I really hate it when docs override the system font
it just makes me punch the article mode button
Describe the bug
max line length formatting not applying when I use editorconfig. It applys only when I use vscode setting with black args --line-length=119. Please guide me if I missed anything.
To Reproduce
- install editorconfig for vscode plugin
- paste the following
.editorconfigfile recommended by django github
# https://editorconfig.org/
root = true
[*]
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
...
Black is the only formatter for python I use, it's rly good
I just meant that sphinx-themes.org is your doing as well as we were talking about furo just a moment before:) You're doing some awesome work with all the Sphinx things is all I want to say
Cool
It's probably the more of the domain of isort (their config afterall) but it is arguable that a "black" profile means it follows the spirit of black too and not just behaviour
I feel like that's an isort thing. I don't know what force_single_line dooes for example
Basically forces every from import to use their own lines
I don't like that π
too repetitive to read
but I think isort should make that decision
Yeah, hopefully not too many people think it's actually what black does (if it's even accepted).
I don't know whether I'm misusing scalene or something like that, but this doesn't look right :/
That's the result of profiling basically lib2to3_parse on src/black/trans.py
I highly doubt regex matching is actually taking 90%+ of the time
I don't have that much experience with C but actually poking into the generated C isn't that scary π I just found a difference when adding Final to a function local variable:
CPyL414: ;
- cpy_r_r533 = ((blib2to3___pgen2___tokenize___generate_tokens_envObject *)cpy_r_r0)->_numchars;
- if (unlikely(((blib2to3___pgen2___tokenize___generate_tokens_envObject *)cpy_r_r0)->_numchars == NULL)) {
- PyErr_SetString(PyExc_AttributeError, "attribute 'numchars' of 'generate_tokens_env' undefined");
- } else {
- CPy_INCREF(((blib2to3___pgen2___tokenize___generate_tokens_envObject *)cpy_r_r0)->_numchars);
- }
- if (unlikely(cpy_r_r533 == NULL)) {
- CPy_AddTraceback("src/blib2to3/pgen2/tokenize.py", "generate_tokens", 559, CPyStatic_globals);
- goto CPyL1132;
- }
-CPyL415: ;
+ cpy_r_r533 = CPyStatics[46]; /* '0123456789' */
cpy_r_r534 = PySequence_Contains(cpy_r_r533, cpy_r_r532);
- CPy_DecRef(cpy_r_r533);
CPy_DecRef(cpy_r_r532);
cpy_r_r535 = cpy_r_r534 >= 0;
if (unlikely(!cpy_r_r535)) {
CPy_AddTraceback("src/blib2to3/pgen2/tokenize.py", "generate_tokens", 559, CPyStatic_globals);
- goto CPyL1025;
+ goto CPyL1024;
}
That's some early binding right there π
Now there's a LOT of generated C code so it's definitely way more than I can handle but this is cool and fun (even if it may or may not help me optimize)
Sure, what's up?
This is probably not Black related, so in the future you might be better off asking in the dedicated help channels. But if you want to create the project, PyCharm simply warns you that you already have files there. No worries in pressing "Create from existing"!
LGTM, disabling empty issues when we have good templates and redirect to a general discussion board would be better in my opinion. But you've probably seen more issues and have more experience than I π and it's an easy change afterwards if we change our mind!
can black format docstrings?
It makes some changes to docstrings, yes
does it wrap docstrings to certain length?
whelp, I just tried to fix my touchpad not selecting text on click and drag but I ended up making things worse by installing a new driver so .. I uninstalled it
what's weird is that it's inconsistently not working
kinda a pain to deal with whole writing the docs for blackbench
Hmmm I wonder if it's a hardware issue since it seems to work if I press hard enough
Woo! I finished the last to-do item for blackbench 21.7.dev2 which was significantly overhauling the documentation. Now for the fun bit of tagging and pushing the release π (which will have to wait for tomorrow since funnily enough, I'm now busy again :P)
Will black drop support for running on Python 3.6 before January? (Eg due to the December EOL of python 3.6)
Most likely not. While we are discussing dropping it when the EOL happens, that might not even happen.
I have some nested tuples, but unfortunately one of them is not well formatted with black.
First one is formatted well but look at the second one - BOOK_CHOICES.
Can you explain why is that happening?
RADIO_CHOICES = (
("Value One", "Value One Display"),
("Value Two", "Text For Value Two"),
("Value Three", "Value Three's Display Text"),
)
BOOK_CHOICES = (
(
"Non-Fiction",
(("1", "Deep Learning with Keras"), ("2", "Web Development with D...
Getting failed to parse source file. AST error message: expression cannot contain assignment, perhaps you meant "=="? (, line 73) even if there is no error.
The code is
async def download_episode(download_url):
anime_name = name_parser(download_url)
filename = anime_name + download_url[-4:]
make_directory(anime_name)
download_path = os.path.join(anime_name, filename)
if not os.path.exists(download_path):
await (
await asyncio.cr...
^ I tried this yesterday when they posted in a different issue and couldn't reproduce it. Maybe someone else can extract a reproducible bug from it
Failed to repro as well with what they posted
Is your feature request related to a problem? Please describe.
Describe the solution you'd like
Describe alternatives you've considered
Additional context
To be fair that would be convenient
I'm guessing something that gives you the changes interactively
And asks you yes or no to apply them
That sounds a lot less simple than the current CLI π
Right?!
According to the black docs there's no "official" client for formatting files with blackd. I've been having trouble with the available plugin for PyCharm (BlackConnect) randomly throwing strange errors on files with more than ~800-ish lines.
Anyway, I whipped up a [simple cli script](https://gist.github.com/the-wondersmith/044de1be3adc1936b1e34f99f65a...
Whelp, looks like someone already implemented the "blackd client utility" idea I was kicking around π
Anyway, blackbench 21.7.dev2 is officially released: https://github.com/ichard26/blackbench/releases/tag/21.7.dev2 This is the first release I feel confident enough about to welcome some exploration by people-who-aren't-me π
Oh I managed to mess up the pyperf requirement, I thought pyperf~=2.0.0 would've worked but apparently not
I wish the blackconnect pycharm plugin would automatically start its own instance of blackd.
Iβd offer to help make a new plugin, but god jetbrains plug-in creation is possibly the worst thing Iβve done in my life
Great products, just never try to make plug-ins lol
I ended up just making a file watcher to run black
So for some reason my system is consistently inconsistent, like every 3rd process is slower than all of the rest. I tuned my system as well as I can with my knowledge so oh well :P
I'm just checking whether my optimizations are actually making a difference
Whelp, overall 5% faster on parsing, that's better than nothing but it's lower than I would've hoped
More work to be done I suppose π
@bright glacier have you seen the celery entry point layout? They recently collapsed all their entry points into one
No I have not, I'm assuming you're implying it was a bad change?
I haven't used celery before actually, so I don't have any context to determine how good of a change that would be.
wut
how to set black to not sort imports?
accorrding to this, its not supposed to sort imports, or did this change?
I'm -1 on the proposal but I know Jelle is at least on the positive side
Right now it definitely doesn't sort imports. If you're seeing imports being sorted, it's some other tool
No I'm implying it was fine. I just replaced the '-' with a ' '
I'm curious, how many entry points did they have?
Ah, black currently has three, black, blackd, and black-primer (this one is a tool for developers of black)

ah
isort is more likely to be the one sorting imports. to get it to produce output compatible with black you can use a custom profile, it's mentioned in the black docs
its a line length somewhere
so
the pre-commit hook for black should read from pyproject.toml?
its isort somehow
I have no idea what's different but today has been a whole heck of a smoother experience optimizing black (sorry I mean blib2to3) for mypyc π
Finally fixed isort
Can indirectly blame Joe because I copied the config from a pydis project but it was wrong in pydis :))
π
~~fyi the fix is making sure the config is correct https://pycqa.github.io/isort/docs/configuration/config_files.html ~~
Hi all. I am new to using black formatter. Is there a way to set max-line-length constraint for a single file? And the remaining files can use the default constraint.
Hi! Beyond the obvious answer of running Black twice with different arguments, there isn't. But I'm curious, why do you want that? π
A friend of mine wants to increase line length constraint for a particular directory and I do not want that constraint to hamper the entire repo
running Black twice with different arguments
This is a good idea. Lemme try setting black precommit twice and see if this works
Thanks Felix
My pleasure! Although I'd argue that if there is no specific reason other than preference, you might be better off reaching a consensus π
Hmm it might be worth considering having directory specific configs. I can think of at least one situation where artificially raising the limit might be useful, specifically templates (think things like django templates)
Fair point!
By directory specific, Iβm thinking itβll use the closest config, working from the file, out
Still needs two calls, but the configuration is much easier
Oh, I was suggesting this as a feature request haha
Oh π I see, go ahead! It might well be worth discussing.
this is nice project
Python 3.10 is currently in its last beta with a release candidate due next week (2021-08-02).
This PR tests 3.10-dev on GitHub Actions, currently Python 3.10.0-beta.4.
I put the versions in quotes in the yaml, because when 3.10 final is released and -dev is removed from 3.10-dev, quoteless 3.10 would evaluate to 3.1!
It would be nice to have a repo cpython developers add in their new syntax sugar every time the latest betas add the new support. That way we can have black run over that code super early and let us know what we fail on with more time before it becomes main stream.
I wonder if we could try format just the cpython test suite .py files for this.
Is black using libcst now?
I found the cpython test suite to be lacking in terms of exercising all the language features
they do a good job for all recently added features though
interesting, what are they missing?
I'd probably want some more complex expressions and bodies for if and while π
semantic features are well covered, but the syntactic minutiae are just not there: optional brackets, commas, newlines, backslashes, semicolons, ...
they are probably covered in the tokenizer tests to some extent since that abstracts all of this away from PEG in CPython
but for the purposes of black/libcst/... these are important test cases
Right, makes sense
Question about the Jupyter Notebook support PR - many of the handle_magics functions are duplicative of what's already in nbQA. Would it be alright to add nbQA as an optional dependency when running on Jupyter Notebooks, and import these magic handling functions from there?
Also, are there any generic concerns about adding Jupyter Notebook support?
Sorry I should get back to that PR but haven't had much time recently. I think we should land it but need to confirm all concerns are addresseed
As for adding a dependency, I'd be slightly hesitant to add more dependencies since they may also affect import performance. I haven't looked at nbQA though
Hi
Sure, I don't want to do anything you'd be hesitant about - and no hurry, I didn't mean to rush you π
You can run with pre-commit.com with different configs, with include and exclude regexes
Yes. Thats what I plan to do right now. Thanks
I feel like I ended up re-implementing a variation of black-primer π
I'm planning to use this to make sure there's no behavioral difference visible to end-users across a large swath of files between two invocations of Black (in my case interpreted vs compiled).
Hmm, looks like mypyc transpiles black twice during a wheel build (on CI via cibuildwheel), that's unfortunate :/ I don't think it's avoidable since it seems like any setuptools PEP 517 hook ends up executing setup.py (and the transcompilation) and both pip wheel (cibuildwheel uses this) and python -m build calls at least two hooks (get_requires_for_build_wheel or prepare_metadata_for_build_wheel + build_wheel). Kinda sucks that analysis + transpilation to C takes a good while (15-30s). At least locally it's avoidable using python setup.py bdist_wheel.
@bright glacier what do you think of landing this? ^
I'll take a look tomorrow (it's ~11 PM over here!) but unless there were significant changes recently I don't have any major concerns IIRC.
thanks!
Reading a file with universal newlines is not TOML compatible.
See e.g. https://github.com/toml-lang/toml/issues/837 for context.
Is your feature request related to a problem? Please describe.
https://github.com/psf/black/pull/826#issuecomment-493549892
... for collections that you know will grow, there was no way to anticipate it by exploding them into one-element-per-line. Why would you want that? Because it minimizes diffs and that is a thing Black advertises as a feature: minimizing diff noise.
Now with #826 effected, my short collections with trailing commas will all explode, introducing way too loud...
Aim for a Sunday release with notebooks support?
I'll be afk for 2 days but back Sunday afternoon.
sounds good
Exciting! I'm already watching the repo, but please do feel free to tag me in any issues which arise as a result of this
Sure thing. Thanks for all the work!
I want more test cases like this π
there are some syntax errors in there, should there be? π€
There is the 'syntax_test_suite' project which was a fork of the black's gallery to test out a chunk of PyPI, which I believe pegen also used a similiar thing before got merged to upstream CPython
What are the syntax errors you see? I didn't notice any
( x , *y , * z , ) = l
Oh I see, that produces SyntaxError: two starred expressions in assignment
there can only be one starred expression in assignment and this is detected during syntax parsing
ye
oh yeah there are 2-3 syntax error in there but they're parsed by the grammar
I guess that's the weird kind of syntax error that's produced outside the parser
these syntax errors are emitted after pegen π
ah
oh this is cool i'll check it out when I'm done with most of the grammar
thx!
here is the link: https://github.com/isidentical/syntax_test_suite
it's going to be great to help me hunt down the missing 1% of the grammar and edge cases π
I'ma bout 70% there
on that tuple torture file the new parser is ~30x faster than libcst
Hmm I wonder if mypyc compiled blib2to3 is slower than the experimental rust-based parser π
it's not a fair comparison yet π
Well yea ... I guess we'll see later then (I may or may not be currently optimizing blib2to3 for mypyc π)
@dense jungle perhaps it would be a good idea to hold off on the "universal newlines" PR since it appears like the suggested change may end up contested? https://github.com/pypa/pip/pull/10238#discussion_r680121388 (note that @drowsy sonnet is a member of the TOML org). Not sure what to make sense of it π€·
Yes, I started looking at the TOML issue too and it seemed like it was still under discussion
I'll watch it and follow whatever pip does
Exactly my thinking as well π
Currently it appears this is under discussion and the changes contained here may end up contested. Given we've already copied pypa/pip when it comes to our toml story, we are going to continue follow them and wait for how they resolve this first.
tests/test_black.py:34: in <module>
import black
src/black/init.py:47: in <module>
from black.files import find_project_root, find_pyproject_toml, parse_pyproject_toml
bm-venv/lib/python3.8/site-packages/black/files.py:26: in <module>
from black.handle_ipynb_magics import jupyter_dependencies_are_installed
src/black/handle_ipynb_magics.py:316: in <module>
class CellMagicFinder(ast.NodeVisitor):
E AttributeError: attribute 'dict' of 'type' objects is not writable
I was scared of this happening with the dataclass + subclassing + mypyc π
dataclasses + subclasses has been the biggest compatibility pain-point with mypyc and looks like the jupyter PR makes this situation worse. I won't block on it, but yay for more work *sigh*
Well OK I found at least one maybe-blocking issue with the PR
1β― cat tests/data/notebook_no_trailing_newline.ipynb | black - --check --diff -l 50 -v --color
Using configuration from /home/ichard26/programming/oss/black/pyproject.toml.
--- STDIN 2021-07-30 19:21:30.173162 +0000
+++ STDOUT 2021-07-30 19:21:30.246786 +0000
@@ -1,39 +1,37 @@
{
- "cells": [
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": []
- },
- "outputs": [],
- "source": [
- "%%time\n",
- "\n",
- "print('foo')"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- }
- ],
- "metadata": {
- "interpreter": {
- "hash": "e758f3098b5b55f4d87fe30bbdc1367f20f246b483f96267ee70e6c40cb185d8"
- },
- "kernelspec": {
- "display_name": "Python 3.8.10 64-bit ('black': venv)",
- "name": "python3"
- },
- "language_info": {
- "name": "python",
- "version": ""
- }
- },
- "nbformat": 4,
- "nbformat_minor": 4
-}
\ No newline at end of file
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {"tags": []},
+ "outputs": [],
+ "source": [
+ "%%time\n",
+ "\n",
+ "print('foo')",
+ ],
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [],
+ },
+ ],
+ "metadata": {
+ "interpreter": {
+ "hash": "e758f3098b5b55f4d87fe30bbdc1367f20f246b483f96267ee70e6c40cb185d8"
+ },
+ "kernelspec": {
+ "display_name": "Python 3.8.10 64-bit ('black': venv)",
+ "name": "python3",
+ },
+ "language_info": {
+ "name": "python",
+ "version": "",
+ },
+ },
+ "nbformat": 4,
+ "nbformat_minor": 4,
+}
would reformat -
Oh no! π₯ π π₯
1 file would be reformatted.
Diffs aren't handled correctly when piping in a jupyter notebook ... I'm not sure how Black knows it's a jupyter notebook but this should probably be handled in a better way
oh lol
You can use the --ipynb option to force treating it as ipynb
IIRC that got removed because I complained that it's bad UX, I didn't mean to remove it, but I definitely wanted to address it eventually
I was complaining about how internally it would be confusing to represent is_pyi and is_ipynb separately in black.Mode. We should probably bring it back but make it an error to define both flags at once at the CLI level
But given that we have both verbose and quiet treated separated I guess this ship sailed already π€·
@dense jungle thoughts? ^^
I'm close to finishing my review but I'm not fully decided on what to do about the above.
Honestly I feel like we should just add the option. If click supports mutually exclusive options we can use that, otherwise no big deal
Click does not, but it's fine to implement this manually
I believe there are also some packages that extend click to support it
but might just be easier to implement it manually
100%, cloup is one I know of, but that's way more heavy handed then implementing it manually
Overall it looks good to me, there's some possible cleaning up to do, but pretty all large PRs has deal with that. The only main change I'd like to see is to bring back the --ipynb flag, I thought about it some more and discussed it with Jelle and ended deciding / realizing that the ability to force ipynb mode is more important than the UX or internal representation (perhaps it will be fine in the end and it ends up just being a quirk of the codebase :slightly_smiling_face:). Sorry for back...
Alright, overall that PR LGTM, just suggested to bring back the --ipynb flag
I am trying hard now to think of a use case for putting type stubs in ipython notebooks π
I assume this is spam? https://github.com/psf/black/pull/2357#issuecomment-890126348
Don't understand the point of it, but that's pretty typical I guess haha
spam or they just replied to the wrong email in their inbox or something
That's possible too. OT I got curious to what language the surrounding text seems to be, apparently Portuguese according to google translate .. the more you know
FastAI are probably working on that as we speak, they love notebooks π
I'll add --ipynb back in now then, thanks for your reviews!
Whelp, now I'm dealing with my own edge cases:
--- test2.py 2021-07-30 21:04:16.577111 +0000
+++ test2.py 2021-07-30 21:06:17.376117 +0000
@@ -1,7 +1,8 @@
-def func() -> ((also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(
- this_shouldn_t_get_a_trailing_comma_too
- ))
+def func() -> (
+ (
+ also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(
+ this_shouldn_t_get_a_trailing_comma_too
+ )
+ ),
):
pass
-
-
Turns out the surrounding tree of the first body leaf can vary a lot (I should've saw this coming but didn't π ) making it a bit harder to figure out whether we're in a return annotation.
That case above ^^ isn't fixed by my original patch, currently working on (read: testing and trying to break) a better fix.
Yeah we got a lot of CI
And that doesn't include our CD pipeline π
building on multiple devices and OSes
you mean publishing the releases, right
wait its missing a bunch of checks using 3.11-dev π /hj
currently it's build sdist + wheel & publish to pypi, build os native binaries + publish to gh releases, and build docker image and push to dockerhub
Eventually there might be a few more jobs for automatic mypyc compilation π
Indeed.
Although the docker one runs on every commit to main too IIRC
which is how it should be tbh
Out of curiosity, why do you need to publish an image to Docker hub?
Honestly I don't know, I barely use docker so Iemme find the relevant issue (it's probably something with having a static build of black all ready to go for end users)
Can't people just do something like RUN python -m black . in their Dockerfile?
gtg
psf/black#1914
I still don't really get why they need a Dockefile for that instead of just installing it as a dep and running RUN python -m black . but I dunno
Me neither honestly :>
@stuck vapor I don't think this looks right:
~/programming/oss/black on jupyter [$?] via v3.8.5 (bm-venv)
β― cat tests/data/notebook_no_trailing_newline.ipynb | black - --check --diff -l 50 -v --color --ipynb
Using configuration from /home/ichard26/programming/oss/black/pyproject.toml.
--- STDIN 2021-07-30 21:23:14.558027 +0000
+++ STDOUT 2021-07-30 21:23:15.048800 +0000
@@ -8,11 +8,11 @@
},
"outputs": [],
"source": [
"%%time\n",
"\n",
- "print('foo')"
+ "print(\"foo\")"
]
},
{
"cell_type": "code",
"execution_count": null,
would reformat -
Oh no! π₯ π π₯
1 file would be reformatted.
~/programming/oss/black on jupyter [$?] via v3.8.5 (bm-venv) took 947ms
1β― black tests/data/notebook_no_trailing_newline.ipynb --check --diff -l 50 -v --color
Using configuration from /home/ichard26/programming/oss/black/pyproject.toml.
--- tests/data/notebook_no_trailing_newline.ipynb 2021-07-30 21:22:45.713550 +0000:cell_0
+++ tests/data/notebook_no_trailing_newline.ipynb 2021-07-30 21:23:26.889930 +0000:cell_0
@@ -1,3 +1,3 @@
%%time
-print('foo')
+print("foo")
would reformat tests/data/notebook_no_trailing_newline.ipynb
Oh no! π₯ π π₯
1 file would be reformatted.
I wonder if --code has the same behaviour ... but it seems unlikely someone would use that + --ipynb π
Well actually someone could technically argue that if someone is piping in a notebook with --diff then they will probably apply that diff so the current output is better (not really possible with the latter).
Yes, this would make sense to me. I know what to change if you'd prefer it to display the notebook-friendly diff - would you like me to change this?
So wait, which format are you proposing to change to, the one from piping or the one from a file?
I don't really care that much, just the inconsistency stuck out at me
IMO, what you've shown above would be the best thing to display.
If you want though, I can change so that this happens:
$ cat tests/data/notebook_no_trailing_newline.ipynb | black - --check --diff -l 50 -v --color --ipynb
Using configuration from /home/marco/black-dev/pyproject.toml.
src -
--- STDIN 2021-07-30 21:38:15.609258 +0000:cell_0
+++ STDOUT 2021-07-30 21:38:15.758472 +0000:cell_0
@@ -1,3 +1,3 @@
%%time
-print('foo')
+print("foo")
would reformat -
Oh no! π₯ π π₯
1 file would be reformatted.
hm, I can see arguments for both sides. Is the point of diff mode so you can easily get a sense for what black changes, or is it a way to be able to save diffs that you can apply manually?
if the former, we'd want the python-only diff; if the latter, we'd want the JSON diff
Personally I just use it for getting a sense of changes, so I'd want the Python-only diff, but others may have different use cases
My gut says that a Python-only diff doesn't make much sense since a notebook is already not 100% python code (I hope I am getting this right) so you would look at changes via the rendered version. BUT I get the Python-only argument too π€·
If the notebooks we're formatting are 100% python code then please ignore my statement π
What would be the expected output if you were to run cat tests/data/notebook_no_trailing_newline.ipynb | black - -l 50 -v --color --ipynb? (i.e. the command you pasted above, but without the diff)
This would show the json output. So IMO if you pass --diff then still showing json output would be consistent with that
β― cat tests/data/notebook_no_trailing_newline.ipynb | black - -l 50 -v --color --ipynb
Using configuration from /home/ichard26/programming/oss/black/pyproject.toml.
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"%%time\n",
"\n",
"print(\"foo\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"interpreter": {
"hash": "e758f3098b5b55f4d87fe30bbdc1367f20f246b483f96267ee70e6c40cb185d8"
},
"kernelspec": {
"display_name": "Python 3.8.10 64-bit ('black': venv)",
"name": "python3"
},
"language_info": {
"name": "python",
"version": ""
}
},
"nbformat": 4,
"nbformat_minor": 4
}
reformatted -
All done! β¨ π° β¨
1 file reformatted.
Hmm yeah that is a good argument for including the JSON-y bits
yes, sounds like JSON diffs make more sense
SGTM, let's ship it (we can always deal with any remaining issues as they get reported).
Well the good news with that is that I don't have any comments left and will press the fancy green button π
is there a way to allow top level await in black?
Not right now. Allowing that would make sense but it requires changing the grammar which is hard
Hmm, blackbench currently heavily assumes that the only input used during benchmarking is Python code. Once jupyter notebook support is landed, that's going to be a problem if we ever want to add a benchmark for it. I was trying to avoid this, but maybe generic benchmark (on top of the specialized and first-class support for task+target based benchmarks) support should be implemented ... I'll have to think about this.
While adding support for it in the backend should be quite easy, the CLI would need a rewrite since the entire core concepts of blackbench would be changed (not to mention docs and tests).
Love how I thought of this issue at midnight /s ... I guess it's better than never π
I think of the most features at 2am so
Just to clarify - should I change something in the Jupyter PR, or would the change go into blackbench?
oh it's definitively on blackbench's side
So one thing that hasn't been clear is how my mypyc work will end up integrated (take it as take you'd like). Currently I'm working on optimizing code under src/black/ (I'm done optimizing src/blib2to3 for the time being). Once the Jupyter PR is merged, I'll have to deal with the introduced crashes. I guess the main thing I'm wondering is how early / late in the process should the changes be merged in. Expanded stability + performance testing is still something I need to do (deferred until I finish up the majority of optimizations) ... we could either do it before merge or after.
The general-I'm-glossing-over-many-smaller-details plan I had in mind goes roughly like this:
- Finish up optimizations (edit: oh and I guess fix the the jupyter crashes)
- Finish up the wheel building workflow
- Check stability and collect official performance numbers on both Linux and Windows (I don't own a MacOS running machine)
- Merge
mypyc-support-pt2intomain<--- maybe we should move this item? - Perform expanded stability testing inviting members of the community to use the experimental compiled wheels
- Once we're reasonably confident the compiled version won't crash, publish a
black-mypycpackage on PyPI (basically previous step but with an even bigger scope) (I stole this idea from mypy's mypyc rollout) - Integrate mypyc (ie. the wheel building workflow) into the main CD pipeline (and misc. like publishing docs)
- Compiled wheels are shipped by default (ie. it's automatic opt-in)
cc @dense jungle did you have any knowledge / wisdom in this area from the mypyc rollout for mypy?
And yeah I'm expecting the above plan to take some time. While I'm not too worried that mypyc is going to break everything (from what I can tell mypy has been doing just fine with their mypyc compiled wheels), I'd like to avoid introducing too much breakage to people who haven't explicitly opted-in into this work.
Nothing in this plan is set in stone. This is definitely the biggest development project I've taken on for black and I don't have much experience managing and planning out these big multi-month projects. Feedback is highly welcomed :)
thanks for all your work on this! some thoughts:
- I don't think we'll need to go through a separate black-mypyc package; that's a lot of complexity and it likely won't help that much (few people are going to use it if it's not the default). Don't put too much additional work on yourself
- I'd like to start merging changes from the mypyc branch as soon as possible so you don't have to maintain too many patches
- I can help perform benchmarks on MacOS
- I can help perform benchmarks on MacOS
Great thanks! Although honestly I'm more worried about the arm64 / universal2 wheels crashing on M1 since unfortunately they aren't testable during the wheel build on CI (GHA doesn't provide ARM MacOS runners).
I'd like to start merging changes from the mypyc branch as soon as possible so you don't have to maintain too many patches
Surprisingly there hasn't been many merge conflicts (although that may change once I start modifying the code under /src/black more) so this isn't as much as an issue.
I don't think we'll need to go through a separate black-mypyc package; that's a lot of complexity and it likely won't help that much (few people are going to use it if it's not the default). Don't put too much additional work on yourself
Fair enough π
This is the weird instability behaviour I brought up a few days ago. It's always the first value that's significantly slower than the others (well until another benchmark runs, but the point is that it's consistently inconsistent). This supposed to be a tuned system with a fixed CPU frequency and a isolated CPU core π . I've seen stable results but just haven't been able to get them for the parsing benchmarks ... (this issue seems less severe with the format-fast benchmarks for whatever reason ...)
And no, more warmups don't help because which value in a process (run = process in pyperf land) ends up being the slow one changes for every benchmark ... (which has the fun side-effect of making some benchmark results quite stable because the slow one ended up being the warmup π)
Stripping out the outliers probably isn't that hard, but I wish I didn't have to do it in the first place (that's what pyperf + system tuning is supposed to handle).
not entirely sure how relevant this is, but i've had the same issue with other benchmarking tools besides pyperf, like the pytest-benchmark plugin
Oh so maybe it's not just my hardware playing poorly with this software. I don't know if that makes me feel better or worse ._.
Getting rid of the warmups seemed to make it significantly more stable. Not sure what that's all about but the weird consistent slowing down of a specific value seems to be gone *shrug*
What does pytest benchmark do
it benchmarks pytest tests
Well duh
not sure how to explain more detailed than that
!pypi pytest-benchmark
i can show a screenshot of outputs and link to where i use it in #ot0-fear-of-python
that works too
Anyway the upside of dealing with this mess is that I got my second round of numbers which look even better after my first wave of optimizations:
Faster (17):
- fmt-fast-dict-literal: 138 ms +- 5 ms -> 58.9 ms +- 3.6 ms: 2.34x faster
- fmt-fast-list-literal: 79.6 ms +- 2.7 ms -> 34.2 ms +- 2.1 ms: 2.33x faster
- fmt-fast-nested: 64.1 ms +- 2.2 ms -> 28.6 ms +- 3.0 ms: 2.24x faster
- fmt-fast-comments: 85.8 ms +- 2.7 ms -> 39.0 ms +- 2.7 ms: 2.20x faster
- fmt-fast-flit/sdist: 191 ms +- 7 ms -> 88.5 ms +- 8.2 ms: 2.16x faster
- fmt-fast-black/mode: 95.8 ms +- 3.2 ms -> 44.6 ms +- 2.6 ms: 2.15x faster
- fmt-fast-black/output: 88.5 ms +- 3.1 ms -> 41.2 ms +- 3.4 ms: 2.15x faster
- fmt-fast-black/strings: 158 ms +- 7 ms -> 74.5 ms +- 4.4 ms: 2.12x faster
- fmt-fast-black/linegen: 804 ms +- 30 ms -> 381 ms +- 27 ms: 2.11x faster
- fmt-fast-flit/install: 410 ms +- 22 ms -> 194 ms +- 12 ms: 2.11x faster
- fmt-fast-black/__init__: 843 ms +- 42 ms -> 400 ms +- 36 ms: 2.11x faster
- fmt-fast-black/brackets: 257 ms +- 8 ms -> 123 ms +- 14 ms: 2.09x faster
- fmt-fast-black/comments: 201 ms +- 7 ms -> 97.6 ms +- 7.9 ms: 2.06x faster
- fmt-fast-black/nodes: 648 ms +- 30 ms -> 321 ms +- 22 ms: 2.02x faster
- fmt-fast-black/lines: 584 ms +- 24 ms -> 294 ms +- 24 ms: 1.99x faster
- fmt-fast-flit_core/config: 552 ms +- 26 ms -> 288 ms +- 27 ms: 1.91x faster
- fmt-fast-strings-list: 25.1 ms +- 1.4 ms -> 13.8 ms +- 1.4 ms: 1.81x faster
Geometric mean: 2.11x faster
What's your question π
The github action, does it print its logs in the way that github will notice them?
What do you mean? Like github statuses / checks?
In that case, no it does not, but could be a good feature to add!
Yeah
Right now I just run black in the github action instead of via pre commit
It uses the official pre-commit action
But not during CI, where it runs the "local" black with check and diff
So github actions reports that
Honestly I'm not following at all (in my defense, GitHub's way of naming stuff IMO suck)
I can find my logs of a failed run where black outputted a diff since a file failed when I get home
Smh
There's commit statuses, git actions workflows, etc
So yeah they're kinda bad tho
It started with when I used the GitHub REST API. The https://api.github.com/repos/psf/black/issues endpoint returns both issues and pull requests. In the API docs, they say that "pull requests are a superset of an issue" ... but sometimes you can get a response representing a Issue that isn't a subset of a pull request. Makes data modeling way harder than it should be.
I wished that they instead added a base concept that holds fields that both issues and pull requests share
Then I could make a Base class and add Issue(Base) and PullRequest(Base) subclasses and the data modeling would make sense.
random fact you probably don't know
semantic versioning and toml were invented by the same guy
and: tom is also the founder of github :)
I was going to search that up but I don't have a browser loaded and currently my system is quite slow so screw that (I'm effectively running a single-core system right now lol).
lol
But very much a TIL.
Look, I have a dual-core APU and I isolated one of the cores (for benchmarking) so what else am I supposed to do. Fun fact, there's no hyper-threading either.
Thanks :^
anyways imma go mess with npm some more
cloudflare wrangler and npm play well together aka requires
ok
--- src/black/parsing.py 2021-08-01 23:28:28.954903 +0000
+++ src/black/parsing.py 2021-08-01 23:28:38.210934 +0000
@@ -36,11 +36,13 @@
else:
ast3 = ast27 = ast
if sys.version_info >= (3, 8):
TYPE_IGNORE_CLASSES: Final[Tuple[Type, ...]] = (
- ast3.TypeIgnore, ast27.TypeIgnore, ast.TypeIgnore
+ ast3.TypeIgnore,
+ ast27.TypeIgnore,
+ ast.TypeIgnore,
)
else:
TYPE_IGNORE_CLASSES: Final[Tuple[Type, ...]] = (ast3.TypeIgnore, ast27.TypeIgnore)
I am confused at why black wants to explode this collection literal when it clearly doesn't violate the line-length limit (see next line) ...
Getting rid of the type annotation made it collapse the whole collection into one line ... whelp.
Oh, maybe I've been misremembering black's style. I could've sworn that the exploding logic for collection literals was the same as function definitions / calls.
19.10b0 and 20.8b1 have the same behaviour so yea looks like expected behaviour ^^
Hey, welcome to the server! We cover a few things in #welcome, but the basics are you can use #python-discussion for most python discussion, #βο½how-to-get-help for python help, and this channel if you are interested in discussing the black formatter.
(For reference, black: https://pypi.org/project/black/)
.catify
#bot-commands is the right place to do that
jesus christ this is legal python
def f():
return f" oh no {yield 1} nonononono"
WHY?!
:O
sure enough, f() is a generator expression that yields 1
would be a fun bug to debug if you aren't vigilant :)
yield is an expression since the pep that adds generator coroutines
it would've been so simple to prohibit crazy stuff like lambdas and yield in there
well, there would be a real usecase for f'the value of the coroutine is {yield from get_string()}'
I like this one ```def f():
for (yield 1)[1] in [1]:
pass
oh yeah I recently learned about being able to put tuples and lists in comprehension targets
I can't think of a use case, can you explain? π
cool though, my parser can roundtrip that π
before async syntax in 3.5, the way you did async was using an @coroutine decorator and yield from instead of await
Our asynq framework makes you write something like yield user.get_name.asynq(). I can see people writing f"Hello {yield user.get_name.asynq()}"
There's one instance of that in our codebase π
also, don't forget that anything that is a valid assignment target can be in a comprehension
def fib(n):
return max(
d[1]
for d in [{}]
for d[0], d[1] in [(0, 1)]
for _ in range(n)
for d[0], d[1] in [[d[1], d[0] + d[1]]]
)
right, right, but why would you not just
yield from x
"hello"
more to my point I guess, when designing a language feature like f-strings, why not constrain it to disallow code that's going to be hard to understand π
The pep talks about it here: https://www.python.org/dev/peps/pep-0498/#supporting-full-python-expressions
Then you end up like with decorators where we've had multiple changes later to allow more syntax
eh, I don't find it confusing, just surprising at first glance
but there's a big spectrum between "only names" and "any expression" π
is that a bad thing?
It means there's more unnecessary churn in the language definition. Like if you want to write @a[b] you need to think about what language versions you target
that's an argument against any change to the language π
Sure, but the argument is stronger if the change could easily have been made earlier
trying to enforce clean code on a syntax level generally doesn't go well, you can always bypass it. People were doing
@getattr(None, '', lambda a: lambda b: a(b+1))
def fun(a):
return a + 1
```long before decorators were made general
Like now you just need to remember 3.6 = f-strings, instead of needing to remember 3.6 = some f-strings, 3.7 = slightly different f-strings
I suppose...
I sure hope the smaller-than-I-expected group of people using these are getting good use out of 'em :)
not even 50 downloads combined lol
I'm surprised that Windows is neck-and-neck with Linux for download count (20 vs 21).
it is also pretty interesting how annotations interact with yields, even under __future__ annotations;
$ python
Python 3.8.5+ (default, Mar 19 2021, 23:41:05)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import annotations
>>> something: (yield)
>>> __annotations__
{'something': '(yield)'}
>>> def foo(bar: (yield)) -> (yield):
... something: (yield another)
... return 3
...
>>> foo.__annotations__
{'bar': '(yield)', 'return': '(yield)'}
>>> foo(1)
<generator object foo at 0x7f48a04f8c10>
>>> next(foo(1))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration: 3
Yeah in PEP 649 we propose to make yields illegal in annotations. It's pretty evil
aha! so it doesn't matter if you're permissive or restrictive, there's always going to be churn π
oh no this is terrible π
it is actually fixed on the upstream now though
but I believe only on 3.10
AFAIK this issue predates the 649 but it was relevant https://bugs.python.org/issue42725
why would anyone ever do this, this isn't #esoteric-python
you can also put walrus operators in for more fun
Ah yes, a: type(a:=5), saves you having to update the type hint if you change the type of the variable π
I like ```py
a: a.append(1) = []
a
[1]
Or better yet:
>>> a: a.append(1) or type(a) = []
>>> a
[1]
>>> __annotations__
{'a': <class 'list'>}
type inference
wdym? and that's not related to black
I'm collecting weird stuff in here: https://github.com/zsol/LibCST/tree/parser/native/libcst/tests/fixtures, will add some of these π
lol ```this.is_not >>= a.monad
ye i was proud of that one
{"2.7", "3.6", "3.7", "3.8", "3.9", ("4.0" if gilectomy else "3.10")} i like this easter egg
del (a := [1])
for (z := 124) in (x := -124):
pass
with (y := [3, 2, 1]) as (funfunfun := indeed):
pass
Here's some more "fun" cases with the walrus operator (I remember these because I fixed a few "bugs" involving 'em).
as far as I can tell, the walrus is not a valid assignment target, but
for (z := 124)[0] in (x := -124):
pass
```is valid syntax
yeah those cases were made by looking at the grammar
del (a := [1])[1] might work too?
β¦why would you use this
The contributing guide suggests using tox to run tests. Perhaps it should be added to the dev dependencies? I would make a PR but I'm unsure how to determine the lowest version to add.
Removes types-toml from pre-commit mypy invocation's addiditional dependencies. Adds tomli and platformdirs.
@bright glacier friendly ping π
As mentioned by @cooperlees I described Docker image tags and provided two basic examples of Docker image usage.
Please note that I'm not native English speaker, so be forgiving π
sigh, I really dropped the ball on all things psf/black did I π. Didn't realize I stated I would be the one merging ... I assumed Jelle would.
Whelp, does anyone have any reason to block the merge? If not I'll press merge relatively soon.
!remind 2H don't forget to actually press the shiny green button on the jupyter PR
Your reminder will arrive <t:1628280220:R>!
Sorry I probably should have done that
Oh bloody heck, I prepped a Pipfile.lock related PR but the PR (which also touched Pipfile.lock) I merged above is now causing a merge conflict. Time to relock I suppose π
@bright glacier
Here's your reminder: don't forget to actually press the shiny green button on the jupyter PR.
[Jump back to when you created the reminder](#black-formatter message)
ugh, I'll deal with that soon, just need to deal with this merge conflict thing still (I got sidetracked with a help channel I was involved in :D)
I'm totally not messing up all of my git commands or anything π
finally! it only took a git stash, git merge main, git stash show -p > .diff, some manual modification of the diff because I can't do stashes today, and git apply .diff -3 phew
oh no, pipenv picked up my 3.9 installation, I hope this doesn't break anything
I should probably move to 3.9 soon, but I am really lazy so shrug
bloody hell what is pipenv doing:
+ "pytz": {
+ "editable": true,
+ "extras": [
+ "d"
+ ],
+ "path": "."
+ }
I have no idea why this happened ... did I make a mistake in Pipfile?
I'm about to press it, any final blockers?
I see a few more TO-DO items but they can be handled later.
And nah it's OK, I didn't see that I said I would be merging it, must've read that and then forgot about it or something along those lines π
let's do it
I am so confused, why did pipenv pull in pytz for even the normal dependencies, no where should black depend on pytz
I thought this would be a simple "make some changes to pipfile, relock, and you're good" but clearly not unfortunately
PR #2357 was recently merged :tada: For the sake of getting it merged somewhat quickly and to not tire everyone, we left a few TO-DO items for later. This issue attempts to list 'em so we don't forget :)
- Add documentation about the newly exported
black-jupyterpre-commit hook - Look into whether we should add the Jupyter deps to
Pipfileor just document the quirk (tox is unaffected)
I probably already forget a few tho, so feel free to edit / comment with more.
@feral spade Please don't try to ping @everyone or @here. Your message has been removed. If you believe this was a mistake, please let staff know!
Can I interest you in some GUIs
π¦
I use git add, git commit git push git pull git fetch and sudo rm -rf .git && git init on the commandline
(its when I mess up the repo so much)
.. Have you not ever used it?
Noβ¦ GUIsβ¦
Iβm not saying they solve all your problems, but Iβm not not saying that
Anyways probs ot
This is OT
only 1/10 of the convo I see in here is about black, and the other 8/10 are with black users and devs
is there a vscode plugin for black?
IIRC vscode has basic support for black via the python extension
it's one of your options in choosing a formatting provider for python
And because I thought the toml story couldn't get anymore confusing / annoying, now the type ignore that's currently present to the bare CR thing (so let's use bytes) is causing mypyc issues, gah!
wait where's the rest of the story
I'm curious because all of my projects now have toml and tomli as dev dependencies for coverage and black respectively
so apparently bare CR isn't actually a valid newline sequence if you want to follow the TOML spec to the letter
so everyone doing with open("file.toml", "r", encoding="utf-8") as f: data = tomli.load(f) is technically against the spec
now IMO it's a bit "are you kidding me"
i remember seeing a pull or issue on the toml github repo to change the spec to what is actually used lol
anyway, tomli in the interest of following the spec has deprecated strings and textIO
and apparently the type annotations have already been changed
so now our type checker is complaining on technically working code
fun
I really wished tomli changed the type annotation to something like Union[bytes, str]
because that is the actual support surface
I get you want everyone to switch, but given that all of this might end up reverted, it is very annoying
yeah
well
I guess I have some free time
@bright glacier why use tomli over toml?
toml is unmaintained
!pypi toml
!pypi tomli
toml has no support for TOML v1.0.0rc (not sure it's stable yet)
oh uh
lmfao
tfw toml links to
as the current spec
this entire story is honestly really frustrating
it feels even more unstable than the packaging world (as much as people really like to comment that it's moving too quickly)
which is what one of my orgs subprojects uses right now
I think that's other still maintained toml library
tomlkit is the slowest out of the bunch
oh?
makes sense given that has style preserving behaviour
my bad
lol
wait
i just read something and now...
why would python adopt this
Whitespace means tab (0x09) or space (0x20).
something that supports both is the cause of all evil
although toml has released 1.0.0 so yeah
honestly I don't mind tabs that much
tomlkit is still out of date
like I don't care which one you want to use, just please be consistent in which one
tomlkit
what i hate is a project I contribute to using tabs
like that fucked me up multiple times
β― python setup.py --use-mypyc bdist_wheel
Parsed and typechecked in 8.267s
Compiled to C in 0.000s
src/black/handle_ipynb_magics.py:228:5: error: Statement is unreachable
src/black/handle_ipynb_magics.py:351:31: error: Incompatible types in assignment (expression has type "CellMagic", variable has type "None")
this is annoying

the previous was cuter IMO
WHAT DO YOU MEAN TOO CUTE
Β―_(γ)_/Β―
+[mypy-black.files]
+# Unfortunately tomli has deprecated strings and changed the API type
+# annotations to bytes all while strings still work. We still use strings
+# since it's unclear whether this will last (depends on how much the
+# TOML people like bare CR as a newline sequence I suppose).
+#
+# See also: https://github.com/psf/black/pull/2408
+# https://github.com/pypa/pip/pull/10238 (because black is
+# following whatever they do)
+# https://github.com/toml-lang/toml/issues/837
+warn_unused_ignores=False
diff --git a/src/black/han
seems about right lol
imma go work on configurave lol
its a project that will import from toml files or export to toml and combine it with enviroment variables and custom sources
because toml is superior to yaml
but json is the ultimate best /s
ask me about configurave
I'm too wrapped up in making mypyc not generate broken code right now
no.
ez solution, don't use mypyc
what even is mypyc
!remind 5D maybe, just maybe ask about configurave
Your reminder will arrive <t:1628732794:R>!
:)
A Python-to-C transpiler based off mypy
black is compiled into C?
yep! C extensions to be exact
ah
wait i have a quick question, what would you use for a tui?
black uses click, but if you had to choose like idk
you mean command line interface?
yeah
TUI usually means a GUI but in a terminal
honestly I haven't used argparse much so I would try that
lol yeah, its because of the code jam
but I don't like any of them
is argparse in the stdlib?
well that settles it ig, lol. I don't want to add any additional deps to this
i know of (translated: I know they exist) click, cleo, typer
anyway, this explains the performance wins I posted earlier
typer is rather unmaintained these days
it doesn't support click 8+
wait wdym?
typer is based off click
pyproject.toml lines 29 to 31
requires = [
"click >= 7.1.1, <7.2.0"
]```
flit is a nice packaging tool
arguably I like poetry's dependency lists more
it still doesn't solve the "I have 5 different overlapping sets of dev dependencies" problem but it's still way nicer to use
I have 5 different overlapping sets of dev dependencies
dev dependencies that aren't compatiaible?
or like tests/docs/build dependencies?
I mean like: lint, tests, docs, docs-extra, dev (which should contain everything before).
ah
basically I wish you could combine extras
I would highly suggest making an issue like this on their repo if you want dependent groups
but tl;dr here are the new docs https://python-poetry.org/docs/master/managing-dependencies/#dependency-groups
flit's notion of dev vs production dependenies would work
if I didn't have two groups each for both lint + docs
No, but I use it for blackbench.
β― lexa requirements/
.rw-rw-r-- 106 ichard26 ichard26 23 Jul 18:55 docs-base.txt
.rw-rw-r-- 28 ichard26 ichard26 23 Jul 18:55 docs-live.txt
.rw-rw-r-- 18 ichard26 ichard26 23 Jul 18:55 lint-base.txt
.rw-rw-r-- 50 ichard26 ichard26 23 Jul 18:55 lint-extra.txt
.rw-rw-r-- 14 ichard26 ichard26 23 Jul 18:55 tests-base.txt
.rw-rw-r-- 35 ichard26 ichard26 23 Jul 18:55 tests-cov.txt
is my current solution

it's still in alpha π
I will, but I want to deal with a few more things first
!gh ichard26/blackbench
wait what
direct link works too π
bad ichard26
smh I can't look at this repo
aaaaaa
my CI and dependency/tools side is showing
to be fair, it's like my first proper open source project
.coveragerc can be in pyproject.toml :)
and I do use nox so it's the not the worse TM
and codecov.yml can be a hidden file named .codecov.yml
I don't use the hidden feature of dotted names
but sure, I guess I can roll that into my modernization branch I have locally
ah, you don't like it, that's fine lol
it's not that I don't like it, it's just that I don't care
I just prefer as many third party config files as I can to start with .
in my case, because I use isort too, I configure both flake8 and isort in tox.ini
but do agree if not having isort, .flake8 is better named lol
like you have it
oooooh
?
@bright glacier here's some info for you