#black-formatter

1 messages · Page 21 of 1

neon loom
#

*bit

bright glacier
#

sorry, it's a trait of mine

dense jungle
#

It's something with ESP I think?

neon loom
#

Possibly

bright glacier
#

Anyway everything's going alright?

dense jungle
#

no pitchforks for me yet

bright glacier
#

Phew

neon loom
#

It’s good to have ya’ll release to find things I take for granted etc.

noble field
#

@GitHub#0000

silent apex
noble field
neon loom
dense jungle
#

great! I'll just close my PR

plain atlas
#

lmao

#

I don't know why, but I find this funny

#

fixed bugbear instead.

#

imagine running enough of the python ecosystem where you can just pick which project to fix

neon loom
#

I'd love more maintainers for bugbear

#

I basically solo maintain it these days - But get good PRs from people still :d

plain atlas
#

nice

#

!pypi flake8-bugbear

late dewBOT
#

A plugin for flake8 finding likely bugs and design problems in your program. Contains warnings that don't belong in pyflakes and pycodestyle.

plain atlas
#

I copied my flake8 plugins from a different project when I set up my env so they were there and on my pre-commit

#

I love B001

#

thank you for maintaining it

#

Actually just noticed that a lot of my code has been caught by bugbear

neon loom
#

@solid adder started it

plain atlas
#

Ah, nice!

#

Yeah I apparently have been saved by it a lot :))

#

ugh

#

fuck this project

#

gimme a few minutes, I need to test something

#

I really wish it used spaces instead of tabs

#

.....

#

holy

#

UH

#

tldr I hate this project's formatting.

#

9726 flake8 problems

#

most of them W191

#

running black bumps it down to 2276 problems

dense mist
mint barn
#

Why

stuck vapor
#

yes, it's valid - you can use additional_dependencies for local hooks

red sedge
#

also it seems to be missing from stable

dense jungle
#

we haven't updated stable yet, will do it later today

late dewBOT
#
It has arrived!

Here's your reminder: check release status + finalize release process
[Jump back to when you created the reminder](#black-formatter message)

dense jungle
#

going to move the stable tag now

#

done

#

hm RTD didn't update. couldn't find the place to do it in the admin UI

bright glacier
heavy heron
#

It isn't building on push?

plain atlas
bright glacier
#

yup and RTD gets confused and rebuilds stable .. using the old stable revision

#

an additional rebuild clears out the issue and RTD then notices the right commit but yea it's weird

hard gale
#

Hey all - I just started using black and felt the diff below was a little strange and was hoping someone might be able to provide some clarity, particularly as the suggested change is far longer than 88 characters and doesn't join the strings. Is this expected? If I set the line length to 80 this change isn't suggested

-        print(
-            f"Found {len(self.selected_str)} strings with a "
-            f"minimum hamming distance of {self._min_dist}"
-        )
+        print(f"Found {len(self.selected_str)} strings with a " f"minimum hamming distance of {self._min_dist}")

edit: if I set --line-length 88 the change isn't suggested either?

dense jungle
hard gale
dense jungle
hard gale
heavy heron
#

Could you perhaps trigger a rebuild using the API rather than doing it manually?

plain atlas
#

...

#

they have a python example even

#
import requests
URL = 'https://readthedocs.org/api/v3/projects/black/versions/stable/builds/'
TOKEN = '<token>'
HEADERS = {'Authorization': f'token {TOKEN}'}
response = requests.post(URL, headers=HEADERS)
print(response.json())
heavy heron
#
echo $RTD_TOKEN | python -c 'exit(0 if __import__("requests").post("https://readthedocs.org/api/v3/projects/black/versions/stable/builds", headers={"Authorization": f"token {input()}"}).ok else 1)'
```Here is a more CI friendly version :D
plain atlas
#

ah, perfect lol

short forge
#

Finally remembered to try this, it does work
experimental-string-processing = true

amber karma
#

Man I finally got around to setting up black to run on file save on pycharm

#

🤤 So nice

flat krakenBOT
#

Describe the bug

Returning a tuple containing star operator without enclosing with parentheses leads to a Cannot parse error.

Oh no! 💥 💔 💥

To Reproduce

def apply_to_last(input, func):
    *header, last = input
    return *header, func(last)

# which is valid code doing this:
assert apply_to_last([1,2,3], lambda x: x+10) == (1, 2, 13)

And try to blackify...

Expected behavior

I expect it to not choke.

There is a workaround -- enclosi...

dark orbit
#

TIL return *header, func(last) is valid python

obsidian granite
#

(not much to say here but I've used Black for ~3 years and I want to say a big thank you to all contributors. Terrific formatter.)

tawny bluff
tribal thistle
#

You can enable it there, or via cli using the --experimental-string-processing option

flat krakenBOT
short forge
tawny bluff
#

It works perfectly fine, Thank you 🙂

flat krakenBOT
#

Describe the style change

For a function with no args, magic trailing comma lets us control how the return type looks.

However, if we add an arg, the magic trailing comma is ignored, and the return type stays on one huge line.
Instead, it should be split across lines.

Examples in the current Black style

Consider the case of --line-length 120. Length is not a factor here; in all cases, the entire definition could fit on one line.

With no arguments to def fn(), ...

flat krakenBOT
#

Describe the bug

To Reproduce

Expected behavior

Environment (please complete the following information):

  • Version:
  • OS and Python version:

Does this bug also happen on main?

<!-- To answer this, you have two options:

  1. Use the online formatter at , which will use
    the latest main branch.
  2. Or run Black on your machine:
    • create a new virtualenv (make sure it's the same Python version);
    • clone this repository;
    • run...
analog bluff
#

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte any ideas why this is happening?

dense jungle
#

Just replied on the issue

analog bluff
#

.gitnore is just venv

#

:/

analog bluff
dense jungle
#

Try debugging it. Maybe print out which file it's trying to read

analog bluff
#

kk

dense jungle
#

Once we know more we can make a change to Black to make the error more informative

analog bluff
#

i think its cause its using utf-8 characters ie emojis and its not sure about it

austere lava
#

does anyone work with Python 3.9 while developing black?

#

I can't get pipenv install to run cleanly because of dataclasses

austere lava
bright glacier
#

I've been trying to fix it but I hate pipenv to no end

#

I'll try a few more relocks but I honestly don't know how to fix it

austere lava
#

oh man this really is painful

#

i tried removing aiohttp-cors but now my Pipfile.lock is full of windows-specific dependencies

#
src\blackd\middlewares.py:1:1: error: Module "__future__" has no attribute "annotations"

Thanks, mypy

flat krakenBOT
austere lava
#

Did we recently update flake8? I got some B904 errors on my PR (I fixed the one in blackd/__init__.py)

#
  • seems like coveralls upload is busted
bright glacier
#

whelp 🙃

bright glacier
#

... that expanded / added B904?

plain atlas
#

uh

#

cooper is a maintainer iirc

#

yeah, cooper is the maintainer

bright glacier
#

OK, coveralls is properly broken.

plain atlas
#

and it has not been updated since that message, at least

#

@austere lava

bright glacier
#

Maybe the cache got evicted and now we are just pulling down 21.9.1?

late dewBOT
#

.pre-commit-config.yaml lines 23 to 27

- repo: https://gitlab.com/pycqa/flake8
  rev: 3.9.2
  hooks:
    - id: flake8
      additional_dependencies: [flake8-bugbear]```
plain atlas
#

its not pinned and it was installed in that pr

bright glacier
#

I know

#

We don't pin the flake8-bugbear version in .pre-commit-config.yaml as it would have to be updated manually so I guess a new version was released recently?

plain atlas
#

at least 4 days ago it was cached still

bright glacier
plain atlas
#

yeah

#

ooh nice pr 2500

#

uh, how do i set up an environment for black--where's the contrib guide

#

nvm found it

bright glacier
#

Ugh, so maintenance-y stuff that is broken include:

  • linting via flake8-bugbear
  • development environment setup on 3.8+ due to the dataclasses backport
  • coveralls
  • probably more...
plain atlas
#

pipenv 🤢

bright glacier
#

FWIW, the development docs are pretty outdated and lacking

plain atlas
#

lol

tribal thistle
#

Hey Richard, I can try to help with the pipenv issues if you have time to share what’s happening on your system

plain atlas
#

...

bright glacier
plain atlas
#

fuck this is gonna take a little longer than I thought be pipenv is stupid and made my venv using 3.10.0rc2

tribal thistle
#

Time to revive the poetry branch? 😄

bright glacier
#

I mean some of the stuff is pretty reasonable like OS, but why a unrelated virtual environment when I'm already in another one?

plain atlas
#

okay, remaking the venv with 3.8.12 now

lament crow
#

yeah, you should have flake8-bugbear pinned same as with the main pre-commit hooks to have proper reproducible builds

#

and also because pre-commit won't reinstall

bright glacier
#

Personally I would just go pure Nox and get rid of pipenv / peotry but that's just my opinion 🤷‍♂️

plain atlas
#

nox?

tribal thistle
#

I’ve seen bug reports on pydis projects for both poetry and pipenv, but at least poetry is faster.

Broken faster

plain atlas
#

I mean, pdm is a new option too

#

!pypi pdm

late dewBOT
plain atlas
#

PDM is meant to be a next generation Python package management tool. It was originally built for personal use. If you feel you are going well with Pipenv or Poetry and don't want to introduce another package manager, just stick to it. But if you are missing something that is not present in those tools, you can probably find some goodness in pdm.

bright glacier
plain atlas
#

!pypi nox

late dewBOT
plain atlas
#

uh?

bright glacier
#

Here's my nox setup for blackbench

lament crow
#

I heard tox 4 will allow configuration through py files

plain atlas
bright glacier
#

Half of the Noxfile.py is just release crap, it's a personal project so why not do some experimenting and see how much I like strong release automation ^^

bright glacier
plain atlas
#

okay

#

after a local check

#

I can confirm that 21.4.3 of bugbear did not show that, and 21.9.1 does

#

with all of them being in either linegen or init.py

bright glacier
#

The problem with pinning flake8-bugbear is that pre-commit autoupgrade won't actually bump it, but I guess pinning it is still worth it even if mildly annoying.

plain atlas
#

i mean

#

not pinning it means that pre-commit autoupdate won't upgrade it either, it'll just upgrade whenever 😛

#

however, its probably worth actually fixing these suggestions than ignoring them

late dewBOT
#

src/black/__init__.py lines 947 to 950

try:
    masked_src, replacements = mask_cell(src_without_trailing_semicolon)
except SyntaxError:
    raise NothingChanged```
plain atlas
#

could be raise NothingChanged from None

#

¯_(ツ)_/¯

austere lava
#

yeah all lint warnings should just be changed to from None

#

I'll do that

flat krakenBOT
austere lava
#

it's been down for like 16h by now

#

emergency database maintenance to avoid transaction wraparound

🙂 kudos to them for noticing before the actual outage started happening

plain atlas
austere lava
#

I'm guessing integer overflow

plain atlas
#

ah

bright glacier
#

can anyone who is more knowledgeable than me with pre-commit quickly check this isn't stupid? psf/black#2481? I highly recommend reading the linked issue FYI.

toxic stormBOT
bright glacier
#

Where do we use pytest-cases in the test suite? I'm currently removing parametrized and I'm wondering if I can remove any other testing dependencies.

gilded mauve
stuck vapor
gilded mauve
#

Hmm.. could well be an issue that's never shown itself through setups I'm familiar with. Suggesting it doesn't seem to have ill effects.

stuck vapor
gilded mauve
#

My pain meds are making me more rooDerp that usual. If there is a breaking condition to avoid, then being strict on the python version at the upstream level makes sense and the end-user can/should understand they need one more line of config if they want more control.
If the only reason is to avoid running on python2, then I don't think it's needed at all. Not in the current setup of the tools involved, at least.

Again, this is me struggling to see the whole picture but not willing to just ghost the conversation.

#

The hook has worked brilliantly for me, going on a year now of using it in all my projects personal and work related. "If it isn't broke" says no change is needed to me. darkoLUL Exhaustion of being defensive around py2 and just wanting it to die says to nuke the line.

gilded mauve
austere lava
#

re Pipfile.lock, I'm more and more convinced we shouldn't check this in

#

it's supposed to make sure people's development environment is the same, but it hinders the development experience more than it helps

dense jungle
#

confession: I have never used pipenv in years of working on black

austere lava
#

pipenv install outright fails on anything > 3.6, or god forbid Windows

dense jungle
#

I just pip install -e in some venv

plain atlas
austere lava
#

well I can't get it to work on a completely fresh 3.7.12 or 3.9.4, it fails to install dataclasses

bright glacier
#

the only way I've *sometimes* gotten pipenv to behave in an OK manner was to do a clean clone (cause any extra files or directories could cause issues), use a python 3.6 virtual environment and maybe clear some caches ... on Linux mind you.

#

We should probably move to something else. I'm not keen on poetry but it sounds like it's mature enough?

#

Honestly I'd prefer a pip-compile + Nox setup over this current one. unfortunately pip-compile doesn't actually have a proper resolver so its lockfile generation is probably worse in terms of cross-platform compatibility. TBF I haven't used poetry nor pip-tools at all so this is just a comment on their scope and general functions.

silent apex
#

I've used poetry without any problems personally

#

I liked it a lot more than pipenv, and it's much faster

bright glacier
#

wish me good luck :)

tribal thistle
#

If you’re willing to take the hit on the big diff, deleting the lock file and relooking usually produces a cleaner result (and is way quicker 🤡)

bright glacier
#

I really don't like the "upgrade the world" feature of that :p

austere lava
#

do we depend on that pipfile lock for anything? CI?

bright glacier
#

no, just for developers locally

austere lava
#

then 🙂 ¯_(ツ)_/¯

red sedge
plain atlas
#

welp

#

ty MarcoGorelli

#

for the local pre-commit hooks since they're well done 🙂

heavy heron
# austere lava `pipenv install` outright fails on anything > 3.6, or _god forbid_ Windows

That is a supidely late reply, but the way pipenv is made it will fail on every single python version except the one you used to lock. So if you have a 3.9 lock file, it will fail on 3.8. If you find yourself needing that, I'd say pipenv isn't the right tool for the job. I am not 100% sure, but I believe poetry doesn't mind that? Flit would also be an option but it is pretty barebone.

plain atlas
#

IMO, change late reply to design choice

#

"this is a stupid design choice...."

plain atlas
tribal thistle
heavy heron
#

Huh, I don't know, I remember it breaking on windows too

tribal thistle
# heavy heron Huh, I don't know, I remember it breaking on windows too

Besides the existing dataclasses issue, I did the following and none of it failed:

  1. Created an environment using 3.9 on my (windows) machine (I also used this for locking. It did complain about not locking dependencies for dataclasses, but that didn't seem to be a problem)
  2. Created an environment using 3.7 on my machine
  3. Created an environment using the 3.9 docker image
  4. Created an environment using the 3.7 docker image

As far as I can tell, it didn't hit any blocks

#

And I sent that premateurly lol

#

Let me finish the testing and get back to you in a bit

#

Mostly just waiting on docker to build the 3.7 image

#

And done, all clear

heavy heron
#

Huh

#

Well, thanks for the info

red sedge
#

What would black do with the proposed f-string changes?

errant barn
#

Oh wow, cool!

dense jungle
red sedge
#

Yeah it looks like you'd have to intentionally break quote parsing if you import the grammar from main

#

It's also a style choice, eg should black alternate quote styles or force "?

#

Obviously if any of 3.6-3.9 is a target version then quote styles must alternate

tribal thistle
#

Consistency would be nice, and you could probably throw the alternating option under the t flag

#

Speaking of, does that actually work? I ran into what I think is a bug with it while investigating another one a while back, but never got around to looking into it

dense jungle
#

Also I don't remember what -t is. --skip-string-normalization?

tribal thistle
#

Alright, I did write a report in response to another issue, I can dig it up and reinvestigate

#

T specifies python version

dense jungle
#

oh, --target-version

tribal thistle
#

I don’t remember the long form

#

Ah

dense jungle
#

I added that option and I still don't remember the short form 🙂

tribal thistle
#

Heh can’t blame ya

#

There are a ton of options

#

Hey I did write a repro 🤓

#

The crux of the problem was:
Running black in a python 3.8+ environment on a walrus with -t set to 37 would work, but the opposite doesn’t

#

Which I think is opposite of the intended behavior

#

I’m not sure it’s acc feasible to fix the issue on a 3.7 env, but I feel like it could be fixed on 3.8

#

Unless I’m fundamentally misunderstanding how that option works

dense jungle
#

I see, I understand why we do it that way but agree it's confusing

red sedge
#

They're talking about parsing the {} directly with PEG in one pass to simplify the parser, but it means they have to choose to reimplement the limitations of the old parser

tribal thistle
#

Which part are you replying to

stuck vapor
plain atlas
#

just used them as a basis to write my own hooks 🙂

amber karma
#

Does anyone have a pre-setup github actions black CI?

#

just to auto format on PR / Push?

red sedge
red sedge
tribal thistle
#

I was referring to the -t option, I’m sure the f-string thing will work when released

ember pendant
#

Whats this channel about

gilded mauve
plain atlas
#

...

#

this is why I test my lint on all versions

#

oof

#

this wasn't actually black that failed, sry

merry quest
#

how to roll back the format

#

is it possible

plain atlas
#

not really

merry quest
#

f

#

nvm

plain atlas
#

if you have version control, you should do that

merry quest
#

nah ,it was local file

plain atlas
#

you can still use git to manage a project even without a server

merry quest
#

i mean it is not a git repo

flat krakenBOT
flat krakenBOT
#

According to the docs, to install Vim plugin with vim-plug, we must use branch stable. But there is no (more ?) branch stable only a tag.

.vimrc file :
Plug 'psf/black', { 'branch': 'stable' }

When I try to install the plugin with :PlugInstall command, I have these error : Invalid branch HEAD (expected: stable).

If I modify my Vim configuration to use tag instead of branch, it works as expected (Vim ...

mint barn
#

How to apply black for a specific PEP Code Layout.. say e501? Right now all i can find on internet docs are just full scan and apply commands.

looking for something like black —apply E501,E402 or black —apply E*

errant barn
#

Hi, Black is not really built to do that. We aim to provide one style and enforce it all the way!

plain atlas
#

e501 is lines too long... i think you can maybe use autopep8 to do those simple things

#

!pypi autopep8

late dewBOT
#

A tool that automatically formats Python code to conform to the PEP 8 style guide

plain atlas
#

this is the most simple formatter

errant barn
#

And yeah, if it's just line length that you're after, you can decrease it by calling black -l 79

plain atlas
#

but that only works if the program is already formatted with black ^

errant barn
#

Yup 😄

plain atlas
#

there is another formatter, although I'm not sure what luck you'll have with it, but yapf

plain atlas
mint barn
# errant barn Hi, Black is not really built to do that. We aim to provide one style and enforc...

I’m sorry i did not give you’ll context to my need. So, here is what i am stuck at. I have more than millions lines of codes that was built for good number of years. Now i have to enforce PEP8 to it, without have git push of millions lines of codes changed and deleted with one commit and PR. So I took statistics / grouped using flake8 —statistics. The plan now is to apply black (if it had option) per PEP8 code layout per commit and push all in one PR. Any help is appreciated.

uncut patio
#

why not format the codebase by parts, rather than change every single file in every single commit slightly

mint barn
errant barn
#

But yeah, formatting a little bit at a time would be an option. Sadly black doesn't quite support that, but it is likely coming: psf/black#1352 Not for single style choices though I'm afraid

mint barn
# errant barn But yeah, formatting a little bit at a time would be an option. Sadly black does...

Thx for sharing the issue ref. As you rightly said.. these issue are similar but not exactly my request.. which is -> apply black to array/list of PEP8 code layout or apply full format but split (like docker layer) each change with PEP8 and auto use git commit / git hooks feature .

So, do you recommend opening issue and discussion around this on GH? Sorry to ask, i am new here, joined few mins ago. Haven’t explored how things work yet. A quick overview or link share will be great help.

errant barn
#

Well the documentation site is a good place to start!

#

We do offer a pre-commit integration, but that would again format the whole code base

mint barn
#

Cool, let me read the docs further first thing in the morning

plain atlas
#

TBH your best bet with those requirements is probably a different formatter.

mint barn
#

Btw are you open for contribution of this feature? Or strict no to such option in black? 😅

plain atlas
#

Very likely strict to no such option

#

Tldr your suggestion is against the core philosphy of black

errant barn
#

Most probably not 😅 but thanks for considering! If you'd like to chime in, there's a mountain of other issues on the tracker 😆

dense jungle
#

We won't add such an option. I'm not sure why you need to apply these changes one by one. Our recommendation with Black is to reformat everything at once so you're done with it.

mint barn
#

Applying all the format at once to millions lines of code and asking for PR review, is actually a big no for any reviewer. 😅

#

Hence the need

plain atlas
#

¯_(ツ)_/¯

errant barn
#

Well hopefully the range format issue will gain some traction and be implemented then, that could be your way out!

plain atlas
#

Like I said, if you want to apply to just pep8, you could try using autopep8 for a simple intial pass 🙂

#

!pypi autopep8

late dewBOT
#

A tool that automatically formats Python code to conform to the PEP 8 style guide

dense jungle
errant barn
#

Although gasp for other formatters advertised :D

plain atlas
#

its like, the total opposite of the spectrum of black

dense jungle
#

Black has safety checks that should make you able to reformat all code at once without worry

plain atlas
#

black is intentionally hard on your code. Like, I've legitimately formatted code with yapf which made the code extremely wonky and black reformatted it without a diff 👀

errant barn
plain atlas
#

now, the one thing that may cause an issue is #3. But since you don't have any other formatting that probably won't be an issue 😆

#

However, it could cause issues if you have any international comments or something in your code

#

huh, just had to reinstall discord

#

okay then

mint barn
#

Thx everyone 🙂

#

Have a wonderful day. Stay Safe. 🙂

flat krakenBOT
#

Description

This PR is in response to issue #2476. It allows the black vim plugin to parse the skip_magic_trailing_comma option from pyproject.toml and act accordingly.

Checklist

  • [x] Add a CHANGELOG entry if necessary?
  • [ ] Add / update tests if necessary?
    I'm not sure exactly how to do this, or if it's necessary. If it is, I can try to figure it out.
  • [x] Add new / update outdated documentation?
    Not necessary in this case. Black already claims to use `pyproject.t...
bright glacier
#

I'm working on a test suite cleanup PR. Main goals include 1) reducing test dependencies, 2) simplifying the more common test cases, 3) restructuring & reorganization. Do y'all have any other requests you'd like put in the hat?

plain atlas
#

more regression tests, maybe?

bright glacier
#

I'm not adding new tests but making it easier to add new ones 😉

plain atlas
#

has anyone ever formatted the stdlib?

white grove
#

Black Formatter is so nice

tribal thistle
#

Let’s see if I can find my results

#

Generated >4MB of annotations

Which turns out to be just over 50K annotations

~1K of them were line length, so bumping that up to 120 left me with exactly 49,720

#

In summary, if you ran black over it, you’d probably end up with a completely new language

heavy heron
#

I kind of want to start up a codespace and let it run that

heavy heron
#

Because I am an idiot it is running

errant barn
#

Let the lines be split

plain atlas
#

lol

#

i pulled the cpython repo locally and formatted it

bright glacier
#

I don't have enough CPU cores for that 😢

plain atlas
#

it took like 6 minutes+

#

also i did a shallow clone since im not dumb

heavy heron
#

You'd think so

bright glacier
#

I have a dual core APU from 2016 that boosts to 2.3 GHz ...

heavy heron
#

Alright, reaching the Tools folder

plain atlas
heavy heron
#

Umh, the process isn't exiting despite having printed Reformatted setup.py, which should be the last file. Should I guess that some workers are stuck on very large files?

plain atlas
#

lmao

#

also i ran isort on the library 👀

#

i also learned about a few peps from places where black failed to reformat the code since it couldn't parse it glare

#

ofc those were parser tests, so black failed successfully 🙂

#

(invalid code, black should not pass on those)

heavy heron
#
error: cannot format Lib/test/test_exceptions.py: maximum recursion depth exceeded
Oh no! 💥 💔 💥
1860 files reformatted, 149 files left unchanged, 13 files failed to reformat.

real    10m8.830s
user    27m38.220s
sys     0m9.280s```
plain atlas
#

i uh, reset my black formatting so lemme find it again

#

lmao wait what

heavy heron
#

3.9

plain atlas
#

I formatted on 3.9.7's version

heavy heron
#
codespace ➜ /workspaces/cpython (main ✗) $ git diff --shortstat
 1860 files changed, 276766 insertions(+), 211327 deletions(-)```
plain atlas
#

git checkout v3.9.7

heavy heron
#

So a good 500k line diff

plain atlas
#

oh god

#

this reminds me

#

i uh

#

have a confession if I can find the logs

#

🙃

#

I have already formatted the stdlib, with github actions so HA

#

er

#

found it

#

that was a fun problem

dense jungle
#

I think it does something like x = x = x = x = a couple hundred times

heavy heron
#

Haha

spring ether
#

Assertions written as assert(condition) appear all throughout a certain code base. Can I use black to change this and nothing else all through the code base at once?

errant barn
austere lava
plain atlas
bright glacier
#

Either I have forgotten everything about our file collection and discovery code or this area of the codebase is truly a mess. Given how hard it has been to write a convenience function for the associated tests, I'm leaning towards the latter. stdin_filename and include are particularly confusing :/

#

Why does passing None lead to different behaviour than passing the compiled default excludes with get_sources? I thought this was supposed to normalize them:

 501     if exclude is None:
 502         exclude = re_compile_maybe_verbose(DEFAULT_EXCLUDES) 
#

oh right, searching for gitignore is blocked if a non-default exclude is set, ahhhhhhhhhhhhh

flat krakenBOT
#

Describe the bug

When using only the black pre-commit hook using the default install (ie: not black[jupyter]), pre-commit throws the following error:

An error has occurred: InvalidManifestError: 
==> File /Users/sam/.cache/pre-commit/repox0xprpud/.pre-commit-hooks.yaml
==> At Hook(id='black-jupyter')
==> At key: types_or
==> At index 2
=====> Type tag 'jupyter' is not recognized.  Try upgrading identify and pre-commit?

Downgrading the pre-commit hook to 21.7b0 ...

bright glacier
#

Perhaps adding some comments to the code wouldn't (or cleaning it up :p ) be a bad idea 🤔

bright glacier
#

cc @stuck vapor

plain atlas
#

seems like a misconfigured pre-commit-config.yaml

bright glacier
#

I doubt it given the error says .pre-commit-hooks.yaml

plain atlas
#

InvalidManifestError

#

... yeah

bright glacier
#
    def test_gitignore_used_as_default(self) -> None:
        path = Path(THIS_DIR / "data" / "include_exclude_tests")
        include = re.compile(r"\.pyi?$")
        extend_exclude = re.compile(r"/exclude/")
        src = str(path / "b/")
        report = black.Report()
        expected: List[Path] = [
            path / "b/.definitely_exclude/a.py",
            path / "b/.definitely_exclude/a.pyi",
        ]
        sources = list(
            black.get_sources(
                ctx=FakeContext(),
                src=(src,),
                quiet=True,
                verbose=False,
                include=include,
                exclude=None,
                extend_exclude=extend_exclude,
                force_exclude=None,
                report=report,
                stdin_filename=None,
            )
        )
        self.assertEqual(sorted(expected), sorted(sources))

to ->

def test_gitignore_used_as_default(self) -> None:
        base = Path(DATA_DIR / "include_exclude_tests")
        expected = [
            base / "b/.definitely_exclude/a.py",
            base / "b/.definitely_exclude/a.pyi",
        ]
        src = [base / "b/"]
        assert_collected_files(src, expected, extend_exclude=r"/exclude/")

Anyway, this is what I'm aiming for most file collection tests. I'm not sure if this idea will hold up well enough, but hopefully it does!

late dewBOT
#

.pre-commit-hooks.yaml line 17

types_or: [python, pyi, jupyter]```
plain atlas
#

tldr the jupyter type here is not accepted

bright glacier
#

oh that's probably the issue lol

plain atlas
bright glacier
#

I should've read the error message a bit more carefully

plain atlas
bright glacier
#

Ah, it's ipynb not jupyter apparently

plain atlas
#

ye

late dewBOT
#

identify/extensions.py line 80

'ipynb': {'text', 'jupyter'},```
bright glacier
#

wait no, this is reversed

plain atlas
#

ugh i don't wanna set up a dev env but I wanna commit that

late dewBOT
#

identify/extensions.py lines 147 to 148

'py': {'text', 'python'},
'pyi': {'text', 'pyi'},```
plain atlas
#

wait

#

yes

bright glacier
#

:p

plain atlas
#

😔

bright glacier
#

It should work then, maybe their identify is super old?

plain atlas
#

!pypi pre-commit

late dewBOT
plain atlas
#

2.15.0...

#
pre-commit version: 2.15.0
sys.version:
    3.8.2 (default, Apr  8 2021, 23:19:18) 
    [Clang 12.0.5 (clang-1205.0.22.9)]
sys.executable: ...snip.../venv/bin/python
os.name: posix
sys.platform: darwin
#

hmmm

#

the error message does say Try upgrading identify and pre-commit?

#

butttt

plain atlas
#

how did you find that

bright glacier
#

the report states identify==1.4.14

plain atlas
#

ahhhhh

#

!pypi identify

late dewBOT
plain atlas
#

sheesh

bright glacier
#

Hmm, what solutions do we have though? A note in the documentation makes sense, but I can't think of an actual technical safeguard. I don't believe you can configure the minimum identify needed.

#

To be fair, that is a fairly old identify version and the error message does say to try upgrading it.

plain atlas
#

yeah

bright glacier
#

The error message could be better though

#

very traceback-y

plain atlas
#

I'll comment on the issue if you haven't already :)

bright glacier
#

Marco already did!

plain atlas
#

i very much appreciate all of the information they gave us

#

ah

#

I wanted to thank them for the amount of information that they provided lmao

#

most issues are not that informative

plain atlas
#

oh lmao in retrospect if this wasn't working on modern version then all pre-commit versions would have been bugged

bright glacier
#

3 files changed, 109 insertions(+), 201 deletions(-) -- not the worse but the clean up did feel a bit sketchy ...

plain atlas
#

okay but like 39 files changed on a completely non-sketchy pr :)

#

I love my prs

bright glacier
#

It's more that I'm worried I accidentally screwed up a test by rewriting it. The problem is that there's two interfaces regarding file collection and discovery, there's get_sources and gen_python_files, they're very similar but not quite the same. I've gotten away with using the same convenience function for some of the gen_python_files ones (even though it was designed for get_sources) but anything related to .gitignore is unsupported :/

plain atlas
#

ah

bright glacier
plain atlas
bright glacier
#

is the commit history clean and readable or kinda a mess?

plain atlas
#

here's another one

bright glacier
#

like I'm sometimes OK reviewing a massive PR if the commit history is well split up into (hopefully atomic) and well described changes

plain atlas
bright glacier
#

Yeah it's not actually that bad, although the sheer diff size means I would straight up reject reviewing the PR

plain atlas
#

lmao

#

the diff size is because it adds an entire subsystem and docs for said system

#

at least for the first one

bright glacier
#

1k is pushing my limits and 2k+ is just too much logic to review at once (even over several sessions)

plain atlas
#

the second one is because it adds an entire other system as well

plain atlas
#

rather than the 2.4k that it says

#

there's like 400 of docs, 200 of spaced out test cases using parameterize, and at least 200 in docstrings Kek

bright glacier
#

doesn't really change much

plain atlas
#

true

#

yeah they might be a little bit big

#

this is another one lmfao

#

i may have a problem.

bright glacier
#
 tests/test_black.py  | 887 +++++++++++++++++++-------------------------------
 tests/test_format.py | 155 +++++++--
 tests/util.py        |  83 +++--
 3 files changed, 510 insertions(+), 615 deletions(-)

this is what the test suite cleanup branch currently looks like compared to main

plain atlas
#

TLDR:
5919 additions = 2486 + 2101 + 1332
1239 deletions = 295 + 702 + 242

bright glacier
#

Whelp.

plain atlas
#

across all three pulls

#

hmmm brb i need to figure out a command to see what the size of the current codebase is

#

current code

#

there's 1832 lines of .py....

#

for reference, the current repo has around 12092 lines

#

so I'm increasing the size of it by nearly 50% with three prs

bright glacier
#

git diff main --stat

plain atlas
#

wow

#

okay

#

lol

#

thank u

mint barn
#

is there a way to get black to output the formatted file to stdout without formatting the file in place? i don't want the diff either with --diff, i want the whole formatted file, much like calling prettier without any flags on a .js file

bright glacier
#

You'll have to pass the file via stdin to get that

#

cat file.py | black - -q should do

mint barn
#

tyvm

#

worked like a charm!

bright glacier
#

Lovely!

flat krakenBOT
#

Thanks for the updates! Having target_version as an argument makes total sense to me as well 👍 I had a look at the code and it looks reasonable, although I don't know vim plugins.

Our changelog is currently at the release, so a new heading needs to be added to the top. So please add a new ## Unreleased heading and place the change under ### Integrations. I left one comment as well. Since we're short on vim wizards, I'm willing to take your word on this working just fine 😄

hallow scroll
#

Can anyone explain what this room is ?
Never heard of black formatter before

errant barn
flat krakenBOT
austere lava
#
errant barn
#

What's the Black style here? :D

#

Indenting parameters only once?

#

Cool doc though

lament crow
#

probably the multi-line style

errant barn
#

yah

lament crow
errant barn
#

Oh, I've taken that as granted :D

#

Just the logical conclusion of dedenting lists etc.

dense jungle
#

if you add type annotations you don't have a sad face any more 😄

austere lava
#

yeah the sadface style with closing parens on a newline

plain atlas
# flat kraken

ahem @glad pilot 😉
(I remember you use the plugin, so you may have a fun time reviewing this pr)

#

@bright glacier okay I'd like to recap my previous changes. A bunch of those changes are in the lock files.

#

poetry.lock | 1513

#

18 files changed, 2101 insertions(+), 702 deletions(-)

stuck vapor
short forge
plain atlas
#

no.

flat krakenBOT
flat krakenBOT
heavy heron
flat krakenBOT
#

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

The cache files are not thread/process safe. I've checked multiple projects simultaneously in different processes but get permission errors when one process is writing to the cache while another is reading from it. On linux the fix is pretty easy: set a different temp directory for each process using the XDG_CACHE_HOME environment variable but there is no equivalent for Windows (there's somewhat an equivalent but you ne...

flat krakenBOT
#

Describe the bug

"string".replace('"', '\"') it is transformed to "string".replace('"', '"')

To Reproduce

Self evident in the description. Needs no arguments, just run plain black on any file containing that line.

Expected behavior

Shouldn't change the replace sentence.

Environment (please complete the following information):

  • Version:

main, Linux, Python 3.8.10, gcc 9.4.0

Does this bug also happen on main?

Yes

Additional context...

dense jungle
#

pretty sure it's not the first time somebody opened an issue about this

errant barn
#

Oh 😅

#

Honestly couldn't have guessed that they were looking to add escapes manually

austere lava
#

Quotes are the literal worst

#

I peeked into the implementation of shlex.quote recently and my brain exploded

bright glacier
#

Argument 2 to "assert_collected_files" has incompatible type "List[Path]"; expected "List[PathLike[Any]]" -- there has to be something really dumb I'm missing here but I do not know what that is 😦

#

Ugh, ignoring that I accidentally wrote a pretty dynamic piece of code ... mypy hates it

bright glacier
#

I worked around it, and anyway mypy hates all of my code

#

Sometimes wish I could just refine variable types and not have mypy complain a bunch. I get it's relatively unsafe but these asserts don't feel valuable

bright glacier
#

Yeah I don't really get it still -- invariance and covariance are not terms I know

#

I mean, I still have 15+ errors, I don't think this code will work anyway

dense jungle
#

the summary is that if something needs a List[something], you must give it exactly that, not a List[something similar]

#

this is needed for safety when the list is mutated

#

often annotating arguments as Sequence or Iterable will help

errant barn
#

That has confused me too 😅

dense jungle
#

and this really is one of the most frustrating parts of typing

bright glacier
#

I think what confuses me is how an explicit type annotations all of sudden makes it OK according to the doc

dense jungle
#

oh something with type context probably

#

it infers a different type for a list depending on context

sour jay
bright glacier
#

makes kinda sense?

sour jay
#

So to put it simply, let's create one function that takes a list and adds a value: ```python
class A:
def init(self, value):
self.value = value

def add(container: List[A], value: str) -> None:
container.append(A(value))

#

Then we create a subclass called B: ```python
class B(A):
... # Whatever, it is different

#

If a list was covariant things would become troublesome

#
target: List[B] = [B('a'), B('b')]

add(target, 'c')  # UH OH!

# target now contains [B('a'), B('b'), A('c')]
# changing its type to List[Union[A, B]]
#

Does that clarify it @bright glacier, @errant barn?

bright glacier
#

no, not really unfortunately

errant barn
#

Well yes and no :D Because surely it is still a valid List[A] for all purposes

#

But I get that mypy would want to make the distinction

sour jay
#

So without mutation into consideration it works, add() can do the same with List[A] as it can with List[B]. But if it adds an element, the type of target changes!

bright glacier
#

it's all honestly going over my head, it sounds legit but yeah no I'm too dense for this today

#
def assert_collected_files(
    src: Sequence[Union[str, Path]],
    expected: Sequence[Union[str, Path]],
    *,
    exclude: Optional[str] = None,
    include: Optional[str] = None,
    extend_exclude: Optional[str] = None,
    force_exclude: Optional[str] = None,
    stdin_filename: Optional[str] = None,
) -> None:
    src = [str(Path(s)) for s in src]
    expected = [Path(s) for s in expected]
    if exclude is not None:
        exclude = black.re_compile_maybe_verbose(exclude)
    if include is not None:
        include = black.re_compile_maybe_verbose(include)
    else:
        include = DEFAULT_INCLUDE
    if extend_exclude is not None:
        extend_exclude = black.re_compile_maybe_verbose(extend_exclude)

this code was a mistake -- I don't know why I didn't remember all of this redefinition would be problematic

sour jay
bright glacier
#

nope, I just can't understand it

#

I get it's the mutation that's problematic now but that changes almost nothing for my understanding

sour jay
#

Tl;Dr ```python
def add(container: List[A], item: str):
container.append(A(item))

target: List[B] = [B('a'), B('b')]
print(target) # [<main.B object at 0x000001D1CBB594F0>, <main.B object at 0x000001D1CBEE3DF0>]

add(target, 'c')

BAD! Types can no longer be statically trusted

print(target) # [<main.B object at 0x000001D1CBEE3BE0>, <main.B object at 0x000001D1CBEE37F0>, <main.A object at 0x000001D1CBB594F0>]

sour jay
bright glacier
#

I guess to explain it in my own words:

  • since add's container type annotation is List[A], that means it's allowed to modify it with items that A permits (assuming covariance)
  • that's a problem since a caller could pass a list typed more strictly than List[A] and add could change it
  • and it isn't an error on add's side because for all it knows container is List[A]
#

that's probably wrong though

dense jungle
#

that's right!

sour jay
#

No that's exactly it

#

👏

bright glacier
#

I always thought containers following typing.Sequence were also mutable, but apparently not?

sour jay
#

typings.Mapping / collections.abc.Mapping isn't mutable

sour jay
bright glacier
#

right

#

this day has gone terribly

sour jay
#

So yeah, I always assumed the same thing but when you put it into words.. yeah

sour jay
plain atlas
bright glacier
#

It's been a slow day and coming home and doing some refactor for only for mypy to hate my code (even if it's right) is not what I needed

plain atlas
#

I also wrote a feature a few weeks ago that's so bad I need to fully rewrite it.

bright glacier
#

does anyone have any good ideas on how to rewrite this code to not depend on implicit type narrowing + implicit type redefinition?

#

I could just add four asserts for include, *exclude* but I feel there could be something better

dense jungle
#

we could turn on mypy's --allow-redefinition flag, not sure if it works well with mypyc

#

or use new variables with a separatename

bright glacier
#

That's probably not a good idea

#

I'll do that, I don't like it much but it seems for the better

#

Oh right lol, I was about to do

if x is not None:
    new_x = Whatever()
else:
    new_x = None

IIRC this is invalid until recently (or the reversed form) when Sully did a PR

#

.. I should go look up the PR, I don't think my memory can be trusted today

plain atlas
#

psf/black#sully

#

😔

bright glacier
#

python/mypy#11002

toxic stormBOT
bright glacier
dense jungle
#

He goes by Sully in real life too

bright glacier
#

TIL

plain atlas
#

hmmm

#

ichard, you write black primer, right?

bright glacier
#

diff-shades

#

Black-primer was Cooper's idea and creation

plain atlas
#

hmm

#

what is the difference?

#

I'm kinda interested in seeing if I can implement this if y'all think its useful for psf/black

bright glacier
#

That's what diff-shades is all about

#

I just haven't found the motivation to continue work on it

plain atlas
#

tldr since you have the repos and code and workflows already, it would just be adding the msg from the workflows somehow

bright glacier
#

Diff-shades is not ready for use yet, it's really fragile and non-user-friendly

plain atlas
#

ah

lament crow
bright glacier
#

Indeed!

#

Also finally! mypy -p tests is now passing (well actually not, but for reason pytest's fixtures aren't being picked up properly by local mypy)

#

I honestly don't quite understand why running mypy via pre-commit resolves the pytest fixture errors but oh well I'm not in the mood to figure it out.

#

Wow, flake8 tests/ was a mistake 😅

lament crow
#

what if you exclude fixtures

bright glacier
#
❯ mypy -p tests --pretty
tests/test_no_ipynb.py:25:48: error: Function "_pytest.tmpdir.tmpdir" is not valid as a type
    def test_ipynb_diff_with_no_change_dir(tmpdir: tmpdir) -> None:
                                                   ^
tests/test_no_ipynb.py:25:48: note: Perhaps you need "Callable[...]" or a callback protocol?
tests/test_no_ipynb.py:29:14: error: Unsupported left operand type for / (tmpdir?)
        tmp_nb = tmpdir / "notebook.ipynb"

not sure what you mean by that

lament crow
#

tests/data

#

sorry, thought you call those fixtures

bright glacier
#

You definitely can, pytest just has its own meaning of fixtures

plain atlas
#

unless its a local hook but even then idk

bright glacier
#

I can't think right can't I today.

flat krakenBOT
#

Describe the bug

Black does not correctly break lines in some cases. In the first two of these examples below it incorrectly puts foo( at the end of a line instead of breaking at the or binary operator as it should. In the other three cases, where I've added a third or clause, it breaks correctly.

This code

if (
    foo(1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
    or foo(1, 2, 3, 4, 5, 6)
):
    pass

is incorrectly formatted as

if foo(1, 2...
flat krakenBOT
flat krakenBOT
#

Description

The main goals of this PR include:

  • improving consistency on how strict the test suite is -- Jelle has seen cases where a test did not fail to an incomplete test setup even though it should've
  • simplifying tests for both ease of creation and reading via parametrization and helpers
  • reorganizing the test suite by grouping more tests
  • dropping test suite dependencies that aren't strictly necessary

The test suite could definitely do with more refactoring, but...

stuck vapor
bright glacier
#

To be honest I didn't want to ask the team if isort would be an welcome addition so I did it one time only for select files ^^

errant barn
#

Could be cool in my opinion 😄

plain atlas
#

^

#

However isort does have a conflict with Black's own style in a specific case

errant barn
#

And despite the profile?

plain atlas
#

ye

#

one sec

#

pycqa/isort#1683

toxic stormBOT
errant barn
#

Oh, not a huge dealbreaker in my eyes

#

But would be cool yea

plain atlas
#

commented on it 👀

stuck vapor
#

I see, thanks! I tend to use force_gridwrap, so all imports end up on their own line (so merge conflicts are minimised) and so had never come across that

plain atlas
#

ah, makes sense

#

i have a full ci on unused imports as well that it complains if they aren't used 😛

#

so its a simple matter of accepting both changes, and running pre-commit and then correcting the linting errors :)

#

on a related ci note, I've been looking into towncrier

#

!pypi towncrier

late dewBOT
plain atlas
#

that's something to use for reducing merge conflicts

#

also no that's not related to black sorry

bright glacier
#

our grep powered news entry CI check has been working well enough for us so far ^^

plain atlas
#

ye, towncrier is a very different solution

#

changes instead get added to their own files

bright glacier
#

Yup I know.

plain atlas
#

👍

#

I actually have a grep news entry ci check too!

#

its nearly identical to black's

#

Its a good workflow, why would I not use it?

flat krakenBOT
errant barn
#

I wonder if having test cases with multiple inputs and one expected result would be good. Like

a = long_call(
    with_,
    some=params,
)
## inputs
a = long_call(with_, some=params)
#
a = long_call(with_, some = params)
#
a = long_call(with_,
              some=params)

or if just making a case for each would be better.

bright glacier
#

Usually such a scenario lends itself well to parametrization

plain atlas
#

^

#

BTW

#

there's not a way to see if a test raises a certain error with a paramertized test

#

!pypi pytest-raises

late dewBOT
plain atlas
#

except if you use that :)

errant barn
#

I meant that we would write those in the test scripts

#

Whereas now we have to provide an output for each input

#

Whereas? Yeah I'm going with whereas.

plain atlas
#

wait huh

#

brb

bright glacier
#

Are you talking about test_black or test_format?

errant barn
#

formats, the tests that we write to the actual py files

plain atlas
#

I'm confused what you mean, felix

errant barn
#

Now when we make formatting tests, we write something like

a = long_call(with_, some=params)
# output
a = long_call(
    with_,
    some=params,
)

So if we want to make many cases, the output has to be repeated every time. Which wouldn't have to be the case.

#

Since there (optimally 😅) is only 1 style, we could maybe shorten some tests a bit

errant barn
bright glacier
#

I'm still confused on where the duplication of the output aka expected result is happening

errant barn
#
a = long_call(with_, some=params)
a = long_call(with_, some = params)
a = long_call(with_,
              some=params)
# output
a = long_call(
    with_,
    some=params,
)
a = long_call(
    with_,
    some=params,
)
a = long_call(
    with_,
    some=params,
)
bright glacier
#

Oh you mean combine tests?

errant barn
#

Ye

#

Yeah my explanation wasn't very clear was it :D

#

Don't know how many cases of this there are though. Could be a non-issue

plain atlas
bright glacier
#

We could do that but the isolation and focused nature of the existing style is probably better

plain atlas
#

Since pytest is used as running, it first collects the tests, which means everything needs to be in a method, basically

errant barn
#

I remember lots of tests being rather long and varied. So this probably won't fit other than the most basic tests

bright glacier
#

Isn't this what test_format SIMPLE_CASES is all about?

errant barn
#

wait.

bright glacier
#

And FWIW I added assert_format and assert_collected_sources helper functions to simplify the more complex tests in that PR

errant barn
#

So the simple cases assert only that the file doesn't change right?

bright glacier
#

I originally planned to add additional class of "semi-complex" tests similar to test_format.SIMPLE_CASES but that was painful to implement so I ditched that idea

errant barn
#

Hope I'm reading it right

bright glacier
#

Well it depends on the data file used

#

If the data file doesn't contain a "# output" marker then any changes will fail the test

errant barn
#

Yeah or that the output is the same

#

Yep, so not quite what I'm thinking about. But it's probably fine :D was just bouncing around ideas

bright glacier
#

Honestly I still don't really know what your idea is all about 😢

errant barn
#

Say we test e.g. some line break thing

#

Like the long call I posted above

#

We could make multiple inputs that should produce a single output. Now we'd have to write the output for each input

#

Not as convenient for these longer scripts, I'll say that much. But for small snippets could be convenient

bright glacier
#

Oh, something like:

[case LineBreak]

[input 1]
x = func(
          this=a
)

[input 2]
x = func(
this=a
)

[output]
x = func(this=a)

(i stole mypy's declarative test style)

errant barn
#

Yep yep exactly

#

Do they already use it?

bright glacier
#

I'm not sure, that would be a question for Jelle and not me

errant barn
#

Oh ok 😄 but yeah that would be the idea. So the smallest unit tests would be easier

#

"unit" well anyway

bright glacier
#

It sounds reasonable, I'm not sure how many cases we could convert, but anyway we should probably do this at the data file level via a specific format (eg. mypy's)?

errant barn
#

Yeah probably. It's just a generalisation of the current format after all

bright glacier
#

yeah, it's pretty basic right now, either you put an output marker or you don't

#

one thing I will note is that I don't like the lack of syntax highlighting due to the extension of the syntax instead via magic comments

errant barn
#

Ye they do look nice

errant barn
#

double-edged sword for sure

errant barn
#

🔥

bright glacier
#

I think I was able to fix the python_version markers in Pipfile.lock

#

The way I did it was really sketchy but hey- it works!

plain atlas
flat krakenBOT
plain atlas
#

Huh

#

About that isort magic trailing command thing, I might be trying to implement it

plain atlas
#

i am trying to implement it :)

plain atlas
#

uh, maybe not

signal jay
#

Yeah

flat krakenBOT
austere lava
#

why do we have flake8 B950 enabled in the repo btw?

#

(that's the line too long error)

flat krakenBOT
#

This endpoint implements the document formatting request from the language server protocol spec: https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#textDocument_formatting
There are a few limitations to this implementation:

  • it ignores all formatting options that are passed in
  • on syntax error it returns a generic "internal server error" message
  • it only supports file:// URIs
  • there's no support for initialization protocol messages: https://micr...
austere lava
#

its kinda annoying that i had to url shorten some links because they're too long to fit on a single line (in a comment or docstring)

austere lava
tribal thistle
#

I've included that note in all my commits for ages because my IDE just... does it, but is there any actual benefit to it?

stuck vapor
austere lava
austere lava
lament crow
#

most notably, in (doc)strings and comments

lament crow
cloud oak
#

How can I place one newline before and after function instead of two using ~/.config/black.

frigid coyote
#

I know this might not be the correct channel to ask this but anyone here who contributes to pandas official repository?

errant barn
errant barn
frigid coyote
#

I have joined there gitter channel as well

errant barn
frigid coyote
flat krakenBOT
#

Describe the bug

Black attempts to run with too many executed threads when running in a container (e.g. in kubernetes).

It is well understood that containers do not mask the number of physical cores available, despite the fact that the container itself might be limited by the amount of CPU it can use at one time. This means that using the result of os.cpu_count() to spin up that many threads can cause a huge number of threads to be created. The memory overhead of this can cau...

flat krakenBOT
#

Description

Fixes Issue #2512. This does introduce a new CLI parameter but it fixes a pretty core issue. See the issue for more details.

Checklist - did you ...

  • [x] Add a CHANGELOG entry if necessary?
  • [ ] Add / update tests if necessary? -- Unsure if this needs testing.
  • [x] Add new / update outdated documentation? -- I checked this and the --help is automatically inserted into the docs.
stuck vapor
#

Regarding https://github.com/psf/black/issues/2505 , is the black pre-commit hook expected to run on non-extensioned Python files?

If not, seeing as there's no way to specify a minimum identify version in pre-commit, a solution could be to just use files instead of types_or

plain atlas
river flame
#

hello

#

Are you ok?

stuck vapor
plain atlas
#

Oh lmao that is you

#

Jeez, I referred you to your own comment.... I'm sorry, I'm not stack overflow, that's not what I should be doing 😛

plain atlas
errant barn
#

I'll have a look

plain atlas
#

psf/black#2505

errant barn
#

Okay I don't really know what's in play here honestly 😅

plain atlas
errant barn
#

So: someone is using our jupyter hook without installing the extra.

plain atlas
#

Original discussion there

errant barn
#

Oh ty

plain atlas
stuck vapor
#

🤣 no worries

Essentially, the alternative would be:

files: (\.pyi?|\.ipynb)$

instead of

types_or: [python, pyi, jupyter]

Advantage:

  • users don't get scary-looking tracebacks if their version of identify isn't recent enough

Drawbacks:

  • if someone has a file with Python shebangs, but which doesn't end with .py, then it won't get formatted
errant barn
#

For it to accept the types_or fiel values

#

Yeah ok thanks!

plain atlas
#

Given that the min version of identify is a year old, imo a user should have upgraded in over a year

stuck vapor
errant barn
#

Right, probably true

plain atlas
#

Also I'm not sure if I commented in it but that user was a great provider of what the problem was.

errant barn
#

So surely there is a way to require a specific identify version lemon_thinking

#

Or a range

plain atlas
#

Sure, they may not have read the message at the bottom of the traceback which fold them to try upgrading identify, but they provided a lot of information

#

And honestly I think that's the solution

#

While yes, the tb is extremely long, I don't think black should make compromises for pre-commit failures

stuck vapor
errant barn
#

Yeah true, but if the config is invalid we could try to help them anyway by requiring a version

plain atlas
#

They do tell the user what to try doing, and I'm not sure if the traceback has changed since then, either.

#

pre-commit/pre-commit#1946 on mobile, wanna see title

errant barn
#

The issue author had a good point about the type being right but with an incomplete listing = no error

#

Oh I'm dumb, the upgrade message is right there at the start of the issue 🤣 Yeah that's definitely the solution to this error, and if the p-c folks are against a config, then it will have to do

plain atlas
#

Also the maintainer is right, but also wrong imo, while yes, there is a message the traceback should not be so long lmfao

#

I haven't seen much but that's the longest tb I've seen in a bug report so far.

stuck vapor
errant barn
#

The alternative way of finding files would be fine as well, but I think I'll just close this for now

#

BTW is it somehow extra expected that with pre-commit you always use the latest version?

#

I mean of course with every library you try to, but

stuck vapor
#

dunno, but at least there's a really clear minimum_pre_commit_version flag for that

errant barn
#

Yeah odd that they wouldn't accept that for identify 😄 oh wel

plain atlas
#

wait

#

that traceback is handled in pre-commit

#

this is the end user part 😛

#

I presume they reran pre-commit in verbose mode

vocal ravine
#

Hey guys, So I am having an issue with black v20.8b1 installed via poetry on python 3.7.6 on linux(Pop!_OS 21.04 to be exact), when I run the command in my project using 'poetry run black .' I just see 'Aborted!' with no error message. It seems to work fine if I run it with the '-S' flag. I tried installing the newest version of black, 21.9b0, with pip globally to test it out, and that version works fine, however this project is for my work and I am not able to just update to the newest version atm. Any thoughts?

errant barn
#

I.e. without poetry

tribal thistle
#

Did you give it a file to format

vocal ravine
tribal thistle
#

Hm

errant barn
vocal ravine
dense jungle
#

I don't think the "Aborted!" message comes from Black itself, so it must be some other layer that's doing it

#

there's no other output than "Aborted!"?

errant barn
#

poetry run --verbose black .? :D

vocal ravine
errant barn
#

And diff didn't need S?

vocal ravine
vocal ravine
errant barn
#

Have you tried an isolated env with Black only?

vocal ravine
errant barn
#

It'll at least give a clue whether a clean install is ok. I'm guessing your global packages have lots of other packages

dense jungle
#

"Aborted!" sometimes happens if the OS kills the process

#

Like the OOM killer on Linux

vocal ravine
errant barn
#

Damn. I don't know where to continue. Is the upgrade stuck on style changes or what?

#

For your team I mean

plain atlas
#

A new poetry environment may copy the site packages from where it was created

errant barn
#

surely not by default lemon_surprised

vocal ravine
# errant barn Damn. I don't know where to continue. Is the upgrade stuck on style changes or w...

This doesn't effect my whole team, as far as I know it is just my local environment. VSCode successfully auto formats on save with black, just a tedious issue I would have to work around seeing as our "make test" target includes formatting and linting before actually running the tests, was just seeing if anyone had seen this before and could help me fix it. If not then I can live with it

errant barn
#

I meant that if the newer version works, is the reason for you not upgrading style issues or something else?

#

But yeah, at least I've never heard of something like this :/

vocal ravine
dense jungle
#

What OS are you on? If Linux I'd check /var/log/syslog to see if anything is getting terminated by the OS

vocal ravine
#

I appreciate the help everyone! Looks like I will just have to bite the bullet on this one and bring up a possible package update to my team. Again, thanks for the support!

flat krakenBOT
plain atlas
#

Heads up: issue 2513 is not linked to 2514

errant barn
#

What do you mean?

plain atlas
#

So if the pr is successfully merged the issue will stay open

#

Just a small maintainer detail which could cause an issue that is actually solved to continue to be open :)

bright glacier
#

Usually I'll notice that the relevant issue wasn't closed during the merge, but it can't hurt to fix it before then -- thanks for noticing!

flat krakenBOT
flat krakenBOT
flat krakenBOT
#

Just letting you know that I love black!

So, I had a fragment like:

    pbn_uczelnia.pbn_integracja = pbn_uczelnia.pbn_aktualizuj_na_biezaco = pbn_uczelnia.pbn_api_nie_wysylaj_prac_bez_pk = True

... and it got formatted to:

    pbn_uczelnia.pbn_integracja = (
        pbn_uczelnia.pbn_aktualizuj_na_biezaco
    ) = pbn_uczelnia.pbn_api_nie_wysylaj_prac_bez_pk = True

How could this be improved?

Well, perhaps I could get a warning on "enterprise-y" ...

edgy blaze
#

GİT HUB

flat krakenBOT
flat krakenBOT
plain atlas
flat krakenBOT
#

Describe the bug

When running the function reformat_code (and code provided as a string) inside a Jupyter Notebook, it raises the following exception:

Traceback (most recent call last):
  File "C:\Python37-32\lib\site-packages\black\__init__.py", line 585, in reformat_code
    content=content, fast=fast, write_back=write_back, mode=mode
  File "C:\Python37-32\lib\site-packages\black\__init__.py", line 843, in format_stdin_to_stdout
    sys.stdout.buffer, encoding=en...
stuck vapor
# flat kraken

should this be fixed in black, or is it a bug in ipykernel? feels like the latter to me, but I don't know

gentle ocean
#
if (mp<len(map)):
                if (map[mp]==1):

IndexError: list index out of range

flat krakenBOT
bright glacier
#

I'm a bit hesitant to join in the event tbh, I haven't heard many positive things about it from other maintainers ...

lament crow
#

you can assess PRs on case-by-case basis, there's no need to add the hacktoberfest topic

#

you can just label PRs with hacktoberfest-accepted if they're worthy (meaning, they're not a hindrance to you as a maintainer :P)

dense jungle
#

It was pretty good for typeshed. It might work less well for Black since it's a lot harder to make a useful drive-by contribution to Black than typeshed.

lament crow
#

I'm pretty sure none of you guys would have an issue with labelling some PR if it was actually a good contribution if the contributor asked nicely and the contribution was useful

#

IMO, there's no need to advertise yourself as project taking part in Hacktoberfest

#

if someone wants to contribute, they already can

short forge
#

The event was a shitshow last year and i recommend not participating even tho it might drive away potential beneficial contributors

sour jay
delicate marsh
potent viper
#

btw what is this

bright glacier
#

The real-time communication home of psf/black, a FOSS project all about building an uncompromising Python code formatter.

potent viper
#

what is a "code formatter" tho

bright glacier
#

A tool that changes code to follow a certain visual style

potent viper
#

I still don't understand what is going on there

silent apex
#

It's programmatically editing your code to follow a specific style.

potent viper
#

Why tho

bright glacier
#

OK, let's say we have this code:

if   ( x == "hello, world!" ):
    print ("hi!")

it's functional but pretty hard to read. Black will convert it into:

if x == "hello, world!":
    print("hi!")

which is more readable and consistent

potent viper
silent apex
#

Say you have this:

def func(): print('hello')
```, black will make it look like this, which follows PEP 8 and is consistent:
```py
def func():
    print("hello")
potent viper
#

what is PEP 8

bright glacier
#

The official style guide for Python code within the cpython project ... although it's the most official unofficial style guide out there for all Python code

silent apex
#

!pep 8 See the link below for the guide itself

late dewBOT
#
**PEP 8 - Style Guide for Python Code**
Status

Active

Created

05-Jul-2001

Type

Process

potent viper
#

I mean it's kinda cool but what are the practical parts? Is this just a fun project or is it being used for something inportant

silent apex
#

It's often used to keep code style consistent through a huge codebase. The original creator made it for use at Facebook(?) I believe.

bright glacier
deft wyvern
stuck vapor
#

How is performance of black measured? I have a patch which might be a performance improvement, but it's based on running rm -rf t; time XDG_CACHE_HOME=$PWD/t black . a few times - is there a better way to check?

little parrot
#

perhaps blackbench from richard if its finished?

bright glacier
#

uhh, what's the type of performance win are we talking about?

stuck vapor
bright glacier
#

ah that doesn't fall under blackbench's scope right now

little parrot
#

can you not just timeit it?

bright glacier
#

Is that for me?

little parrot
#

no for marco

stuck vapor
#

indeed, no noticeable difference running %%timeit and some of the tests which use gen_python_files , and slight decrease for others - oh well, it was fun to try this anyway 😆

silent void
bright glacier
#

haha, yes lemon did make a song all about PEP 8

flat krakenBOT
potent viper
#

sheesh

flat krakenBOT
#

Describe the bug

Non-idempotent source

To Reproduce

assert sort_by_dependency(
    {
        "1": {"2", "3"}, "2": {"2a", "2b"}, "3": {"3a", "3b"},
        "2a": set(), "2b": set(), "3a": set(), "3b": set()
    }
) == ["2a", "2b", "2", "3a", "3b", "3", "1"]

Run

black mytest.py
touch mytest.py
black --check mytest.py

Expected behavior

Second call to black shouldn't find changes to the code, but it does

**Environment (please complete ...

hardy panther
#

I love black the formatted!

ivory vine
#

Is this really how Black formats long unpackings like this?

turbid ivy
#

.

tribal thistle
#

Hey @bright glacier thought you were done with pipenv issues did you? 🤡

This may be my fault for trying to run in 3.10, but typed-ast 1.4.2 doesn't build. 1.4.3 does. All other dependencies are fine, so I'm not sure if this is a me thing, or if needs to be bumped

bright glacier
#

why >.<

tribal thistle
#

It's just throwing pages of syntax errors from typed-ast

#

I can bundle it into a pastebin

bright glacier
#

the long term solution to this is to del typed-ast on py3.9+ but we first need to deprecate and remove python two support

#

lemme build 3.10 locally and test it out, but anyway I wouldn't mind bumping typed-ast

tribal thistle
#

Is there a reason it was locked to 1.4.2 specifically?

bright glacier
#

Not as I know I of

#

ah, we bumped it once to 1.4.2 to avoid issues on s390x

bright glacier
bright glacier
#

Thanks for noticing

flat krakenBOT
heavy heron
#

although @bright glacier they do expire three weeks after the last view. Probably not relevant for that issue, but that may be something to keep in mind.

tribal thistle
#

weeks or months lol

heavy heron
#

think it is week? ||@delicate marsh||

delicate marsh
#

three months

#

it’s three months after the last link open

plain atlas
#

!remind 2m click the above link

late dewBOT
#
Sure.

Your reminder will arrive on <t:1638695149:F>!

delicate marsh
#

scrapers hit the site enough that most pastes get a bump lol

plain atlas
#

Smh

#

Feels like the paste site could use a robots.txt then

heavy heron
#

Haha

flat krakenBOT
#

Describe the bug

When pipenv tries to lock dependencies, the following sub-dependency error arises:

✘ Locking Failed! 
[ResolutionFailure]:   File "/home/ru/.local/lib/python3.9/site-packages/pipenv/resolver.py", line 741, in _main
[ResolutionFailure]:       resolve_packages(pre, clear, verbose, system, write, requirements_dir, packages, dev)
[ResolutionFailure]:   File "/home/ru/.local/lib/python3.9/site-packages/pipenv/resolver.py", line 702, in resolve_packages
[Resolu...
flat krakenBOT
flat krakenBOT
pastel skiff
#

!remind 2m click the above link

late dewBOT
#
I got you.

Your reminder will arrive on <t:1638759859:F>!

bright glacier
#

Arl wth did you start lol

flat krakenBOT
flat krakenBOT
#

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

Black normally removes all parentheses in some simple cases like:

if ((x and y)):
    pass

is turned into

if x and y:
    pass

But in more complex situations it does nothing, which is understandable.

However, one thing that I'd like to see is at least replace all double/triple parenthesized parts with a single parentheses. Currently this doesn't happen.

if not (...
potent geode
#

What's a last version can I get in windows 7 32bit

tribal thistle
#

Python 3.9, which I think means you should have access to the latest black version

#

But windows 7 has been EOLed for nearly two years now, and I don't think I've seen a 32bit machine that wasn't a microcontroller, or dedicated for something in my lifetime

#

Yup first 64bit was made in 2003, the year I was born lmao

bright glacier
#

I'm working on deprecating Black's Python two support wholesale, but I don't know how to actually emit the deprecation warning.

#

My first thought was to issue a DeprecationWarning but that's pretty ugly in the output (and is hidden by default)

#

But if we only emit a warning to STDERR people using black as a library won't be able to rely on any Python-level warning capturing systems they have in place (as a responsible developer) eg. pytest's

#

Thoughts?

tribal thistle
#

What does pytest use black for

bright glacier
#

I meant like if anyone collects warnings while using black's unofficial API, example a test running under pytest

tribal thistle
#

Ah ok

bright glacier
#

I don't mean pytest uses black, just that it collects warnings and presents them nicely which a stderr warning won't play nicely with AFAIK (i.e. nothing happens)

tribal thistle
#

For the ugliness part, it would probably look fine without a traceback

#

But I'm not sure how you could address it being hidden

lament crow
#

I don't think DeprecationWarning will give the majority of the people anything over stderr message

#

Cause usage of Black API or the -W error interpreter flag is rather unlikely even for all users of Black, yet alone people that format Python 2.x codebase.

#

but then again, issuing a warning is a single function call

tribal thistle
#

What if you raise the warning instead of printing it

dense jungle
#

Honestly I think a stderr warning is fine.

lament crow
#

I just think that if anything will be of use, it's the stderr message

bright glacier
#

ugh, I can't find where ubuntu stores screenshots

lament crow
#

isn't it just ~/Pictures?

#

if you're using the default GNOME

bright glacier
#

not there for some reason which is odd given there's a bunch of older ones in there

#

got this right now