#black-formatter

1 messages Β· Page 16 of 1

lament crow
#

so I just couldn't use it at all lol

#

you're doing awesome work, writing docs isn't as pleasant as coding (at least for me) and doesn't give immediate feedback but it can help the project a lot in the long run so it's good to see someone puts work into it :)

ionic nymph
ionic nymph
#

We've found two patterns that reproduce the bug, a line with just a \ or a ! will do the trick.

dense jungle
#

I guess we should report a bug to the gitignore parsing library we're using. In Black we can just try-except the exception produced and print that the gitignore is invalid

ionic nymph
#

@dense jungle We found the bug in the original parsing library, we're doing a little open source contributing session at work (Ordina Pythoneers), so we're going to open a PR to fix it at the upstream library.

dense jungle
#

Great! We might still want the try-except in Black for people using an old version of the library

ionic nymph
#

Alright

stuck vapor
#

Hello πŸ‘‹

#

Quick question - what do --run-optional no_python2 and --run-optional python2 do? I just tried both of them, and it seems to me that they collect the same tests:

$ pytest tests/test_black.py --collect-only
116 tests collected in 0.19s
$ pytest tests/test_black.py --collect-only --run-optional python2
 116 tests collected in 0.15s
$ pytest tests/test_black.py --collect-only --run-optional no_python2
 116 tests collected in 0.13s
tribal thistle
#

They collect the same number

#

But different tests (edit: are run)

#

Look for ones marked with

@pytest.mark.(no_)python2

#

(The python2 ones install the extra)

stuck vapor
#

Are you sure? It seems to me that both are collecting test_docstring_reformat_for_py27, even though it's marked @pytest.mark.python2:

$ pytest tests/test_black.py --collect-only --run-optional python2 | grep test_docstring_reformat_for_py27 
      <TestCaseFunction test_docstring_reformat_for_py27>
$ pytest tests/test_black.py --collect-only --run-optional no_python2 | grep test_docstring_reformat_for_py27
      <TestCaseFunction test_docstring_reformat_for_py27>
tribal thistle
#

Interesting, I can't repro that

#

hmm

#

Well, I can if I run collect, but actually running it, it gets skipped

#

tests/test_black.py::BlackTestCase::test_docstring_reformat_for_py27 SKIPPED (Marked with disabled optional tests (python2))

stuck vapor
#

Ah, you're right!

$ pytest tests/test_black.py --run-optional no_python2 -k test_docstring_reformat_for_py27
1 skipped, 115 deselected in 0.20s
$ pytest tests/test_black.py --run-optional python2 -k test_docstring_reformat_for_py27
1 passed, 115 deselected in 0.20s

Cool, thanks for your help, I'll try doing something similar for the jupyter tests

bright glacier
#

just gotta love an install error when trying to update your year out of date system πŸ˜„

#

I honestly have no clue on how my Python installation is set up / works in this environment.

#

It's one giant mess πŸ™‚

stuck vapor
dense jungle
#

site-packages/~ip hmmm

bright glacier
#

Yeah some sort of delete operation failed, pip renames a directory before truly deleting it

#

My environment isn't broken though, so I'mma just leave it alone for now and see if I can get away with mypyc + black without breaking something πŸ˜„

#

(I know, final last words)

#

It's been so long that I don't remember why there's two site-packages, one in roaming and another one in local

#

There's no such thing as virtual environments in this system, everything is installed user level (which is fun /s)

#

It's probably obvious which system I started my development journey on ahaha, it's windows.

tribal thistle
#

I can't even get mypyc working, and my environment is fine πŸ˜›

stuck vapor
#

πŸ˜„ yeah mypy has been just fine for anything I've worked on so far

Anyway, I opened https://github.com/psf/black/pull/2357 last week, and just wanted to ask if anyone has any early feedback - assurance that it's on the right track would be appreciated

No hurry though, I understand that reviewing PRs is hard and that black is probably an all-volunteer project!

bright glacier
#

I kinda have to wait for Windows update to do its thing since it's slowing down my laptop to unusable levels .-.

dense jungle
#

I'll take a look soon! I was on vacation for a week and barely caught up on github notifs now πŸ™‚

bright glacier
#

ooo welcome back then, and yeah those damn GH notifications are like spam, hard to get rid of and there's a lot of them

stuck vapor
plain atlas
#

weird

#

vim in powershell heh

austere lava
#

cool stuff

bright glacier
#

I've come to love Vim. It's my primary editor πŸ˜„

#

Although I do use Visual Studio Code for complex projects or tasks.

bright glacier
#

YAY, I was able to reproduce the Windows + mypyc "Reached allegedly unreachable code!" issue, now time to debug.

#

Some fighting and head scratching with Visual Studio and the C build tools / chain may have or may have not been involved πŸ˜‰

flat krakenBOT
bright glacier
#
>   if sys.platform == "win32":
RuntimeError: Reached allegedly unreachable code!
#

I guess this is because of the platform=linux in mypy.ini?

#

And somehow I've managed to freeze Notepad++ :sigh:

flat krakenBOT
bright glacier
#

oh for goodness sake, I switched shell from CMD to powershell and now I can't convince the build tools to use 64-bit mode ....

#

back to cmd I guess

bright glacier
#

@dense jungle would it be better to just remove platform=linux from mypy.ini or to add logic to setup.py to override that platform override (ie. "--platform={sys.platform}") under mypyc?

dense jungle
#

It doesn't make much sense to me for it to be in mypy.ini, so I'd just remove it

#

even without mypyc we should typecheck Black on Windows too

bright glacier
#

Fair enough, that's what I was thinking too. Let's hope this fixes the unreachable crash πŸ˜„

bright glacier
#

AND I got the test suite passing locally with mypyc-ified black on Windows! πŸ₯³ Now time to push my fixes and see if my cibuildwheel workflow will work now on windows.

#

The main reason why it took so long to get to this point is probably due to windows update. I've been debugging / compiling / testing with updates happening in the background and wow my system is slow and sometimes unresponsive πŸ˜„

stuck vapor
bright glacier
#

I like the lightweightness of vim though, so Visual Studio Code feels a bit much to me sometimes.

stuck vapor
bright glacier
#

I'm no vim pro :p

lament crow
#

Use language servers

#

I don't use vim but I know there is an extension/plugin for adding language server integration and then you can just use whatever server you wish to

bright glacier
#

TL;DR is that wheels have been successfully built for Windows, MacOS, and Linux across arm64, universal2, and amd64 / x86_64, but there's still a few smaller items to complete regarding the builds. More performance tuning and testing is also something that is on my radar.

lament crow
bright glacier
#

just saw that as I quickly checked the GHA default artifacts retention duration πŸ˜„

lament crow
#

lol

#

I thought of it after looking at one of the PR updates with more tests and seeing that it needs workflow run approval

dense jungle
#

hm where in the settings is it?

#

ooo "Actions"

lament crow
dense jungle
#

should have thought of that

bright glacier
#

My experience has been that the workflow approval hasn't been an issue for us (although we haven't experienced abuse of GHA either)

#

I'm just one maintainer out of many though πŸ™‚

dense jungle
#

I'm annoyed by having to click that button all the time

lament crow
#

ye, I haven't experienced abuse of GHA either which I just find it a bit annoying for the projects I work on

bright glacier
#

It actually hasn't been annoying for me lol

dense jungle
#

I'm not sure there's much risk for maintainers? I assumed GitHub did this to reduce resource usage

lament crow
#

they already changed the more likely abuse which is the upstream being affected by the activity of forks

#

which was dumb

dense jungle
#

I don't have access to the setting for Black but I changed it for typeshed

lament crow
#

I think it's annoying experience for first-time contribs too, because you need to run the tests locally rather than just rely on CI

bright glacier
#

That's a great point!

lament crow
#

when I'm contributing to such projects I often end up enabling actions on my fork just so that I can get the tests to run and see I don't fail something in CI

#

sometimes CI isn't the same as local run too so there's also that

bright glacier
#

I am curious about the "who recently created a GitHub account" bit, like I've seen spam from quite old accounts. Not that it matters much, but I'm curious πŸ™‚

lament crow
#

ye, "who recently created a GitHub account" might not be effective but I feel that until maintainers experience the abuse from their first-time contributors, it's probably better to go for that than make people's life harder

dense jungle
#

I feel like "don't run Actions" doesn't help that much against abuse anyway. I guess it prevents the PR from eating up our CI budget?

lament crow
#

but ye, just letting you guys know about the feature since not all people are probably following GH's changelogs

dense jungle
#

But we still have to close the PR

bright glacier
#

Indeed. I basically never contribute outside of projects that aren't either mine or ones I've contributed to already (I would burn out if I picked up more things) so this hasn't bit me much.

dense jungle
#

also, thanks for letting us know! really useful to have this option now

lament crow
bright glacier
lament crow
#

but like, if malicious PRs start happening, you can always temporarily enable it back as I doubt GH would just straight out block a repo on a first such PR rather than continuous occurence

bright glacier
#

Fair enough

lament crow
# lament crow they already changed the more likely abuse which is the upstream being affected ...

actually I thought this was about the forks affecting upstream repo without the PR, but now that I read the associated blog post again, it looks like they actually did change it so that PRs against the upstream affect the fork

The recent surge in cryptocurrency prices has driven a significant increase in targeted abuse across CI providers. At GitHub, we’ve seen a variety of vectors being exploited. One of these is pull requests from forks being used by bad actors to run mining code on upstream repositories. This obviously has a negative impact on repository owners whose legitimate pull requests and accounts may be blocked as a result of this activity.

To prevent this, we’re delivering two changes to how we treat pull requests from public forks in Actions to help maintainers.

First, we’re updating how we assess reputation on Actions. Specifically, if we determine an Actions run to be abusive or against our terms, our enforcement will be directed at the account hosting the fork and not the account associated with the upstream repository. The goal is to prevent maintainer accounts from being flagged and blocked due to these bad actors.

#

so should not be a big deal for repo maintainers to not require approval regardless of potential bad actors

#

other than big spam that literally throttles actions on your repo due to rate limits lol

bright glacier
#

yep! good thing it's easy to cancel workflows

dense jungle
#

oh ugh 😦 I haven't seen crypto miners spam in the wild on GitHub. mypy occasionally gets PRs that just seem like clueless people

bright glacier
#

still annoying though (the notification they send you when a workflow has been successfully cancelled is understandable, but annoying)

lament crow
#

I think the cancel notification is sent to the person that triggerred the workflow run, not the one who cancelled, right?

bright glacier
#

I don't know, but it's still annoying πŸ˜›

lament crow
#

ye, I wish the notifications for workflows were a bit more configurable

#

and I mean both on user level and repo level

#

for repo level I'm thinking of some actions that I wouldn't want people to be emailed when they fail

#

like... I wanted to make a check using GH Actions that fails when the PR has some "Blocked by" label (i.e. dependency, damage control, etc.) and make it required check but that would email the author of PR even though they did nothing wrong lol

#

I know I can use GH app/bot, just kinda wanted to do it with GH Actions

bright glacier
#

@dense jungle it looks like our test suite has a flaw: only the original safety checks behavior is used during tests, the extra runs behaviour isn't implemented, so the test suite is not reflecting real-world behaviour which probably isn't ideal?

#

oops

dense jungle
#

Yes, that's not good. I think it also doesn't do AST safety checks

stuck vapor
#

Yeah, I was like "they could submit a typo fix PR trivially, and then the protections would be useless"

LOOL, that's was I did last week, thanks for the fast approval πŸ˜„

bright glacier
#

I had zero reason to not trust you πŸ˜›

stuck vapor
lament crow
#

I on the other hand had some failures locally that weren't actually related to my PR but CI was passing

#

something about typed-ast

bright glacier
lament crow
#

I know I said it on one Black issue but I suppose it might have made some sense to make separate issue for it as well

bright glacier
#

Yeah, I just install typed-ast in my environment because I haven't spent the time to learn how the testing infrastructure works since the changes made during the refactors.

lament crow
#

the no_python2 test

#

we fixed the other with Felix so I should cross that out

bright glacier
#

I still need to actually do something about the "improving the contributing experience" issue, but I've procrastinated with other work πŸ™ƒ

#

actually @dense jungle I found at least a few tests that don't run the AST safety checks

lament crow
#

I'm in the middle of improving the contributing experience for one of the projects I work on right now too πŸ˜„ Indirectly though as it's about better triaging so that the status of issues is presented more clearly but in the end it helps contributors too since they know what issues they can (safely) make PRs for

bright glacier
#

there's like 4 different patterns of formatting code across the test suite, lovely!

dense jungle
#

😦

bright glacier
#

sigh

dense jungle
#

I recall somewhere that I had code that produced a syntax error in the output and the test didn't fail

bright glacier
#

Here's some patterns from a quick scan :

# I think this one is actually doing more work than necessary?
actual = fs(source, mode=mode)
self.assertFormatEqual(expected, actual)
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, mode)

# no AST safety checks since fs is a wrapper over format_str
actual = fs(fs(source))
black.assert_stable(source, actual, DEFAULT_MODE)

# also limited safety checks, although it appears be intentional?
ff(tmp_file, write_back=black.WriteBack.YES)
self.assertFormatEqual(expected, actual)

# this one is used by test_format.py (which contains the majority
# of our formatting tests)
actual = fs(source, mode=mode)
self.assertFormatEqual(expected, actual)
if source != actual:
    black.assert_equivalent(source, actual)
    black.assert_stable(source, actual, mode
#

Very consistent indeed πŸ™‚

#

It was way worse before test_format.py existed though, since every single format test file had to be linked up manually with the choice of how to call black yours! (lots of copying and pasting ended up happening)

#

At least what was copied and pasted over and over again called all the right safety checks πŸ˜…

flat krakenBOT
#

Describe the bug

no_python2 test errors on main while following Black's docs for contributing.

To Reproduce

Per docs:

pipenv install --dev
pipenv shell
pre-commit install
pre-commit run -a
tox -e py

The above works properly, however another run of tox -e py results in an error due to tox's usage of existing py environment causing no_python2 mark to be fulfilled:

__________...
lament crow
#

decided to make a full issue for easier tracking

#

almost gave up because it worked on first try lol

bright glacier
#

thanks for the issue! I don't use the tox setup because reasons ... so I wouldn't have known

lament crow
#

personally, as a new contrib I'm more likely to use those kinds of tools so that I can test while making contributions to the projects I'm not that familiar with yet rather than make a PR before I even am sure that I'll be able to fix it

bright glacier
#

yeah I'm well aware of that πŸ™‚

lament crow
#

once I am more familiar with the codebase, I usually just rely on CI πŸ˜„

lament crow
#

CI - Continuous integration

dusty compass
#

Doh should’ve known that one πŸ˜‚

lament crow
#

Basically running stuff like tests and any other checks on a build server

#

i.e. GitHub Actions

flat krakenBOT
#

Closes #2355

No added trailing comma in one argument function definitions

def no_trailing_comma_one_argument_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
    some_argument
):
    pass

This is consistent with the existing style for two and more arguments

def no_trailing_comma_multiple_arguments_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
    first_arg, second_arg
):
    pass
flat krakenBOT
flat krakenBOT
lament crow
# flat kraken

I assume it probably works but it feels kinda hacky, I wonder if tox has some configuration option to fix this BlobThinking

stuck vapor
lament crow
#

I was more wondering if it could somehow cache both of the environments as separate ones to still keep the performance of the cache but I suppose the recreate option is good too

#

oh right

#

cause it's all done in a single testenv right now

#

hmm

#

should be a matter of splitting it in two and adding to envlist?

#

with use of extras = instead of pip install too

#

and would have to not use skip_install which I'm not entirely sure why it is used in the first place

#

hmm, single coverage report

#

I guess that would be split too if splitting testenvs, not sure if that's an issue...

stuck vapor
#

just tried timing it with recreate=True, and on my laptop it took just under 1 minute

163.86s user 16.32s system 312% cpu 57.643 total

which, arguably, is fast enough?

Either way, I'm no tox expert, so if you know of a better way to do this I'll close my PR and you can submit a fix, no worries πŸ˜„

bright glacier
#

if anyone wants speed (eg. me) they can just call the individual commands (eg. me)

lament crow
#

Aussie detected πŸ™ƒ

bright glacier
#

I am in fact not an Aussie lol

lament crow
#

:o

bright glacier
#

Eh. It is what it is.

flat krakenBOT
#

Describe the style change

Currently, black does not check blank lines between functions docstring and body.
That means both these options are valid:

def foo():
    """docstring"""
    
   return 0
def foo():
    """docstring"""
   return 0

As black is uncompromising and opinionated, I guess this should be taken into account.

Personally I tend to put a blank line but looking at the only potential reference [PEP 257](https://www.pyth...

celest sorrel
#

whats a foo

#

and a docstring

gilded sable
celest sorrel
#

ih

#

uh

#

k

gilded sable
bright glacier
dense jungle
#

let's do i

#

t

bright glacier
#

Sounds good to me!

#

oh wait, there's an error in the setup.py requirement definition 🀦

late dewBOT
#

setup.py line 77

"tomli>=0.2.6.<2.0.0",```
bright glacier
#
>>> Requirement("tomli>=0.2.6.<2.0.0").specifier.contains("2.5.5")
True
#

well lemme fix that

dense jungle
#

oh it's a period instead of a comma?

bright glacier
#

yep, tiny mistake that makes packaging think 2.5.5 is now a valid version ._.

dense jungle
#

Looks like graingert has been getting a lot of projects to switch from toml to tomli, that's another reason for us to switch too

neon loom
#

What a time to be alive

#

I vote push when that’s released just to see who that upsets …

#

*merged even

bright glacier
#

here's what happens with a comma lol

#
>>> from packaging.specifiers import SpecifierSet
>>> SpecifierSet(">=0.2.6,<2.0.0").contains("2.5.5")
False
#

just almost entered a git command into discord by a window switching mistake πŸ˜…

neon loom
#

@dense jungle LoL

dense jungle
#

glad to be helpful

neon loom
#

Much satisfaction.

prime gull
#

@solid adder congrats on being the first cpython developer-in-residence!

solid adder
#

Thanks

plain atlas
#

wait @solid adder is the first member here who has the cpython core devs role?

#

<@&699731944149090466>

#

no nvm they aren't

#

there's at least 3 others

solid adder
plain atlas
#

??

solid adder
neon loom
#

Black formatted cpython here we come πŸ˜‚

frozen badge
manic zinc
sour verge
#

In the location ~/.config/black I have
[tools.black] line-width = 79
But black still uses 88 unless I pass it as a command argument...

Any ideas?

mint barn
#

whats psf

lament crow
#

Python Software Foundation

lament crow
#

as project's pyproject.toml takes priority over user configuration

neon loom
#

@dense jungle + @bright glacier - Thoughts on a low risk release for toml + other fixes?

dense jungle
#

Go for it

#

let me check what else we merged since the last release

neon loom
#

P.s. I ran experimental on some FB code, but even without it we had some crashes ....

#

Haven't had time to dig in

dense jungle
#

hm, doesn't look like we've made a lot of changes to formatting behavior since the last release. would be good to resolve if there are new crashes though

neon loom
#

O, we don't have black on 100% of our repos so I'm prob hitting areas that are disabled etc. - Haven't looked into it. I can now parse a toml config with the new library easy having tomli so I'll write a runner to parse our internal config file and check those directories only

#

It was a very hacky runner just to see how it went

#

I need to also try it on Instagram

#

Bah - I am blind - Ignore my dataclass comment on diff, clicked wrong button as I was doing a review. Then saw it, I was like I thought we were using these elsewhere.

stuck vapor
bright glacier
#
GitHub

Get rid of .github stuff
Cya profiling stuff (this really isn't useful for end-users)
Yeet Vim plugin files
Dust away official Action

GitHub

Closes #2178, alternative to #2218: This PR continues on the work of Hasan Ramezani in the alternative PR to improve the error messages when parsing formatted AST. His original commit is till at th...

#

They should be low-risk but I don't think these had strong approval either so 🀷

dense jungle
#

I have no opinion on the MANIFEST one but cooper seemed to disagree?

#

I'll take a look at the other one

bright glacier
neon loom
#

That's exactly my point. Can we leave all the CI config please

#

I feel we're limiting people there for little gain. Now the other stuff, that makes sense to me to clean up.

bright glacier
#

How about we just remove profiling?

#

It's like 40% of a git checkout size

neon loom
#

Ya, makes sense to me

#

What creates that again to refresh my memory?

#

makes/uses

bright glacier
#

It's so old lemme look at the commit history πŸ˜›

#

Looks like those files were used as profiling targets when working on performance regressions / lows

bright glacier
#

I've occasionally used them as a quick benchmark between two versions, but that sort of stuff is rather rare.

#

Sdist (on main): 1.1M, sdist (with prune profiling): 540k

#

The rest of the difference between the sdist and wheel (roughly 400kB) is basically the docs and tests now IIRC. That's a fair bit of text lol.

bright glacier
#

OT: is it just me or is the requests documentation getting worse over time?

plain atlas
#

Wdym

#

Oh

#

πŸ€¦β€β™€οΈ

bright glacier
#

I'm trying to create some new graphs regarding the pull requests and it's shockingly hard to navigate.

plain atlas
#

Thought you meant are the requests for documentation getting worse

#

But you mean the requests lib...?

lament crow
#

the theme doesn't help

bright glacier
#

Yes. I'm querying the GitHub graphql API

lament crow
#

sidebar menus are useful

#

and here you need to scroll up...

bright glacier
#

But like why is the table of contents so low in the sidebar ???

plain atlas
lament crow
#

but just scroll a bit and you don't even see the toc at all!

bright glacier
#

I'm used to requests as my http library but honestly I might just use urllib3 or something like that

lament crow
#

tbf, Python's docs have a static toc too

frozen badge
#

what exactly is it you're looking for? i found most stuff in requests is so simple the docs are rarely needed.

plain atlas
#

I personally use httpx rn lol

lament crow
#

but well

#

with Python I know what I'm looking for generally

#

with requests, I have no idea

#

will know when I find it

bright glacier
#

Requests is simple, but the documentation experience is not great (tm) so when searching for stuff like (like how to add a timeout or auth) it's annoying, not hard, just annoying.

plain atlas
#

Aiohttp

frozen badge
#

my approach to documentation in general is just to google what im looking for like "python requests timeout", click the first link that seems promising, and ctrl + F my main search term

plain atlas
#

But actually I would use httpx for simple stuff now. Aside from not having websockets, it's basically a drop in replacement for requests

bright glacier
#

I think I'll stick with requests for this project, but the next one I'll probably look for something new.

lament crow
#

that's a terrible section name if I just want to find how to make a request with json payload

frozen badge
plain atlas
bright glacier
lament crow
#

d.py docs at least have a ToC go with you!

bright glacier
#

Also that mailchimp ad is quite something

frozen badge
lament crow
#

d.py is all on one page which just freezes my mobile browser and Ctrl+Fing gives you a lot of stuff but usually Ctrl+Fing still works for me

#

but then again, as you play more with it...

#

you learn how to work with it I guess

bright glacier
#

It's mostly the TOC being hard to use in the documentation, Black's TOC ain't great either, but at least it's not hidden down.

frozen badge
#

in dpy its really the library design and not the docs

plain atlas
#

@frozen badge the 2.0 docs also got a minor face-lift fyi

#

For dpy

frozen badge
lament crow
#

scroll down

#

and then it's not there

#
  • it's really far down
frozen badge
#

the only meh thing is that you always need to start on advanced usage

lament crow
#

there should just be one toc

#

listing all the stuff

frozen badge
bright glacier
#

here's my view

lament crow
#

instead of separate "Useful Links" section

frozen badge
lament crow
#

the toc doesn't scroll with you

#

it does on black :P

#

and I can barely see the toc too

bright glacier
#

I wonder if that's due to the custom CSS we added πŸ˜›

lament crow
#

when I'm on top

frozen badge
lament crow
#

and actually...

#

how do I even go to homepage lol

bright glacier
#

You tell me dude.

frozen badge
lament crow
#

I can go to GH with star button

#

but there's no "Requests" header or something that lets me click on it so that I can go to homepage

frozen badge
frozen badge
#

this is why i dont rely on the docs themselves to be easy to navigate

#
  1. search on google
  2. find link and ctrl + f
  3. read relevant sections
  4. start over with new terms if nothing found
bright glacier
#

Maybe it's just me fooling myself that docs can be easy to navigate given I'm the one responsible for black's docs πŸ™ƒ

lament crow
#

do you guys still use IRC

#

for black I mean

bright glacier
#

Nope.

frozen badge
#

@lament crow you are currently speaking in the black irc

#

well

#

where its migrated to

bright glacier
#

Discord is the new IRC?

frozen badge
#

isnt it? you used the IRC for what you now use this channel for, right?

lament crow
#

ye, I asked because I've seen there's an IRC link in black's docs but now I see that I was on stable, not latest docs so my bad :P

bright glacier
frozen badge
#

yes, i meant that the black IRC has moved to this channel

#

not that discord = irc

bright glacier
#

Ah ok that makes sense.

bright glacier
#

And here's the first graph produced by my latest scripting project. Note that "core review" means a review either by a collaborator or a contributor of the repo. Also note that PRs without a review in their lifetime had their delay value calculated with their creation date diff-ed either against their merge datetime (I'm assuming the PR was reviewed while merging) or the current datetime.

#

Yeah, there's a few PRs that had delays of over 400 days πŸ˜… (it's the vim ones of course)

#

Oh right and PRs that ended up closed aren't factored into the calculations at all (mostly because I was too lazy to handle their edge cases).

dense jungle
#

nice! I guess the data for more recent months is biased downward because it doesn't include PRs that are still open

bright glacier
#

Unless I'm misunderstanding your point, that bias shouldn't exist since PRs that are still opened are factored in?

dense jungle
#

though maybe there aren't any PRs that haven't received any review

bright glacier
#

That seems more likely, there were a lot of PRs that were never reviewed back then lol.

#

Also, because I keep forgetting to mention all of the little details, only the delay between the PR being opened and the first core review is counted.

#

The delays between the next reviews aren't counted - my thinking was that the initial delay is way more important to the contributing experience then the average delay of the all reviews.

#

And yes I was inspired to make this graph reading up on the DIR position πŸ˜„

#

But anyway, I think this shows *some* progress in improving the contributing experience. Having your PR be a desert ain't fun and reducing time spent in that state is IMO important. Makes sense since there's more people available to do reviews these days πŸ˜„

dense jungle
bright glacier
#

Well first of all I don't have any plans of actually reviewing it anytime soon (matter of fact I just removed my self-request) πŸ˜›

#

I sorta get its value (maybe you have some fancy frontend to your CI pipeline or test suite) but it feels like a lot of code for an uncommon use-case (I feel the same way regarding the GitHub Actions statuses integration issue)

#

I'm also worried that if we implement that, we'll get closer to "black is now a linter" zone and I would rather not go there.

dense jungle
#

Yes, I feel like invoking Black in CI should just be --check: if it returns 0 you're good and if it returns 1 you're not

bright glacier
#

and another graph, with atleast all of the same pitfalls as the previous one πŸ™‚

lament crow
#

as well as my own lol

#

well, that's assuming I don't use pre-commit already anyway

#

since then it has diff on failure flag

tender jay
#

I need to make a socket and how can I make like a delay for example

#

the server waits for few seconds, if the client dont send anything in this seconds I will reply to the client a message that the package is loss

#

this is I'm doing

tribal thistle
bright glacier
dense jungle
#

I don't feel like the question I asked there was ever answered: what observable behavior does this change?

bright glacier
#

Looking at the code probably nothing. And if my knowledge on this area is serving me right, we still need typed-ast < 3.8 because feature_version support was spotty for the built-in ast module so that answers their "question reply".

#

If so, I want to ignore that and work on getting the PR landed.

dense jungle
#

yes, seems like a blib2to3 issue

bright glacier
#

Alright cool, I'll let them know that we can just ignore that (it's probably fine, Black happily accepts invalid input in certain edge cases so it's not Black is good at being a syntax checker anyway) πŸ™‚

stuck vapor
#

typing-extensions only introduced TypeGuard in 3.10.0.0, is it OK to bump the minimum requirement of it for #2357 ?

dense jungle
#

yes

bright glacier
#

Don't forget to bump the requirement in Pipfile although it appears no locking is required whew πŸ™‚

#

I recently did a pipenv lock (for the tomli PR) so it looks like the pinned typing-extensions is already at 3.10.0.0

stuck vapor
bright glacier
#

Wait what?

#

Oh you mean like it being pinned to 3.10.0.0 already?

#

Yeah pipenv lock upgrades all of your dependencies when relocking

stuck vapor
#

yeah, I meant: to make 3.10.0.0 the minimum runtime dependency. Currently setup.py just has "typing_extensions>=3.7.4; python_version < '3.8'",

stuck vapor
#

Is the Pipfile meant to contain all the dev dependencies? I'm just a bit confused as to why pytest and tox aren't there

tribal thistle
#

I think I left a comment on that in my first time contrib feedback

#

For whatever reason, package deps are in pip file, but doc and test deps are separate

#

It technically allows you to do things a bit quicker, say if you just wanted to build docs, or just wanted to run tests

#

But I don’t personally think the time gain there is worth all the extra setup steps

bright glacier
#

I think it would be good to like move them in tests/ and add the test dependencies to pipfile.lock

#

I just haven't done that yet (well IIRC I have actually have a local branch with such a commit but I didn't finish the rest)

#

That file might be worth keeping for CI since speed is quite import there tho

tribal thistle
#

Speaking of, I left an update on my pre-commit issue
psf/black#2299

toxic stormBOT
bright glacier
#

!remind 18h look into maybe* pushing a new release

late dewBOT
#
Sure thing!

Your reminder will arrive in 18 hours!

cinder ivy
#

When I use pre-commit I noticed black and isort were in conflict when it comes to long lists of imports

#

I tried to add an argument for the isort hook but I still have the same error

#

β€”profile blackdoesn’t seem to work for some reason

lament crow
#

Is it about magic trailing comma perhaps?

#

i.e. isort puts the imports back into one line even though black considers it fine?

#

Other than that, the only other thing I can think of is not setting same line length for both formatters or some edge case

#

Without you showing actual code, it's not possible to tell what is actually wrong and if there is even anything wrong.

cinder ivy
lament crow
#

Can you show an example?

cinder ivy
#
from drf_yasg.utils import swagger_auto_schema
from rest_framework import status
from rest_framework_simplejwt.views import (
    TokenObtainPairView,
    TokenRefreshView,
    TokenVerifyView,
)

from .serializers import (
    MyTokenObtainPairSerializer,
    TokenObtainPairResponseSerializer,
    TokenRefreshResponseSerializer,
    TokenVerifyResponseSerializer,
)
lament crow
#

And the output is?

cinder ivy
#

Oh nevermind I solved it by just passing args inside setup.cfg

#
[isort]
profile=black
multi_line_output=3
flat krakenBOT
#

Describe the bug

If a with or async with statement with multiple with items has parenthesises around the items, like in this example:

    async with (
        get_connection_pool() as pool, 
        get_cursor(pool) as read_cursor, 
        aiohttp.ClientSession() as session
    ):
        ...

Black fails to parse it with error: cannot format ...: Cannot parse error, even thought the regular Python interpreter has no problem executing the file.

**To Reprodu...

dense jungle
#

yay I get to close a duplicate

flat krakenBOT
late dewBOT
#

@bright glacier

It has arrived!

Here's your reminder: look into pushing a new release.
[Jump back to when you created the reminder](#black-formatter message)

bright glacier
#

@neon loom it would be great if you could do a quick look over for the MANIFEST.in PR, it's probably the last thing I want to get in for the next release. Thanks!

neon loom
#

Sure

bright glacier
#

Great! So what are we thinking for 21.7b0?

dense jungle
#

it needs to happen

bright glacier
#

Got any final things you want landed?

rose moth
#

How to use black in vscode?

tribal thistle
#

The docs have a guide on doing that

#

Side note: docs look really weird on mobile

urban cape
#

!remind 3s hi there

late dewBOT
#
Absolutely!

Your reminder will arrive in 3 seconds!

#

@urban cape

It has arrived!

Here's your reminder: hi there.
[Jump back to when you created the reminder](#black-formatter message)

urban cape
#

sry shouldn't have done this here

flat krakenBOT
flat krakenBOT
flat krakenBOT
neon loom
#

I'm off the grid (literally - Going off roading) in ~10 mins or so - So I can cut a release now or someone else can do it over the weekend. I won't be back till Monday evening with Internet.

#

I might add the change log entry myself for #2374 and merge if we do want to push now

dense jungle
#

let's do it now, if anything goes wrong I can deal with fallout

neon loom
#

(Y) I'll go add a commit to that with changes entry - I guess it would be nice to get new platformdirs too - That import speed is a nice win

dense jungle
#

It can wait though, no hurry

dense jungle
#

@neon loom I noticed one PR that was merged after the last release got put in the wrong place in changelog, let me push a change to your PR real quick

neon loom
#

@dense jungle - Sure - thanks!

dense jungle
#

more than one actually

#

done

#

It's pretty easy to make this mistake with the way CHANGES.md works; if there's a release between the time the PR is made and the time it's merged, the changelog entry will likely end up in the wrong place

neon loom
#

Cool - once CI passes I'll merge and cut a release. Cheers

dense jungle
#

it did!

neon loom
bright glacier
#

I don't understand what change we made that allows this person's interesting way of building our docs to work now, but I'm happy it's closed :)

#

(that was kinda a joke btw, I bet they installed black before building the docs which has been a requirement for a long time)

tribal thistle
#

Why do people build docs? isn’t that what CI is for?

#

Does it actually upload the results anywhere

bright glacier
#

Looks like that was a packager for some distro in that issue

#

why else would you make a man page

stuck vapor
bright glacier
#

even the same person gosh

tribal thistle
#

I don’t think I’ve seen something quite like this before.

#

Are they building their own python tool with like… all the packages ever?

dense jungle
#

I'd guess they're a Python package maintainer for some linux distro, but apparently that's not the case?

flat krakenBOT
#

Oh nice, one less unmaintained dependency; and that import time reduction is real nice :tada: I hope the pipenv locking wasn't too painful :)

Thank you for the PR!


By the way, if time allows it would be great if you could add any comments on your contributing experience here: #2238. I understand that you're probably busy though. P.S. thanks for maintaining virtualenv :smiley:

bright glacier
#

!remind 1D document docker tags

late dewBOT
#
Affirmative!

Your reminder will arrive in 1 day!

bright glacier
#

P.S. you can skip like the first minute of their video, it's just them setting up a virtual environment pretty much.

bright glacier
#

OK, maybe not a long time (the last commit was from Jan 2020), but in general IIRC this theme was built during the era when responsive mobile design considerations weren't really a thinig

tribal thistle
bright glacier
#

isn't it shown in the video?

tribal thistle
#

Uhh, oh yeah they did pop list

bright glacier
#

also, it appears they want two terminating newlines which ???

#

unless I'm missing something, I'm not sure what Black is doing wrong

#

anyway, I'm impressed that Alabaster has continued to be Sphinx's default theme in 2021.

#

My best guess at why they are confused is on Windows it's typical to see the terminating newline to be rendered as an empty line

#

Also, Visual Studio Code also renders the terminating newline as an empty line too IIRC

bright glacier
#

I'm doing some refactoring work on the code between main() and format_str() and I got a question. What's the reasoning behind getting the STDOUT buffer, wrapping it, and then writing directly to it? Encodings stuff?

bright glacier
#

@dense jungle I have my doubts I'll be beating you anytime soon (if ever) πŸ˜„

dense jungle
#

Just introduce some really buggy new feature and then fix them πŸ˜„

bright glacier
#

45 times ... (nah people who aren't familiar with the issue tracker are really bad at finding duplicates so it should only take a few horribly broken changes)

bright glacier
#

it's nothing be ashamed of, who else would vaguely remember hundreds of issues at once? ... maintainers of course!

plain atlas
bright glacier
#

hopefully the maintainer was having a good day ^^

plain atlas
#

i may have done it again on a different repo

#

sorry @tribal thistle

dense jungle
#

^ planning to merge that PR soon

#

then see if I can get psf/black#2278 closer

toxic stormBOT
bright glacier
dense jungle
#

sounds good

bright glacier
#

By the way, do we have a Jupyter user who could review ( ... or is that you Jelle? I've seen you use a Jupyter notebook IIRC)?

dense jungle
#

I don't use it

bright glacier
#

Ah, well, I don't either so hmm.

dense jungle
#

we do have some in our codebase, let me run the branch on them

bright glacier
#

so for some reason some jupyter tests fail when running the full test suite but then everything passes when only selecting the jupyter tests ...

#

I wonder if this is an actual issue or just something with my environment hmm

#
    def test_non_python_notebook() -> None:
>       with open(os.path.join("tests", "data", "non_python_notebook.ipynb"), "rb") as fd:
E       FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/non_python_notebook.ipynb'

/home/ichard26/programming/oss/black/tests/test_ipynb.py:306: FileNotFoundError
❯ find | grep "tests/data/non_python_notebook.ipynb"
./tests/data/non_python_notebook.ipynb
#

well that's totally not confusing πŸ™ƒ

#

I feel like I'm missing something real dumb, but this makes no sense AFAIK

#

so wait, apparently CWD is being modified somewhere, why not always is still beyond me

dense jungle
#
tests/test_black.py:            os.chdir(str(root))
tests/test_black.py:            os.chdir(str(old_cwd))
tests/test_black.py:                os.chdir("..")
tests/test_black.py:                os.chdir("tests")
bright glacier
#

whelp, is CI on github passing, would surprise if so

#

it probably is though since I've expected pushes

dense jungle
#

yes, it's all green

bright glacier
#

sigh

#

oh, the jupyter tests are only run standalone not with the rest of the test suite

dense jungle
#

I strongly suspect it's due to the os.chdir calls I flagged above

bright glacier
#

man the various optional test groups really make this confusing

dense jungle
#

we should use some sort of context manager that resets the cwd to where it came from after the test

bright glacier
dense jungle
#

do you know if unittest or pytest provides something like that?

bright glacier
#

not by heart, but it would surprise if pytest didn't come with something for that, lemme look

dense jungle
bright glacier
#

So we have the following optionals: no_python2, no_blackd, and now no_jupyter. I plan on adding a incompatible_with_mypyc marker ... gosh that's a lot. Good thing it appears no test is dependent on another one (that would've been real fun to debug).

bright glacier
dense jungle
#

sounds good, I'll send a PR

flat krakenBOT
bright glacier
#

Oh my that was fast.

#

well okay the lint job is failing πŸ˜›

dense jungle
#

not any more!

#

all green now πŸ™‚

bright glacier
#

can tell, I've been hovering over the GHA status πŸ˜‰

flat krakenBOT
bright glacier
#

Alright first initial lookover complete (I skimmed the jupyter specific code since I have no knowledge of jupyter).

#

Probably worth some more manual testing though (looks like you found a bug).

flat krakenBOT
bright glacier
#

I was going to check if the changes would break my mypyc work (was a little worried about the dataclasses inheriting ast.NodeVisitor) but it turns out there's a few merge conflicts in the parsing module from main already so I noped out πŸ™‚

stuck vapor
short forge
late dewBOT
#

src/black/__init__.py line 91

def read_pyproject_toml(```
short forge
#

nevermind, getting played by github, apparently ctrl+f works better than github's own lookup

late dewBOT
#

@bright glacier

It has arrived!

Here's your reminder: document docker tags.
[Jump back to when you created the reminder](#black-formatter message)

plain atlas
#

if i ever start to finish stuff I work on I'm kinda interested in what this would be like~

#

There is no official blackd client tool (yet!). You can test that blackd is working using curl:

bright glacier
#

apparently black is reponsible for over 12% of click's downloads 🀯

#

27% (i.e. largest dependant) of appdirs' πŸ˜…

#

55% of pathspec ... well okay damn

#

(it should be noted that this data 100% has issues, but even the possibility of black being *that* influential via what it depends on is a bit scary and crazy)

flat krakenBOT
flat krakenBOT
dense jungle
#

^ anyone using PyCharm who can confirm this change is correct?

tribal thistle
#

I remember setting up the integration when I first started contributing here, and didn't run into any problems

#

I'll do a more thorough test now though

plain atlas
#

huh

#

!pypi click

late dewBOT
plain atlas
#

oh what

tribal thistle
#

Yeah seems that change is indeed incorrect

flat krakenBOT
plain atlas
tribal thistle
#

Replying to the messages above

plain atlas
#

ah

#

(since its named click, but actually isn't a tui framework is a bit surprising imo)

tribal thistle
#

For those following along at home:
Path to my file was: "C:\Folder Name\file.py"

Running without the quotes netted: Error: Invalid value for 'SRC ...': Path 'C:\Folder' does not exist.

Running with quotes outputted regular black output

dense jungle
#

thanks @tribal thistle ! that's very useful

plain atlas
#

isn't that inhernet to terminals tho?

#

I've never had any path that didn't need "" around it if the path had a space

tribal thistle
#

It is expected behavior, so the quotes should probably be left in there

plain atlas
#

true

plain atlas
#

hmmmm

#

is there an "official" way to add black to ci?

#

Right now I am using black through pre-commit in the ci

tribal thistle
#

Well there’s an official precommit hook

#

That’s, pretty official

plain atlas
#

o

#

hm

#

maybe i should remove it from pre-commit

#

or run it seperately with different args

#

because if it would reformat a file i would rather it doesn't so flake8 can get to it and report on it

#

or wait no that's kinda dumb πŸ‘€

tribal thistle
#

It might make sense to use β€”check in that case

plain atlas
#

right

#

but

#

does it also make sense to use --check locally?

#

i feel like running it locally it makes sense to run the format

#

which would mean setting it up to be bypassed in the ci

tribal thistle
#

That depends on what you believe the hook should do. If it’s just meant as a fallback in case something gets missed before commiting, sure

plain atlas
#

and then after bypassing it in the ci, run it seperately

#

yeah

#

wait why am i using the repo as my hook in pre-commit when i can use local black

plain atlas
#

huh

plain atlas
#

oh no

#

@tribal thistle i regret my life choices right now

#

well no shit that workflow errored

#

when you scan all of the site packages, what do you think would happe

#

relevant because it was black

#

fixed

#

smh

#

finally

#

its done

#

mmm

#

i still might change that a little more haha

plain atlas
#

Update: fixed ci, but my commits weren't signed so now I have to fix it again

flat krakenBOT
#

Describe the bug

When formatting a *.py file with bracketed returns annotations the error below is returned:

error: cannot format test.py: INTERNAL ERROR: Black produced code that is not equivalent to the source on pass 1.  Please report a bug on https://github.com/psf/black/issues.  This diff might be helpful: /var/folders/9m/cps802s92k77tpy3z1w56hxr0000gn/T/blk_fu7q8w3k.log

To Reproduce

For example:
test.py

import typing

returning_a_deeply_nested_im...
flat krakenBOT
#

From @akaihola in #779:

In akaihola/darker#164 (comment) we noticed that format_str() gives different results for some files than running black from the command line or black.main(..., standalone_mode=False). This should probably be fixed before making format_str() an officially public Python API.

Consider this test script compare_black.py:

import io
import sys
from contextlib import redirect...
flat krakenBOT
#

Hello,

Not sure where the best place to ask this question is so I decided to file an issue. In my organization, we've been running black for a couple of months under python versions 3.7 and 3.8 in our CI and I've never noticed that the output is different between the two.

Is there any scenario where the code style between the python 3 versions will be different? I'm wondering if I should suggest that we only run black with python 3.8.

Thank you! I love using your package.

tribal thistle
#

I've run into a really weird situation testing the above issue

#

On a py37 install, I ran the following:

black -t py37 file.py

where file.py is:

if x := False:
    print("wot")

It errored out my first run, but then... it just worked for all subsequent runs. The content of the file on disk has not changed as far as I can tell.

#

Ok well... I managed to get it working again.

#

Having a newline at the end of the file causes it to work

#

not having it causes it to fail

neon loom
bright glacier
#

Also welcome back to the computerized part of the world πŸ™‚

neon loom
#

Cheers. It's nice to be clean again.

#

Rubicon Trail is no joke (for any off roaders in here) - I live 45 mins away from the Tahoe entry. So I had to check it off the list.

dense jungle
#

did you walk it? looks fun!

neon loom
#

Drove it with friends in their highly modified rock crawling Jeeps

bright glacier
#

That explains the many jeeps I saw in a quick google search for images πŸ˜„

neon loom
#

Spot the nerd controlling the drone … I bet you can’t guess who that is.

dense jungle
#

I bet it's not the guy who makes a Prometheus dashboard for his house

neon loom
#

Graph everything in your life.

flat krakenBOT
#

Fixes #2381.


This fixes a bug where a trailing comma would be added to a
parenthesized return type annotation changing its type to a tuple.
Here's one case where this bug shows up:

def spam() -> (
    this_is_a_long_type_annotation_which_should_NOT_get_a_trailing_comma
):
    pass

The root problem was that the type annotation was treated as if it was
a collection (is_body=True to linegen::bracket_split_build_line) where
a trailing comma is usually fine. ...

bright glacier
#

@dense jungle I can look into other syntax constructs where a trailing comma is dangerous but I am a bit busy so it will have to wait πŸ™‚

dense jungle
#

No problem! I can check too

bright glacier
#

Just managed to sneak a bugfix into my free time

dense jungle
#

In your code it just feels a bit ad hoc that we're checking specifically for return annotations, so that had me wondering if this could appear somewhere els

#

e

bright glacier
#

It seems unlikely given that code should only add a trailing comma to either imports or function parameters (according to the nearby comments)

#

I guess rolling up the check into the no_comma could be cleaner but I found its behaviour a bit confusing so hmm

#

I agree it does feel a bit ad-hoc (also technically that new variable's name is misleading)

#

I'll look into at least rolling the check up into no_comma, should make it a bit cleaner πŸ™‚ (unless there's more situations leading to the bug)

tired shard
#

Why does black have configuration for poetry, pipenv and tox(we could run tests with pipenv/poetry too, using tasks?)? Why not just one of them?

#

And the poetry configuration is faulty

plain atlas
tired shard
#

Oh nvm

#

the pyproject.toml is just a example configuration for those using black for there poetry packages

#

hypothesmith and hypothesis aren't included in the dev packages in pipfile? Was that just missed or?

tired shard
#

Weeee psf/black#2360

toxic stormBOT
tired shard
#

I had to check if the opt value was of type tuple then it would have been an argument, and if the value of the argument is empty i.e () then it wasn't passed inside

#

Felix, do you want the Error?

#

i don't think it is needed when you include black is furious lol

errant barn
#

Well that message suggestion was a bit tongue in cheek anyway πŸ˜… I'm not sure we should actually use it. But yeah I agree

#

The other maintainers haven't commented on the issue yet though, so this is by no means fully accepted

tired shard
#

it is a good messed lemon_pensive

errant barn
#

I appreciate you giving it a go though!

tired shard
#

Ah yes, i missed it doesn't have accepted label. Lemme know what other maintainers think below

flat krakenBOT
#

Describe the style change

Today with black, lists are either formatted as all elements on one single line, or all elements on a line each. Within the array, no room for alignment is allowed.
I think there are many cases where a middle ground makes more sense, where the data is more tabular or have other useful context. I have two examples where alignment would help readability of both 1D-lists and 2D tables/matrices.

Example 1 is a pattern we see a lot in our code base. From a re...

tired shard
bright glacier
silent apex
pure sable
#

pinned in my clipboard

bright glacier
#

Alright, let's see if I can find any then πŸ˜„

dense jungle
#

I thought that PR would make Black make those transformations which got me excited. But it's only making changes in Black's own source code πŸ˜„

bright glacier
#

seems to be someone just applying some tool to lots of repos looking at the user history

#

i'm not going to bother approving the CI, I don't see a good reason to merge the changes (perf or readability wise)

#

Whelp I managed to cause another crash via a more complicated return annotation

#

looks like I'll sadly have to add something more generic and less specific to detect when we're operating on a return annotation, y'know I would've have thought this would've been an easy quick fix to improve my AST mangling skills with but nope :D

stuck vapor
flat krakenBOT
#

Describe the bug
error when running per-commit on file black

error: cannot format /home/ayesha/Desktop/workSpace/benchmark-comparison/ev/lib/python3.9/site-packages/pandas/io/pickle.py: INTERNAL ERROR: Black produced code that is not equivalent to the source. Please report a bug on https://github.com/psf/black/issues. This diff might be helpful: /tmp/blk_2pyt3r5d.log
To Reproduce

Expected behavior

**Environment (please complete the following information):*...

bright glacier
#

very useful bug report ^^ /s

#

actually I take that back because they're formatting a Library in a virtual environment

#

This won't be the easiest thing to reproduce but it might be possible

frigid coyote
#

Hello Everyone, I am a newbie to Open Source and have some experience in contributing to the documentation but when it comes to fixing issues and code contributions I am unable to perform. Like I don't understand what the issue is and its terminology can anyone help me?

errant barn
#

Are you thinking about something specific to Black?

flat krakenBOT
#

Describe the bug

We found two test failures when building with nix on OSX ( https://github.com/NixOS/nixpkgs/pull/130785 ).

Wondering if anyone has an idea of what could be causing this based on the output of the test failures.

To Reproduce
Happens on certain (but not all) darwin systems. Assuming the nix package manager is installed the following will build the package and run the tests

nix-build --check "" -A python3.pkgs.black

Expected behavior

Te...

tribal thistle
#

Would be helpful if they shared what tests are actually failing πŸ˜›

#

Oh they shared the PR

#

sweet

solid adder
tribal thistle
#

I might be missing something, but wont the stable version of docs show the latest version at time of release

#

I.E 6b

#

Latest shows 7

flat krakenBOT
#

Describe the bug

Traceback (most recent call last):
  File "C:\python\conda\envs\clone\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\python\conda\envs\clone\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\python\conda\envs\clone\Scripts\black.exe\__main__.py", line 7, in 
  File "C:\python\conda\envs\clone\lib\site-packages\black\__init__.py", line 1130, in patched_main
    main()
  File "C:\python\cond...
frigid coyote
bright glacier
#

!remind 2H move the stable tag since there hasn't been a fire πŸ”₯

late dewBOT
#
You got it!

Your reminder will arrive <t:1626884735:R>!

stuck vapor
late dewBOT
#

@bright glacier

It has arrived!

Here's your reminder: move the stable tag since there hasn't been a fire πŸ”₯.
[Jump back to when you created the reminder](#black-formatter message)

bright glacier
#

@dense jungle any objection to moving the stable tag? There's a regression report but it's due to a buggy old pathspec release being installed (not sure how they tested 21.7b0 since that version (or before IDR well) the pathspec minimum requirement to avoid this issue but oh well)

dense jungle
#

go for it

bright glacier
#

Sounds good then

#

I still don't understand why RTD doesn't pick up the stable movement the first time around (I have to request another job after the first one triggered by the tag update) but everything should be fine now πŸ˜„

errant barn
#

I feel like we've discussed this already, but I don't quite remember: why are the stable RTD builds not set to happen on every release?

#

Meaning on every tag, rather than on "stable"

lament crow
#

It's because black is not stable

#

RTD doesn't build betas as stable

frigid coyote
tribal thistle
#

It’s okay to ask for help as you work through the issues. Others can help get you familiarized with the code base, and push you over any initial hump

mint barn
#

Is black the best formatter

errant barn
#

100 %

errant barn
#

It's the kind of tool that makes it possible for you to not worry about how you write your code. Black doesn't change the logic, only the look, so that this:

def foo(a, counter=0,con=None, close=lambda x:x.close(),write=lambda x,s:x.write(s),n=lambda a=0,b=0,c=0:0):((foo,n)[counter](a, 1, (open,n)[counter](a + '.txt', 'wt')),((n,write)[counter](con, str(a)),(n,close)[counter](con)))

becomes

def foo(
    a,
    counter=0,
    con=None,
    close=lambda x: x.close(),
    write=lambda x, s: x.write(s),
    n=lambda a=0, b=0, c=0: 0,
):
    (
        (foo, n)[counter](a, 1, (open, n)[counter](a + ".txt", "wt")),
        ((n, write)[counter](con, str(a)), (n, close)[counter](con)),
    )
#

That'd be a trailing comma, aimed to minimise diffs. For example, when you add items at the end of lists or new function arguments, this way you don't have to add the comma to the previous line

flat krakenBOT
#

Is your feature request related to a problem? Please describe.

Having to run isort is an additional step when formatting code.

Describe the solution you'd like

Black sorts imports (similar to isort) and removes unused.

Additional context

Black is great, just an idea to make it better.

tribal thistle
#

Can you actually implement removal of unused imports without doing some static analysis

#

Hmm maybe just a blind search

dense jungle
#

not completely safely in the presence of globals() and side-effecting imports

flat krakenBOT
tribal thistle
#

I considered side effects, but most of the time I handle those with noqas anyways lol

stuck vapor
#

is sorting imports still being considered by black? if not, then just out of interest, why not close the dupe issue?

dense jungle
#

I would kind of like to see it, but it's not likely to happen anytime soon

#

I would like to have a tool that knows to do all kinds of safe or probably safe source transformations. That could also include import sorting, simple type annotations like https://github.com/JelleZijlstra/autotyper, cleaning up some comprehensions, etc. I don't like having to remember tons of different tools to do these things

flat krakenBOT
#

Describe the bug

Running :Black in a fresh install of Neovim (via Homebrew), with black installed via vim-plug, results in the following error:

Error detected while processing function provider#python3#Call:
line   18:
Error invoking 'python_execute' on channel 3 (python3-script-host):
Traceback (most recent call last):
  File "", line 97, in 
ModuleNotFoundError: No module named 'black'
Error detected while processing function black#Black[1]..provider#python3#Call
...
bright glacier
#

Yeahhhh at that point I would leave it alone (presumably option one) and try to never ever have to maintain or touch it ... ever!

errant barn
#

Yea fair, just an example of reasonably complex formatting!

red sedge
# flat kraken

@bright glacier probably worth doing pyupgrade --py36-plus on black rather than hacking away at the old style line by line

stuck vapor
red sedge
#

I don't think large automated code formatting changes are appreciated in black ;)

stuck vapor
flat krakenBOT
#

Before

foo = "foo"
bar = "bar"
msg = (
    f"This is a fake message containing {foo} "
    f"and {bar}"
)

After

foo = "foo"
bar = "bar"
msg = f"This is a fake message containing {foo} " f"and {bar}"

which apparently is indeed valid Python, but preferably the two pieces would be combined into a single string literal.

Python: 3.8.7
Black: 21.7b0

bright glacier
#

What issues are blocking us from flipping the switch on ESP again? I am failing to remember everything again πŸ™‚

#

I know of performance issues but are there crashes too?

dense jungle
#

I think only the performance one

#

I believe all the crashes were fixed

#

The known ones at least πŸ˜„

bright glacier
#

There's no bugs if you don't know of them πŸ˜‰

#

did we ever resolve sqlalchemy's apparent crash with esp?

#

I just took a look at primer.json

#

I bet there's an issue somewhere about it, need to find it

dense jungle
#

found it with discord search, pretty nice

bright glacier
#

I'mma quickly run main black over sqlalchemy locally with ESP

#

if it passes, I'll add ESP to primer.json

#

sadly there's no way to select a specific project from the black-primer cli, but doing its job manually is quite easy πŸ˜„

#

What were the results of your duration branch Jelle?

#

I got reminded of it watching black slowly format sqlalchemy

dense jungle
#

Nothing too interesting I think. A lot of variation in lines/s timing.

bright glacier
#

Fair enough, what was the max and min values πŸ˜„ ?

#
Oh no! πŸ’₯ πŸ’” πŸ’₯
411 files would be reformatted, 177 files would be left unchanged.
dense jungle
#

can't tell because the state of the repo changed 😦 my LOC counter fails because some files were deleted. I'd have to rerun the whole thing

drowsy sonnet
#

Hallo folks!

bright glacier
#

Oh that's unfortunate, no worry then! Was just curious if you still remembered numbers.

drowsy sonnet
#

As @bright glacier likely noticed, I'm reformating pip's codebase with black. Is this a good place to ask "why would black do this!?" questions? :)

dense jungle
#

sure!

bright glacier
#

Yeah sure, and the answer to your "is ESP safe?" question is that as far as we know, other than performance issues, it's fine. Black is run over quite a few big projects in CI with ESP enabled and there's no crashes (up in the history you can see us figuring that out - and me testing the last crashing project).

dense jungle
#

and the performance issue seems to manifest when you have extremely long logical lines (e.g., enormous list/dict literals). not sure if pip has any of those

drowsy sonnet
#

(also, yes, the input isn't exactly nicely formatted)

errant barn
#

Yes, that's a quite highly-discussed aspect of our formatting!

bright glacier
#

IMO the way black handles any complicated collection literal is ugly, but I don't make these design decisions here πŸ˜›

dense jungle
#

sorry what part of the diff is that referring to?

bright glacier
#

I have no idea, trying to figure it out.

errant barn
#

Lemme try to find the issues πŸ˜…

drowsy sonnet
dense jungle
#

but yes that sounds like the long-running complaint about how black splits lines πŸ™‚

drowsy sonnet
dense jungle
#

It doesn't for me. I think the hash may be double-encoded or something?

drowsy sonnet
#

Here's a screenshot!

bright glacier
#

What does work is if you go into view file from the diff screen and then select your lines IIRC.

#

Some PyDis bot will also catch that and present it nicely

dense jungle
errant barn
#

There's psf/black#2156, which has lots of references to other issues!

toxic stormBOT
bright glacier
#

And is unfortunately extremely disruptive

drowsy sonnet
#

To be clear, my goal ain't to rehash extended past discussions here. Basically, if it's stuff I can help with or if it is something new, I'd be more than happy that I asked here.

bright glacier
drowsy sonnet
dense jungle
#

I think the summary is that it's something that it's often complained about and we have sympathy for the complaints, but it's hard for us to change existing formatting decisions at this point

drowsy sonnet
#

Yup yup, totally understand that! :)

bright glacier
#

but I doubt we'll actually accept it

#

it's been ignored, so yeah, not looking good for it πŸ™‚

errant barn
#

Yeah, I think the problem is far deper than that

#

Since there's a boatload of losely related issues with the "2 items not formatted but 3 are" theme

drowsy sonnet
bright glacier
#

IIRC ambv said if we could redo this, we would just stop touching parentheses so much since they're too painful work with.

drowsy sonnet
#

Is there any chance that black can get a special case for re-indenting textwrap.dedent(<multiline string>)?

bright glacier
#

seems reasonable to me, but Jelle didn't like it for some edge case?

#

also it's another pr that needs a lot more attention sadly

drowsy sonnet
#

Hmm... That looks like something I can pick up and drive to completion actually.

bright glacier
#

Heh, I was going to say I would be fine doing that myself (although as usual I have like 4 different things on the go at once)

#

I bet you do too πŸ˜›

dense jungle
#

you mean that it would modify the string itself?

drowsy sonnet
#

Screenshot, to make it easier to see here (what black gave me vs what I want)!

drowsy sonnet
dense jungle
#

yes that makes me uneasy πŸ˜„

#

like we'd have to detect the function being textwrap.dedent, but what if it's aliased?

bright glacier
#

Don't support it I guess?

drowsy sonnet
lament crow
#

it's not ast safe

dense jungle
#

Sorry I mean the other way around: what if I have a totally different function that just happens to be called textwrap.dedent in the source?

lament crow
#

what if someone overwrites textwrap

drowsy sonnet
dense jungle
#

And yes, it's an AST modification so it would affect our safety guarantee

bright glacier
#

Yeah, it would require hacking on the AST safety check, not sure how fun that would be be.

drowsy sonnet
#

Yea.

dense jungle
#

A more general idea here could be a sort of plugin system that modifies certain strings. For example, this could be used to format embedded SQL or GraphQL strings.

bright glacier
#

That sounds like way too much work Jelle :p

drowsy sonnet
drowsy sonnet
lament crow
#

no but that wasn't really my point

drowsy sonnet
#

What is your point then?

dense jungle
#

It's more about the principle for me, though to be fair we do already make some AST-unsafe changes. The safety check is one of Black's main unique selling points

lament crow
#

other than the docstrings, black doesn't do anything that can affect what the code does

#

(to my knowledge)

#

and there's already been people mad about the docstrings :)

bright glacier
dense jungle
#

There's the del thing that changes the AST but not the meaning of the code

drowsy sonnet
#

"what if people do something that they don't?" is NOT a good argument. "we'd need to relax our AST promise further" is.

dense jungle
#

@drowsy sonnet what I'm worried about is people thinking "I can't safely apply Black to my codebase, because it may change the meaning of my code"

drowsy sonnet
#

Yup yup. I get that.

#

I was involved in the whole discussion that happened after the docstring formatting stuff. :)

#

(it's almost as if you quoted people from that thread lol)

dense jungle
#

I guess that thread made a deep impression on me πŸ™‚

drowsy sonnet
bright glacier
#

Do we special case like the case that's being suggested right now? (I know they don't involve touching the AST checks, but I wanna see what precedent there is, if there's any).

#

It seems unlikely we've special case-ed based off names

dense jungle
#

No, we haven't

errant barn
# drowsy sonnet Here's a screenshot!

And to go back a bit. Honestly, wrt. all the two-item splits and parens, I still think our style would be so much better if it was implemented. But since disruptiveness is a big concern (as it should TBF), the whole argument is kinda stuck. Which is really sad to me, especially because everyone seems to agree that it's the better style πŸ˜…

lament crow
#

you would have to analyze the scopes

#

and then there's things like people doing dynamic stuff with the global namespace

dense jungle
#

Yeah, probably we'd rely on textwrap.dedent with a single string argument just being the standard library function with behavior we understand. Which is probably true, but it's not safe in general

bright glacier
drowsy sonnet
#

And, it's easy enough to say "no, that's not supported".

red sedge
#

I have a from package.compat import textwrap

#

And that textwrap.dedent passes on the b" or u"

drowsy sonnet
red sedge
#

Yes only changed for b"..."

dense jungle
#

That one would be fine I think if we implemented what @drowsy sonnet wants, Black would just ignore anything that's not a single string argument

drowsy sonnet
#

ANYWAY, taking a step back -- my goal here isn't to convince folks that this is a good idea -- I mostly wanna see how folks feel about these things and if there is stuff I can help with. :)

drowsy sonnet
bright glacier
#

The summary is that "while we do want to make changes, we're kinda chained by things we promised in the past - and we're not sure whether we want to change those promises"

#

as usual πŸ™‚

dense jungle
#

Not that that completely stopped us in the past πŸ™‚

red sedge
#

I've got used to it now

dense jungle
#

But it raises the bar for when we want to accept changes that affect existing formatting

errant barn
bright glacier
#

To a lot of people, the beta markers means nothing now

red sedge
#

My only concern is running new black on projects without new black configured

drowsy sonnet
#

Honestly, if you're thinking of maintaining those promises indefinitely, I'd say it is time to drop the .bN from your releases.

red sedge
#

Eg they're not running pre-commit with the autoupdate bot

drowsy sonnet
#

Because then you CAN use the versions to mean something.

dense jungle
#

Yeah I don't think the b makes much sense. But now dropping it becomes a big deal πŸ™‚

red sedge
#

Make it a

drowsy sonnet
#

(although, adopting CalVer means you probably wanna tie it to the annual cycle to not break semver-y expectations)

bright glacier
#

Currently the goal post for stable is getting ESP by default landed, but we're scared to be honest

dense jungle
#

I think the b just stands for Black now. We make our own versioning scheme

red sedge
#

rc good btw

dense jungle
#

More seriously I'm not sure the versioning scheme really affects what happens in practice (except that the b causes issues for some tools that treat pre-releases differently). We already see that people use Black in tons and tons of projects, and complain if we change behavior. I don't think that would be very different if we didn't have the b.

drowsy sonnet
#

Right, then it makes sense to just drop it. It's basically the same as 0ver, but with a beta tag because black adopted CalVer.

errant barn
bright glacier
#

We both have people thinking it allows us to make disruptive changes and people who completely ignore its existence, I think (opinion) the majority is the latter camp at this point

dense jungle
red sedge
drowsy sonnet
#

Hmm... I wouldn't consider dropping the beta tag to mean "complete".

#

It's clarifying what promises you make.

drowsy sonnet
#

If the trouble is that you're too constrained by the promises made in the past and that's hurting the project's evolution and users now ("we want it, but can't change now") -- then maybe what you need is to do some expectation management.

red sedge
#

Is the plan to release final before peg?

drowsy sonnet
#

pip had to do that, and that's how why we had to switch to calver and got a 6-months-of-warnings deprecation policy.

errant barn
#

What did you do exactly? I'm not sure how to relate deprecations to formatting changes lemon_thinking

bright glacier
#

The main argument I have against Black changing formatting between releases is that a fair bit of people don't pin black (or in general but that's a packaging rant)

dense jungle
errant barn
bright glacier
#

I guess we could argue that you should pin black or "you're on your own" ...

dense jungle
#

Yeah we get all those issues where people complain about Black formatting things inconsistently and it invariably turns out they're using different versions

bright glacier
#

Probably, it's hard to announce that to the userbase though,

red sedge
#

People need to enable Pinning and autoupdating

errant barn
#

Witnessing the docutils 0.17 break with sphinx wasn't fun either

red sedge
#

Otherwise I have to check which shade of black I'm using every time I contribute to a new project

errant barn
solar widget
#

is guido against black

bright glacier
#

p.s. @drowsy sonnet thanks for sparking up this conversation, I would imagine some sort of more defined policy of how formatting changes are gauged instead of gut feeling and maintainer consensus would make this situation way better!

drowsy sonnet
red sedge
#

pip's so much better now

bright glacier
drowsy sonnet
bright glacier
#

The veto power was basically ambv, and I guess still is, but he's pretty inactive so ???

solar widget
errant barn
#

Perhaps just personal preference

bright glacier
#

There's enough twitter threads on the topic, and we're likely to be biased πŸ˜‰

#

It basically ranges from "I don't like losing control to I hate the sad face"

dense jungle
errant barn
bright glacier
#

people depend on e v e r y t h i n g remotely exposed

errant barn
#

Hopefully we can learn from that

bright glacier
#

there's a ton of stackoverflow answers with people digging in pip's internal

drowsy sonnet
#

:)

#

Hyrum's Law

An observation on Software Engineering
Put succinctly, the observation is this:

With a sufficient number of users of an API,
it does not matter what you promise in the contract:
all observable behaviors of your system
will be depended on by somebody.

bright glacier
#

wish it didn't exist

red sedge
#

Might be nice to have one of these

errant barn
#

Law X+1: there's a law for everything

bright glacier
#

Indeed, sad reality.

drowsy sonnet
errant barn
#

I can imagine..

drowsy sonnet
#

Once a tool is popular enough, you will have someone somewhere complaining about everything. Even good things.

bright glacier
#

One thing is that y'all have auto locking on your issue threads, does that help here? Not saying we'll adopt it but it sounds like it could bring useful perspective

flat krakenBOT
#

We're often hesitant to change formatting now, even though technically we're still in beta (#517). Some questions we should document the answer to:

  • When does Black accept formatting changes? How is the decision to change formatting made?
  • What are the guarantees Black wants to continue making? When will we make exceptions to the AST safety guarantee?
  • As a user, what should I expect when upgrading to a new version of Black?
  • How will this change when we have a "stable" release? Wil...
errant barn
bright glacier
#

(although stopping people from complaining sounds impossible)

#

sorry, I meant "unnecessarily unproductively complaining"

drowsy sonnet
#

:)

red sedge
#

What about if you made a whole brand new parser with its own AST

bright glacier
#

someone is going to quote me and call me an unreasonable maintainer

red sedge
#

And guaranteed that AST compatibility

#

Rather then pinning to cPython ast

drowsy sonnet
#

Yea, the balance you gotta hit is "what is unproductive complaining" vs "what is a genuine problem".

solar widget
#

is this the right place to post a glowing review of black?

red sedge
#

But also people use multiple tools

drowsy sonnet
#

100% a good idea to tell the maintainers that you like the thing they're working on. :)

solar widget
#

black is the only reason why I haven't ripped off the heads of devs who use inconsistent indentation

red sedge
#

black has saved me so much time effort and heartache!

errant barn
#

LOL

solar widget
#

you've made the world a better place

bright glacier
dense jungle
#

Yes, I would prefer not to have our own parser

solar widget
#

we live in peace, and there are no wars in the office where I am at

#

there you go!

bright glacier
#

wait until one of your new hires hates black

red sedge
#

All the people who apposed black quit to work at banks :(

red sedge
#

We've had candidates ask if we use black

solar widget
bright glacier
#

... as if they will decline / accept based off its usage?????

errant barn
#

Slightly off road: the thought of making a target test suite for us has crossed my mind. A bit idealistic? Yes, but I thought that could help in planning and communicating upcoming changes.

drowsy sonnet
bright glacier
#

I do technically have access to the RTD stats, but I'm too lazy to check

#

It would help with planning though

errant barn
#

Yeah those are absolutely fine! I just doubt how much raw code we can fit in there πŸ˜… but I'm glad you at least like it on some level

bright glacier
#

From watching some of the rollout of pip's new resolver, it's like impossible to be good at communicating changes

drowsy sonnet
errant barn
bright glacier
errant barn
#

Seriously though, like a failing test suite that would be the ideal formatting behavior

drowsy sonnet
errant barn
#

πŸ–‹οΈ πŸ“°

drowsy sonnet
errant barn
drowsy sonnet
#

That said, getting a bunch of major + large OSS projects onboard to use as a smoke test sounds like be a good idea to me!

dense jungle
red sedge
errant barn
#

Pin the issue as well?

#

"I suck at coming up with names" :D

bright glacier
bright glacier
drowsy sonnet
#

:P

errant barn
dense jungle
#

Yeah, I'd like black-primer to work like mypy-primer where it posts a comment with changes that would be made by a PR

bright glacier
#

I guess my "improving contributing experience" issue can be unpinned

dense jungle
errant barn
#

Fair enough

#

Have a "policy" tag? nah, not likely to be many policy issues after these are hashed out

bright glacier
#

I'll replace my contributing focused issue with the "Define a stability policy #2394", it's IMO way more important

drowsy sonnet
#

OH WAIT.