#black-formatter

1 messages · Page 24 of 1

bright glacier
#

this should fix the misfiring fwiw

plain atlas
#

!d signal

late dewBOT
#

This module provides mechanisms to use signal handlers in Python.

bright glacier
#

I honestly have never installed a custom signal handler

trail plaza
#

it's neat for cleanup (trapping SIGTERM and friends)

late dewBOT
#

modmail/bot.py lines 117 to 122

try:
    # adds signal handlers so the loop is safely stopped
    loop.add_signal_handler(signal.SIGINT, lambda: loop.stop())
    # this one we may want to get rid of, depending on certain things, and just hard stop instead.
    loop.add_signal_handler(signal.SIGTERM, lambda: loop.stop())
except NotImplementedError:```
bright glacier
#

Aren't they Unix only sadly enough? I mean that's better then nothing, but it won't help scale in that case

trail plaza
#

there are different signals for windows ig. SIGBREAK (only for win)

plain atlas
#

^

#

there's also the simple one

#

KeyboardInterrupt

#

which is the exception

late dewBOT
#

modmail/bot.py lines 130 to 133

try:
    loop.run_forever()
except KeyboardInterrupt:
    self.logger.info("Received signal to terminate bot and event loop.")```
tribal thistle
#

@bright glacier so it seems the redirect is only slightly working. If I redirect output into a file, I can see what it caught

bright glacier
#

I wonder if the multi processing is hitting some open file descriptor limits

#

perhaps using an in memory file like object would fix it

tribal thistle
#

And it seems to have just caught black output

#

All done! ✨ 🍰 ✨
.

plain atlas
#

are you redirecting both stderr and stdout?

bright glacier
plain atlas
#

or just redirecting stdout

tribal thistle
#

I modified the suppression code to:

@contextmanager
def suppress_output() -> Iterator:
    with open('x.temp', "w", encoding="utf-8") as blackhole:
        with redirect_stdout(blackhole), redirect_stderr(blackhole):
            yield
bright glacier
#

both

plain atlas
#

is that only valid on 3.10?

bright glacier
#

wut

plain atlas
#

the dual with

#

with redirect_stdout(blackhole), redirect_stderr(blackhole)

#

or is that able to be done on 3.9 and before?

tribal thistle
#

definitly doable on python 3.9 (I'm also running this code on 3.9)

#

I'm not sure what's up with click

#

But it doesn't seem to be outputting to stderr at all

#

Which is not a bug I want to try and debug today

#

Though I didn't change anything in diff-lib aside from editing black to always emit warnings

#

One somewhat hacky, somewhat not, fix would be to patch the echo function and explicitly specify the file

bright glacier
#

replacing os.devnull with an actual file nets me this

tribal thistle
#

I wonder why it isn't outputting for me then

bright glacier
#

I even set the process count to 12 thinking maybe it was something due to the higher open file handlers you'd have with a quad-core but nope!

plain atlas
bright glacier
#

yes it's already fixed in main

plain atlas
#

ah cool

bright glacier
#

something that is annoying with being on windows is that I can't push changes to github as my PAT is stored on an ext4 drive ....

plain atlas
#

pat?

#

oh

bright glacier
#

personal access token

plain atlas
#

just make a new one that expires in a few days

bright glacier
#

yeah I guess but that's also annoying lol

tribal thistle
#

Ok something interesting, click isn't picking up my terminal as windows

plain atlas
#

¯_(ツ)_/¯

tribal thistle
#

So it's returning an incorrect file handler for stderror

bright glacier
#

are you using mginw bash / git bash on windows or something?

tribal thistle
#

Pycharm, but I can replicate on CMD

#

I also get the output in CMD

bright glacier
#

what script are you running to query click, lemme run it on my windows install

plain atlas
#

if i was more familar with click i could probably help better

#

haven't written the cli for my project that I intend to write some time

tribal thistle
#

Nothing, just hopped into my site-pacakges, modified the if to print, and ran diff-shades lol

bright glacier
#

and it worked magically lol?

tribal thistle
#

Well, yeah I saw my print in the output, benefits of modifying site

bright glacier
#

I wonder if patching at the file handler level would be work as a workaround to click's weird interaction with sys.std*

tribal thistle
#

The thing is, I can copy the code click uses to determine os, and run it in a repl

#

But for some reason, it's returning False when running

#

You know what, ignore all what I said

#

I had my prints backwards lol

bright glacier
#

me wonders if this is why it's behaving weirdly

late dewBOT
#

src/click/utils.py lines 249 to 253

if file is None:
    if err:
        file = _default_text_stderr()
    else:
        file = _default_text_stdout()```
late dewBOT
#

src/click/_compat.py lines 610 to 612

_default_text_stdin = _make_cached_stream_func(lambda: sys.stdin, get_text_stdin)
_default_text_stdout = _make_cached_stream_func(lambda: sys.stdout, get_text_stdout)
_default_text_stderr = _make_cached_stream_func(lambda: sys.stderr, get_text_stderr)```
bright glacier
#

seems to be cached on initialization?

tribal thistle
#

<ConsoleStream name='<stderr>' encoding='utf-16-le'>

#

(_default_text_stderr)

bright glacier
#

although this doesn't explain why it's working on linux and my windows

plain atlas
#

what windows version

tribal thistle
#

10

bright glacier
#

10

plain atlas
#

damn it

#

was hoping they'd be different lmao

bright glacier
#

what the heck is click doing to set up its streams 👀

#

so complicated

tribal thistle
#

Where are the days of print("ERROR: {e}") lemon_pensive

plain atlas
#

welp i'm going to go mess around with click now

#

even though i have 200 different things on my todo list

#

including one issue with github actions removing a new line that gets added locally....
pre-commit istg

bright glacier
#

only for you obviously

tribal thistle
#

Lmao yeah

#

I'm not sure why

plain atlas
#

smh i can't get figure out why one would use click over argparse, both are equally annoying /srs /hj

tribal thistle
#

What's the value for file in your click?

bright glacier
#

how am I supposed to check that?

#

(sorry, I haven't been paying much attention, been reading click's source code)

tribal thistle
#

Well, one way would be doing what I did and manually modifying the the click code

bright glacier
#

ah yes

#

will do.

#

virtual environments ftw

plain atlas
bright glacier
#

I've only used click because it's what I've been exposed to first (from psf/black duh)

plain atlas
#

i've only used argparse because i was making scripts and didn't want to have many dependencies

bright glacier
#

yea I would use argparse for that too but click is already installed in the majority of my environments lol due to black

#

a never-ending cycle

plain atlas
#

lmao

#

i do have black installed in this environment, along with several other things that use click

bright glacier
#

i'm also gonna take the time to express my happiness for standardized editable installs

#

they're so awesome

plain atlas
#

but for my pre-commit scripts I want to keep dependencies to a minimum

tribal thistle
#

I keep forgetting to run install after each change. Why can't pyproject projects be installed as editable lemon_pensive

bright glacier
#

they can!

tribal thistle
#

Go on lol

bright glacier
#

flit has had support for pep 660 for quite a while now

#

and I use it in development of diff-shades

plain atlas
#

and poetry does that automatically lol

bright glacier
#

just get a pip newer than 21.3.0

#

!pep 660

late dewBOT
#
**PEP 660 - Editable installs for pyproject.toml based builds (wheel based)**
Status

Accepted

Created

30-Mar-2021

Type

Standards Track

plain atlas
#

!pip flit

#

...

#

scale can i make a pr to add pip as an alias to pypi?

bright glacier
#

!pypi flit

plain atlas
#

kthxbai

late dewBOT
tribal thistle
#

Hadn't realized my pip is so out of date

plain atlas
tribal thistle
#

How do I upgrade major version lol

#

Kinda stuck on 21

plain atlas
#

pip install -U pip

bright glacier
#

sorry I wrote the wrong major version

#

pip is also calver

#

year.minor.bugfix

plain atlas
#

what version are you on, scale

tribal thistle
#

I see, alright that's done it

#

I was on 21.3.1 after running install

bright glacier
#

are they awesome 👀

tribal thistle
#

which is why I was confused

bright glacier
#

also lemme actually run with the modified click, was too distracted. ..

#

i'm too distractable

#

@tribal thistle

#

seems like it picked up the right stream on mine

tribal thistle
#

What did you print?

late dewBOT
#

src/click/utils.py lines 249 to 255

if file is None:
    if err:
        file = _default_text_stderr()
    else:
        file = _default_text_stdout()

# Convert non bytes/text into the native string type.```
tribal thistle
#

hm, interesting

bright glacier
plain atlas
#

wtf happened to @toxic storm

bright glacier
#

.ping

toxic stormBOT
#
:ping_pong: Pong!

Gateway Latency: 115ms

plain atlas
#

#bot-commands message

#

it took 10 seconds to respond

bright glacier
#

I guess this means I'll have to monkeypatch click.echo for the time being until we (ever) figure out why click is holding on the original stderr stream like it's the last slice of cake on your machine

plain atlas
#

problem with flushing?

bright glacier
#

well assuming that functools.partial does what I expect lol

#

I doubt it as it's printing to the totally wrong (read: unexpected) stream after the monkeypatching

#

there's nothing printed before the redirection so the buffers should be empty

plain atlas
#

@bright glacier tldr click is a lot easier to use than argparse

#

for simple things, argparse seems the way to go, but add any complexity or subcommands then use click

bright glacier
# tribal thistle hm, interesting

sigh, sorry for dragging you into this mess, what a confusing adventure into streams / file handlers & descriptors and what a mess they are

plain atlas
#

although i can actually see argparse useful for discord bots and adding flags and such to bot commands lol

bright glacier
#

what's even weirder is that I use suppress_output in a different function and click's output is captured as expected

#

even for scale

little parrot
plain atlas
late dewBOT
#

Hey @delicate hatch!

It looks like you tried to attach file type(s) that we do not allow (.pdf). We currently allow the following file types: .gif, .jpg, .jpeg, .mov, .mp4, .mpg, .png, .mp3, .wav, .ogg, .webm, .webp, .flac, .m4a.

Feel free to ask in #community-meta if you think this is a mistake.

sonic mica
#

hi

flat krakenBOT
bright glacier
#

Actually developing in vscode is still rather annoying as 1) my laptop is too slow to run it smoothly, and 2) I have to use the mouse so much more >.< compared to fish + vim

#

LOL - I pasted the totally wrong PAT for the username field and yet GitHub let me in via the password field :p

bright glacier
#

ci is still broken, I guess time to pin coveralls somehow

#

pretty sure it's provided by a docker image the coveralls-upload action uses

tribal thistle
#

You can use the coveralls package from pypi directly

#

It’s basically the same interface, ‘coveralls’

bright glacier
#

the last time I tried to resetup coveralls it was painful (when we had to move off travis)

#

I suppose it's worth trying again 😄

tribal thistle
#

Actually when things last broke for us in pydis, we just disabled failures from that action somehow I can’t fully remember

#

It’s such a pain

#

The coveralls went down completely and we just completely yanked it

#

Probably more a viable solution here, but fun to think about

bright glacier
#

is there a way to allow failure of a specific job step?

tribal thistle
#

Yes but it’ll still be marked red with the cross

bright glacier
#

the whole workflow / job?

tribal thistle
#

Well, it’ll fail just that one step, but that’ll propagate to mark the entire workflow, test suite, commit, and PR as failing

bright glacier
#

cool, so it's not usable then

tribal thistle
#

Basically it’s only good if you want to do the next step even if one fails

#

Yeah lol

tribal thistle
#

The people just loved that

bright glacier
#

"no." - probably

tribal thistle
#

Actually I don’t think that’s an official GitHub representative

bright glacier
#

developing black's action has been painful due to github's lack of quality polish

tribal thistle
#

If you want to allow failures, you might be able to do it on the execution level

#

Configure the failure exit code to be 0, or catch other codes in some other way

dense jungle
#

honestly I'm not sure the coverage action is that helpful anyway

bright glacier
#

the action's output is out of order 99% of the time and on top of that you have to explicitly pass environment variables to the action when a normal workflow doesn't need it

dense jungle
#

how often do we use the results?

bright glacier
#

uhhh usually when you break coverage jelle 😄 /lh

dense jungle
#

I broke it? 🙊

bright glacier
#

No, when you drop it to 0 because obviously your code is just so damn good it needs no tests 😉

#

it's a reference to an exchange in our old messenger chat :)

#

presumably it was actually due to a poisoned cache or something

dense jungle
#

oh yes

plain atlas
bright glacier
#

wait what.

plain atlas
#

or maybe that's the codecov uploader

tribal thistle
#

Uhh considering it had an update like a couple weeks ago

#

And the maintainer is answering issues

bright glacier
#

doesn't seem deprecated to me

#

!pypi coveralls

plain atlas
#

yeah confused with codecov

late dewBOT
plain atlas
#

!pypi codecov

late dewBOT
plain atlas
#

codecov's uploader is deprecated

#

not coveralls

#

right and the reason i don't use coveralls is because A- had problems with it and B- doesn't support coverage 6.0 yet

bright glacier
#

I use codecov for my personal projects as I've had a much better experience with it w/ pypa/bandersnatch

plain atlas
#

just checked it, it apparently does support coverage 6.0 now

plain atlas
bright glacier
#

!pypi codecov

late dewBOT
plain atlas
tribal thistle
#

I mean it’s not deprecated yet

late dewBOT
#

.github/workflows/ci.yml lines 44 to 47

- name: Upload coverage to Codecov
  # If pushed / is a pull request against main repo.
  if: (github.event_name == 'push' && github.repository == 'pypa/bandersnatch') || (github.event.pull_request.base.repo.full_name == 'pypa/bandersnatch')
  uses: codecov/codecov-action@v2.1.0```
tribal thistle
#

Also it’s a matter of just a bit of housekeeping to upgrade

plain atlas
#

the package*

tribal thistle
#

Dude, read:

On February 1, 2022 this uploader will be completely deprecated

plain atlas
#

and the rest of that sentence:

and will no longer be able to upload coverage to Codecov.

tribal thistle
#

I really don’t see how that goes against “it’s not deprecated yet”…

#

Or any part of this conversation

plain atlas
plain atlas
tribal thistle
#

“Yet”

#

I feel like we’re saying the same thing here

plain atlas
#

Yeah

#

it still works, but it won't in 4 months

plain atlas
#

seems like there's an indirect solution

#

depending on how the action is being ran, it may be possible to use an echo to fix it

#

or something

#

like uh

#
# random thing, help me

name: Totally Random Thing

on:
  pull_request:
    types: [created]

jobs:
  build:
    name: Example
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: Upload to coveralls
        run: |
          python -m coveralls ; exit 0
```*this workflow is not complete*
#

something like that

heavy heron
#

python -m coveralls & exit 0 or python -m coveralls & true is usually what I use

flat krakenBOT
#

<!--
Please make sure that the bug is not already fixed either in newer versions or the
current development version. To confirm this, you have three options:

  1. Update Black's version if a newer release exists: pip install -U black
  2. Use the online formatter at , which will use
    the latest main branch.
  3. Or run Black on your machine:
    • create a new virtualenv (make sure it's the same Python version);
    • clone this repository;
    • run pip install -e .[d,python2];
      ...
muted haven
#

Since the pattern matching feature is very experimental at the moment, would it make sense to only change the parser when the target-version is explicitly set greater than 3.10?

tired shard
#

probably

dark orbit
#

can black replace strings like
"abcded...<long string>\npqrs..."
to
"""abcded...
pqrs...
"""?

#

would be useful for my friend, he's getting tons of flake8 line too long warnings because he used \n 💀

lament crow
#

it will eventually split strings but it will do it differently than how you suggested

#

Something like this (I wrote that manually so the split place might be wrong + it depends on the line length limit)

# before
text = "veeeeery long string that could not possibly fit the line length limit without being split in at least two parts"
# after
text = (
    "veeeeery long string that could not possibly fit the line length limit"
    " without being split in at least two parts"
)
#

Personally (as a user, I'm not a maintainer of this project nor do I have any power over what it chooses to do :) ) I would still like some improvements to string processing before it stops being experimental, for example:
https://github.com/psf/black/issues/1467

and there are still some known bugs iirc which is why it's still experimental

GitHub

Describe the style change Black should respect new lines (\n) in strings. Input: message = ( "1. Go to Google Developers Console and log in with your favourite Google account.\n" ...

#

I might be wrong about there still being known bugs, I haven't really been paying attention lately

bright glacier
#

@muted haven sorry about failing CI, I'll look into it when I get back home

flat krakenBOT
#

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

"Trojan Source Attacks" https://www.trojansource.codes/trojan-source.pdf can create a discrepancy between how code looks to reviewers and how it is interpreted by python.

Describe the solution you'd like
black is used by many python projects. It would be great if black could replace "Bidi overrides" with the appropriate escape characters that are visible to humans.

**Describe alternatives you've considere...

errant barn
tribal thistle
#

If you need to test writing code in arabic, well I've got a keyboard or two to help with that 😛

flat krakenBOT
#

If I want to find all instances like [1, 2, 3] and then rewrite them to [ 1, 2, 3 ], is there a good way to get Black to do this? I find the latter to be vastly more readable:

  • Easier to see what the data structure is (e.g. list, tuple, set, etc.)
  • Easier to read the first and last elements
  • Especially easier within the context of function calls, so that it's easier to see that my_func([ 1, 2, 3 ]) is accepting a list as one parameter, rather than three separate parameters.

The...

flat krakenBOT
#

Is your feature request related to a problem? Please describe.
The typical situation where this would be useful:

  1. The code is formatted using Black
  2. This splits a parenthesized expression into multiple lines because it's too long.
  3. The code is refactored.
  4. The parenthesized expression would now fit on a single line.
  5. But Black won't do that change, out of fear the split is intentional.
  6. Each line of the code has to be checked manually to find such occurrences.

**Desc...

tribal thistle
#

An easily findable exhaustive list of flags would be great.
Isn't that just the help command, which is also in the docs

lament crow
#

it's currently not that easily findable in docs but yeah, it is

plain atlas
#

heads up, i ran black and uh

#

wait

#

nope, error is still there

#

(was on 21.8b0, but now on 21.10b0)

#

/home/aru/.cache/pypoetry/virtualenvs/modmail-lmlBH83T-py3.10/lib/python3.10/site-packages/black/init.py:668: DeprecationWarning: There is no current event loop
loop = asyncio.get_event_loop()

#

!d asyncio.get_event_loop

late dewBOT
#

asyncio.get_event_loop()```
Get the current event loop.

If there is no current event loop set in the current OS thread, the OS thread is main, and [`set_event_loop()`](https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.set_event_loop "asyncio.set_event_loop") has not yet been called, asyncio will create a new event loop and set it as the current one.

Because this function has rather complex behavior (especially when custom event loop policies are in use), using the [`get_running_loop()`](https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.get_running_loop "asyncio.get_running_loop") function is preferred to [`get_event_loop()`](https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.get_event_loop "asyncio.get_event_loop") in coroutines and callbacks.

Consider also using the [`asyncio.run()`](https://docs.python.org/3/library/asyncio-task.html#asyncio.run "asyncio.run") function instead of using lower level functions to manually create and close an event loop.

Deprecated since version 3.10: Deprecation warning is emitted if there is no running event loop. In future Python releases, this function will be an alias of [`get_running_loop()`](https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.get_running_loop "asyncio.get_running_loop").
plain atlas
#

Deprecated since version 3.10: Deprecation warning is emitted if there is no running event loop. In future Python releases, this function will be an alias of get_running_loop().

#

seems like a fix would be:

try:
  loop = asyncio.get_running_loop()
except RuntimeError:
  loop = asyncio.new_event_loop()
  asyncio.set_event_loop(loop)
plain atlas
#

...

#

a fix would not be that since black supports 3.6

little parrot
#

I feel like you're better trying asyncio.run first at this point

tribal thistle
#

3.6 is EOLing in like two months anyways 👀

#

5 long years of service

#

In the meantime, could do a check for python version and go off that

red sedge
#

I've got asyncio_backport with a copy of run

#

There's some issues with cancelling async generators though

flat krakenBOT
#

<!--
Please make sure that the bug is not already fixed either in newer versions or the
current development version. To confirm this, you have three options:

  1. Update Black's version if a newer release exists: pip install -U black
  2. Use the online formatter at , which will use
    the latest main branch.
  3. Or run Black on your machine:
    • create a new virtualenv (make sure it's the same Python version);
    • clone this repository;
    • run pip install -e .[d,python2];
      ...
short forge
#

is there any sort of sneaky way to have black change this

if not any(
    expected in value for expected in self.bad_styles[style_name]
):

to something like this

if not any(
    expected in value 
    for expected 
    in self.bad_styles[style_name]
):
lament crow
#

Nope, Black is not configurable

#

If generator expression doesn't fit in one line (per line length limit), it will be split, though not in the way you've shown

short forge
#

so only line length can change how this is shown, right?

errant barn
#

yep, but in your case the rest of the code would look quite ugly if you were to reduce it to, say 40

short forge
#

sad, i really dislike this sort of formatting and reducing line length doesnt always fix it

function(
    super long line that cant be split with magic commas
)
``` is there possibly an issue about this
errant barn
#

We do format things like that if the inner line is within the limit but the outer isn't

#

but no, an issue about making a toggle for that wouldn't be accepted, if you mean doing it earlier than the line length limit

#

hope you understand 😅 like Jack said, Black isn't really configurable

short forge
#

well not a toggle but a trailing comma forces parameters to their own line, i was wondering if theres an equivalent for this

errant barn
#

I might have misunderstood then, could you ellaborate?

short forge
#
def pretty_print(
    count: defaultdict[str, int],
) -> None:
``` this is well within the line limit
short forge
#

so i dont understand why the line length thing is used as an argument here

errant barn
#

Do you want that to not be the case?

#

that it would be formatted like the second one

short forge
#

i want something that would break a *-comprehension to multiple lines, even though its already within the line length limit

errant barn
#

oh I get it, so something akin to the magic comma but for comprehensions

short forge
#

yes

#

does it already exist?

errant barn
#

I don't think so

short forge
#

is it something you guys would be keen on exploring?

errant barn
#

sadly I doubt that it would get accepted either, we are religiously against taking previous formatting into account, the comma being a very rare exception :D

short forge
#

sad but fair

errant barn
#

yeah I know, thanks for understanding

flat krakenBOT
#

Describe the style change

I write python modules that are configured by .yml files which look something like this:

Category_X:
  Subcategory_Y:
    Enable_Condition_Z: true

After reading them in, they are addressed like a nested dictionary (see below). Then I write if clauses that check if a condition is to be checked and if the condition is fulfilled. Black messes that up a bit.

Examples in the current Black style

def black_if_test():
...
flat krakenBOT
#

Describe the bug

Thanks for a great library. When running the following command, black excludes the folders in the regex as expected:

black . --check --exclude 'build'

However, when running this, the exclude pattern is ignored:

black **/*.py --check --exclude 'build'

To Reproduce

In an empty folder:

echo 'print(  1)' >> test.py
mkdir build
echo 'print(  1)' >> build/foo.py

Then running black, gives this output:

# bl...
flat krakenBOT
bright glacier
#

man, it feels good to triage an issue well :)

tired shard
#

review my 2 PRs, it would make you feel even better

graceful magnet
#

how do u change the format

bright glacier
#

Could you elaborate?

#

Black doesn't really provide options to tweak the formatting, there's --line-length, --skip-magic-trailing-comma, --skip-string-normalization (ooh and --experimental-string-processing) and that's it

graceful magnet
#

gotcha

#

but you can change colors right?

bright glacier
#

Colors?

#

do you mean the color in the console output?

graceful magnet
#

yea

bright glacier
#

What's the problem with it currently? Usually you don't see people asking tools to allow configuration of their console output fwiw :)

graceful magnet
#

i just don't like the output colors but it's all cool

bright glacier
#

Yeah, unless there's a real functional problem I'm going to say no to a request to add knobs for the console output colors

graceful magnet
#

true i see what you mean

bright glacier
#

it's not an unreasonable request but it wouldn't be worth the maintenance cost

graceful magnet
#

definitely, also time-consuming as well

#

but no big deal

#

thanks for the help!

flat krakenBOT
flat krakenBOT
bright glacier
#

really ....

#

why is it that just 3.9 is broken?

plain atlas
#

yes

plain atlas
bright glacier
#

seems like it isn't picking up the typed-ast dependency and hence why a bunch of python two tests are failing but I have no idea why

dense jungle
#

Is this because of the typed-ast saga?

bright glacier
#

did they do a release earlier today or something?

dense jungle
#

typed-ast is broken on Python 3.9.8 only because cpython dropped some private API function

bright glacier
#

----------- coverage: platform linux, python 3.9.8-final-0 -----------

#

seems like you're right lol

dense jungle
#

Shantanu is making a release today to get the fix out

plain atlas
#

wait that's 6 days

#

;-;

#

i can't calendar

bright glacier
#

No offense to whoever works on typed-ast but I can't wait until we can drop Python 2 support fully

#

seems like it was a good call to drop Python 2 support soon :)

dense jungle
bright glacier
#

ohi

#

smiles awkwardly

dense jungle
#

though I've been happy to leave most of the actual work to other people, I don't think I've ever really done anything on iit

tribal thistle
#

Jelle you maintain like half the python ecosystem 😅

plain atlas
#

*asottile

plain atlas
#

/srs

#

i swear i see their github account on all of the repos i use

tribal thistle
#

Has coveralls been fixed yet btw

plain atlas
#

pre-commit
flake8
pyflakes
isort
tzdata
pycodestyle
identify
pyupgrade

literally 95% of the pre-commit hooks and shit are maintained by asottile

bright glacier
#

I suppose waiting until the next release is the best course of action @dense jungle ?

#

I'd rather not pin and have it break on some future release of Python 3.10 or whatever

tribal thistle
#

Ah it's been fixed two hours ago

plain atlas
bright glacier
tribal thistle
#

Whenever coverage 6.1 was released

dense jungle
plain atlas
#

oof, black should not use coveralls /hj

dense jungle
#

Or figure out how to do it myself

plain atlas
#

the coverage image on their website

#

is google/yapf

bright glacier
#

I thought you said you didn't have permissions, or do you just have file uploading permissions but no admin?

plain atlas
dense jungle
#

I think I do have permission

bright glacier
#

oh wait I was getting confused with typing-extensions 😔

plain atlas
#

that's what happens when you [know] a power maintainer 😛

dense jungle
bright glacier
#

my internet connection hates me today :(

dense jungle
#

Not just you, I think it's just broken

plain atlas
#

setting up a new .venv be like:
pip install pdbpp ipdb bpython ipython ipykernel flake8 black isort

bright glacier
#

Oh? did the cache configuration break?

#

I thought it was my side as my internet is really slow today, even GitHub is loading slowly when it is usually super fast

dense jungle
#

the profile pictures are 504ing

plain atlas
#

i have not experienced that

bright glacier
#

Ah yeah that's their problem then

#

Also apparently fuzz on 3.9 is broken too .. although I honestly have given this workflow zero attention as I feel like we already have enough bugs to fix 😄

lament crow
#

unless it's just a coincidence they have same last name lol

flat krakenBOT
lament crow
#

both first names start with an A too!

bright glacier
#

my discord notifications lemon_ping

plain atlas
#

and dms ^^

#

lmao ngl when i close an issue i legitimately listen for the discord ping

dense jungle
#

I continue to be impressed by how fast it is

#

Like it shows up in discord before the server request finishes

plain atlas
#

or when i merge, i listen for the sweet ping ping ping, of an issue being closed, a pr being closed, and commits being pushed

plain atlas
#

i see the notification of "issue closed" "pr closed" "new commits" before the page even goes to a loading screen

bright glacier
#

By the way, did GitHub change how workflows are run for pull requests?

plain atlas
#

yes

#

plot twist: its not any faster, but the return result of a merge is actually slow

dense jungle
#

what changed?

bright glacier
#

nothing as far as I can tell

#

I just submitted my pr from a branch on my fork and that behaves differently with CI than I'm used to as I usually use branches on the main repo ever since becoming a maintainer ^^

dense jungle
#

typed-ast 1.5.0 has arrived

bright glacier
#

... did we just discover another CPython bug?

 raise type(err)(
SystemError: compile('delA\\ \n#\n', '<string>', 'single') raised SystemError: Negative size passed to PyUnicode_New
```7
plain atlas
#

another

#

when was the first

bright glacier
tribal thistle
#

It's open on BPO, hitting it here too

bright glacier
bright glacier
plain atlas
#

ah, before this channel

tribal thistle
#

Hm, maybe not, are you using exec? I haven't actually looked too far into it, because the thing I hit it with was using it

plain atlas
#

wish i knew how to comment on that, since it happens on 3.9 too

tribal thistle
#

Do you have a BPO account

plain atlas
#

no lol

tribal thistle
#

The login, and signup is on the left

plain atlas
#

wtf why does it look so weird

tribal thistle
#

What ancient browser are you using lol

plain atlas
tribal thistle
plain atlas
#

OH DARKTHEME

#

aight now it just looks ancient

tribal thistle
#

Well... it sorta is

#

Broken in certain spots too

plain atlas
tribal thistle
#

Such as the issue tracker 🤡

plain atlas
#

fuck

#

...

#

i have some bigger issues now

#

for the fifteenth time

#

i have fucked up my PATH

bright glacier
#

noice

plain atlas
#

i think im gonna go die now

#

my entire path is dead

dense jungle
#

They're working on migrating issues to GitHub for what it's worth

#

Don't know when it'll happen

plain atlas
#

oooh nice

flat krakenBOT
bright glacier
#

!remind 16H open an issue to deal with warnings and set up pytest to fail on new ones as we've gotten bit / close to bitten by missed deprecationwarnings :(

late dewBOT
#
You got it!

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

flat krakenBOT
bright glacier
#

testing out the match pr 😎

tribal thistle
#

Still slow?

bright glacier
#

nope.

tribal thistle
#

Oh nice

#

When was that fixed

bright glacier
#

Honestly I don't know, haven't been able to reproduce it 😅

#

happy to see the match PR isn't actually slowing black down noticeably

#

although I plan to do actual benchmarking so I'll know by then

tribal thistle
#

benchmarking the benchmarking tool? But what benchmarks the benchmarks' benchmarks?

bright glacier
#

diff-shades isn't really a benchmarking tool lol

#

!pypi blackbench

late dewBOT
bright glacier
#

we make for a good maintainer duo @dense jungle 😄

bright glacier
#

@dense jungle I thought supporting parentheized with would also require hacking the tokenizer? .. at least with LL(1) parser tech

dense jungle
#

If I remember correctly Batuhan said earlier that this change would also support parenthesized with

#

I think because he made x as y a node

bright glacier
#

OK this is embarrassing ... I tried this to test it

with (
    open("o-my", "w") as f:
):
    f.wriet("YAY")

and didn't notice the trailing colon in the body >.<

#

I just assumed parser failure == no support for parenthesized with

#

That's probably also worth a call out in the docs

dense jungle
#

oh I also just realized that --safe doesn't work if you're running black on something that's not 3.10 and you try to parse a match statement

bright glacier
#

Yeah although it's the same with all newer syntax in regards to runtime requirements w/ black, no?

dense jungle
#

true, but it confused me for a while 🙂

bright glacier
#

Yup yup, for what it's worth I don't really have Python 3.10 on my machine

#

I mean, I do have a built version of CPython 3.10.0 but like it's soooooooooo slooww

#

I built it with the intention of quickly testing something so basically disabled all optimizations... turns out that's a bad idea even for quick testing.

#

In other news, sadly the deepcopy calls are breaking mypyc support for the PR

dense jungle
#

really, why?

#

I would have thought mypyc could just fall back to pure python calls

bright glacier
#
    self._start_point = copy.deepcopy(self.parser.stack)
/opt/python3.8.5/lib/python3.8/copy.py:146: in deepcopy
    y = copier(x, memo)
/opt/python3.8.5/lib/python3.8/copy.py:205: in _deepcopy_list
    append(deepcopy(a, memo))
/opt/python3.8.5/lib/python3.8/copy.py:146: in deepcopy
    y = copier(x, memo)
/opt/python3.8.5/lib/python3.8/copy.py:210: in _deepcopy_tuple
    y = [deepcopy(a, memo) for a in x]
/opt/python3.8.5/lib/python3.8/copy.py:210: in <listcomp>
    y = [deepcopy(a, memo) for a in x]
/opt/python3.8.5/lib/python3.8/copy.py:146: in deepcopy
    y = copier(x, memo)
/opt/python3.8.5/lib/python3.8/copy.py:210: in _deepcopy_tuple
    y = [deepcopy(a, memo) for a in x]
/opt/python3.8.5/lib/python3.8/copy.py:210: in <listcomp>
    y = [deepcopy(a, memo) for a in x]
/opt/python3.8.5/lib/python3.8/copy.py:146: in deepcopy
    y = copier(x, memo)
/opt/python3.8.5/lib/python3.8/copy.py:205: in _deepcopy_list
    append(deepcopy(a, memo))
/opt/python3.8.5/lib/python3.8/copy.py:172: in deepcopy
    y = _reconstruct(x, memo, *rv)
---------------------
    def _reconstruct(x, memo, func, args,
                     state=None, listiter=None, dictiter=None,
                     deepcopy=deepcopy):
        deep = memo is not None
        if deep and args:
            args = (deepcopy(arg, memo) for arg in args)
        y = func(*args)
        if deep:
            memo[id(x)] = y
    
        if state is not None:
            if deep:
                state = deepcopy(state, memo)
            if hasattr(y, '__setstate__'):
>               y.__setstate__(state)
E               AttributeError: 'Leaf' object attribute '__hash__' is read-only
dense jungle
#

huh why is it trying to set __hash__

bright glacier
#

I have no idea 🤷

bright glacier
dense jungle
#

__hash__ = None # type: Any # For Py3 compatibility.

#

I think we can just remove that line. The class defines __eq__, which means it already implicitly has __hash__ = None

#

__hash__ inheritance is weird

#

also mypyc doesn't build for me 😦 ```/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/_stdio.h:93:16: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
unsigned char *_base;
^

#

which sounds like a very pedantic error

bright glacier
#

🤷 I don't use macos

#

fwiw I had to switch out gcc for clang to get it working on linux so you're not alone in the weird compiler errors

dense jungle
#

do you know if there's a way to control what compiler options get passed to the C compiler?

bright glacier
#
Python 3.8.5 (default, Sep  9 2020, 23:45:44) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import black.parsing
>>> node = black.parsing.lib2to3_parse("a")
>>> node.children[0].children[0]
Leaf(NAME, 'a')
>>> node.children[0].children[0].__mypyc_attrs__
('_prefix', 'bracket_depth', 'column', 'fixers_applied', 'lineno', 'opening_bracket', 'used_names', 'value', '__hash__', 'children', 'parent', 'type', 'was_changed', 'was_checked')
>>> node.children[0].children[0].__getstate__()
{'_prefix': '', 'column': 0, 'fixers_applied': [], 'lineno': 1, 'value': 'a', '__hash__': None, 'children': [], 'parent': Node(simple_stmt, [Leaf(NAME, 'a'), Leaf(NEWLINE, '\n')]), 'type': 1, 'was_changed': False, 'was_checked': False}

This is what I get with compiled black, seems like __hash__ is treated like a normal attribute?

dense jungle
#

yeah that makes sense with how mypy normally works

bright glacier
dense jungle
#

I'd recommend just removing the __hash__ = None

#

or maybe annotating it as a ClassVar will help

dense jungle
#

this worked CFLAGS='-Wno-expansion-to-defined -Wno-nullability-completeness -Wno-undef-prefix' BLACK_USE_MYPYC=1 python setup.py build

bright glacier
#

Huh, interesting

dense jungle
#

also, typical Apple to have their compiler provide checks that fail on their own system headers

bright glacier
#
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/home/ichard26/.local/share/virtualenvs/black-Q9x7i-w-/lib/python3.8/site-packages/mypyc/lib-rt -Ibuild -I/home/ichard26/.local/share/virtualenvs/black-Q9x7i-w-/include -I/opt/python3.8.5/include/python3.8 -c build/__native_f4ee935d5338f3d318fb.c -o build/temp.linux-x86_64-3.8/build/__native_f4ee935d5338f3d318fb.o -O3 -Werror -Wno-unused-function -Wno-unused-label -Wno-unreachable-code -Wno-unused-variable -Wno-unused-command-line-argument -Wno-unknown-warning-option -Wno-unused-but-set-variable
build/__native_f4ee935d5338f3d318fb.c: In function ‘CPyDef_linegen___LineGenerator_____post_init__’:
build/__native_f4ee935d5338f3d318fb.c:98746:21: error: stray ‘\303’ in program
98746 |     PyObject *cpy_r_��;
      |                     ^
build/__native_f4ee935d5338f3d318fb.c:98746:22: error: stray ‘\230’ in program
98746 |     PyObject *cpy_r_��;
      |                      ^
build/__native_f4ee935d5338f3d318fb.c:99025:11: error: stray ‘\303’ in program
99025 |     cpy_r_�� = cpy_r_r8;
      |           ^
build/__native_f4ee935d5338f3d318fb.c:99025:12: error: stray ‘\230’ in program
99025 |     cpy_r_�� = cpy_r_r8;
      |            ^
build/__native_f4ee935d5338f3d318fb.c:99360:58: error: stray ‘\303’ in program
99360 |     PyObject *cpy_r_r110[3] = {cpy_r_v, cpy_r_r98, cpy_r_��};
      |                                                          ^
build/__native_f4ee935d5338f3d318fb.c:99360:59: error: stray ‘\230’ in program
99360 |     PyObject *cpy_r_r110[3] = {cpy_r_v, cpy_r_r98, cpy_r_��};
      |                                                           ^
build/__native_f4ee935d5338f3d318fb.c:99403:59: error: stray ‘\303’ in program
99403 |     PyObject *cpy_r_r122[3] = {cpy_r_v, cpy_r_r116, cpy_r_��};
      |                                                           ^

okayyy wow gcc really doesn't like mypyc's code

dense jungle
#

fun fact on macos gcc is actually clang

#
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 13.0.0 (clang-1300.0.29.3)
Target: x86_64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
bright glacier
#

to be fair those identifiers look suspicious as heck but if clang accepts it uhh it makes gcc look unforgiving :)

bright glacier
dense jungle
#

is that from where we use an empty set character as an identifier for the empty set?

bright glacier
#

Pretty sure there's an issue on the mypyc tracker noting how gcc really hates unicode identifiers

dense jungle
bright glacier
#
diff --git a/src/black/nodes.py b/src/black/nodes.py
index 6e5c235..47c877f 100644
--- a/src/black/nodes.py
+++ b/src/black/nodes.py
@@ -20,6 +20,8 @@ if sys.version_info >= (3, 8):
 else:
     from typing_extensions import Final
 
+from mypy_extensions import mypyc_attr
+
 # lib2to3 fork
 from blib2to3.pytree import Node, Leaf, type_repr
 from blib2to3 import pygram
@@ -142,6 +144,7 @@ ALWAYS_NO_SPACE: Final = CLOSING_BRACKETS | {token.COMMA, STANDALONE_COMMENT}
 RARROW = 55
 
 
+@mypyc_attr(allow_intepreted_subclasses=True)
 class Visitor(Generic[T]):
     """Basic lib2to3 visitor that yields things of type `T` on `visit()`."""
 
diff --git a/src/blib2to3/pytree.py b/src/blib2to3/pytree.py
index 3af2833..39ff481 100644
--- a/src/blib2to3/pytree.py
+++ b/src/blib2to3/pytree.py
@@ -91,8 +91,6 @@ class Base(object):
             return NotImplemented
         return self._eq(other)
 
-    __hash__ = None  # type: Any  # For Py3 compatibility.
-
     @property
     def prefix(self) -> Text:
         raise NotImplementedError

That's not bad as a fix lemon_happy

#

wait a second, I typo-ed the mypyc_attr didn't I... how it working then?

#

eh, I'll continue with this tomorrow. Thanks @dense jungle for the help!

#

Hopefully we can land the match PR and mypyc PR soon 🤞 (this weekend is going to be busy as heck for me tho)

dense jungle
mint barn
#

hellllllo

willow zenith
#

hello

flat krakenBOT
#

Describe the bug

Black thinks that a file containing a syntax error is well formatted.

To Reproduce

With a file containing just this code:

{
    f"{",
}

Black does not give an error:

$ black bad.py 
All done! ✨ 🍰 ✨
1 file left unchanged.

But there is a syntax error in the file:

$ python file.py 
  File "/home/inglesp/file.py", line 2
    f"{",
        ^
SyntaxError: f-string: expecting '}'

**Expected beha...

#

Given that we'll be dropping Python 2 support in 2-3 months I don't think we'll need to do much in terms of letting folks know PyPy doesn't support Python 2. Perhaps we should notice when our built-in parser (which has excellent cross-version syntax support; ignoring parenthesized with and pattern matching -> #2586) falls back to the Python 2 grammar but we can deal with that later as isn't strictly related to PyPy compatibility.

late dewBOT
flat krakenBOT
bright glacier
#

i- ... how am I the most prolific contributor since May 2019 ?!

#

I very much don't remember making 72 commits :)

dim haven
#

Where's the full documentation for all the configuration options in the pyproject.toml file for black?

#

I don't find it :/

#

For example, I want to configure the tab size

bright glacier
#

running black --help nets 98% of the available options usable in pyproject.toml tho

bright glacier
dim haven
#

Noooo, yikes!

dense jungle
#

We don't support configuring indentation size though, and we are not going to add it

#

Black is meant to be opinionated and non-configurable

dim haven
#

Damn. My preferences are tab size 2. How come you don't want to make it so I'm able to set it to 2 instead

bright glacier
#

The main ethos and appeal behind Black is that it isn't configurable. Yapf is on the other side of the spectrum, it's rather configurable ^^

dim haven
#

There's a lot of tools, I'm sure I can set it to 2 afterwards though, so I think it's not a big deal, now that I think of it

#

Hm, now I wonder how do I find such a tool. "Tool that looks in all your files and makes them tab size 2"

bright glacier
#

!pypi indentpy - perhaps?

late dewBOT
bright glacier
#

hmmm

#

seems rather out of date in terms of packaging standards, it suggests installing from github even when it's on PyPI?

#

I still need to write up the document explaining how people can test the wheels but at least the feedback collection bit should be ready :)

#

Gotta say the new issue forms are looking pretty nice even if the UX creating them wasn't the easiest thing to get used to!

lament roost
#

is formatting like this intentional? I don't quite get what it's trying to do

AHK_TEMPLATE = Template(
    """\
stdin := FileOpen("*", "r")

${hotkey}::
    while not stdin.AtEof
    {
        system := Trim(stdin.ReadLine(),"`n ")
    }
    ${user_script}
"""
)
bright glacier
#

I assume no? Pretty sure there's reports on the tracker about this

lament roost
#

ah, I searched with a space in multiline

bright glacier
#

GitHub search is a mysterious thing sometimes 😄

lament roost
#

I guess it's indenting the opening quotes because of the parentheses?

bright glacier
#

yeah and then it dedents the closing quotes because the logic probably assumes it'd be indented and broken up later i.e. fixed (except that's impossible for multiline string literals)

dense jungle
#

The closing quote is dedented because doing anything else would change the contents of the string literal

dim haven
bright glacier
dense jungle
bright glacier
#

Yeah I still need to write those docs - good point on explaining what it is and linking to relevant docs

#

I might also give it less prominence in the form, perhaps I'll integrate it into the "additional commentary" bit

plain atlas
#

mm

#

@bright glacier very nice commit message 😅

late dewBOT
#

:incoming_envelope: :ok_hand: applied mute to @wide warren until <t:1636798652:f> (9 minutes and 58 seconds) (reason: duplicates rule: sent 4 duplicated messages in 10s).

regal crest
#

Hey, might not be the place for this, but I'm a big fan of the black formatter, I recently started learning javascript, does anyone know if there's a similar tool for js? Not sure how to search for it haha

tribal thistle
#

Prettier is pretty popular

silent apex
#

^, or running eslint with the --fix cli option can be really nice, although it takes some configuration

red sedge
#

I use eslint Airbnb it's pretty nice

#

prettier is great too

flat krakenBOT
flat krakenBOT
#

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

One of the reasons I use black is so that I can focus on code without having to focus on style. #1824 introduced a --skip-magic-trailing-comma flag to further control style. However, there's no way to set this flag in a config file, so the file format will change depending on whether or not a contributor uses the flag.

Describe the solution you'd like

I would like to be able to set this in a config file like `py...

livid fjord
#

hey can one of you help me figure out how to apple the finctions of import os and import os.path to my hw? thanks

flat krakenBOT
#

When you have vim builded with Python 3.10 the black plugin will fail when running :BlackUpgrade or :Black

Error detected while processing /home/michal/.vim/bundle/black/autoload/black.vim:
line 201:
:5: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives

I am able to fix the issue by removing from distutils.util import strtobool from autoload/black.vim and re-implementin...

bright glacier
#

caching is fun to implement :)

bright glacier
#

Should we test PyPy 3.8 or shall we do that later @dense jungle ?

dense jungle
#

it's unreleased, right?

bright glacier
#

Also related, how does requires_python work with PyPy?

dense jungle
#

need to read up on that

bright glacier
dense jungle
#

I have no idea

dense jungle
#

Also I'm hoping to merge your mypyc PR too, looking at a few others right now

bright glacier
#

I'm just worried someone on PyPy 3.6 will attempt to install black and pip won't complain that we aren't compatible

#

Although it seems like PyPy 3.7 is the oldest series still supported by upstream so I guess it's fine regardless

dense jungle
#

Are we not compatible though? Honestly most of the time these things just work (though I have little experience with pypy)

bright glacier
#

It would probably take a lot of changes to fix the failures for pypy3.6. Since that wouldn't really be in the spirit of this PR I removed it from the list of targets.

dense jungle
#

Oh I see, was confused with 3.8

bright glacier
#

locally yes

#

I'm not ready to start community testing yet but might as well merge it now to avoid more conflicts :)

dense jungle
#

yeah was just going to say that

#

even if the wheels still need some work it's good to get the PR in because we definitely want those changes

plain atlas
bright glacier
#

what?

plain atlas
#

draft prs

bright glacier
#

Yea... but isn't this whole discussion all about merging the PR early to avoid conflicts?

plain atlas
#

ohhhh

#

you said merge it now... ;-;

plain atlas
dense jungle
#

Yeah please push the local changes to get it mergeable and then we can hit the big button

bright glacier
#

I'm undecided but in general this seems way too niche

dense jungle
#

Also seems possible to write a tool that just calls black --diff and turns the output into the desired format

bright glacier
#

what's the value of adding a changelog entry to psf/black#2562 ?

toxic stormBOT
dense jungle
#

Telling users that they can run black under 3.10

bright glacier
#

Fair although runtime support already existed and the 3.10 syntax is already in the changelog 😄

bright glacier
#

Man are the pypy tests slow on the already slow macos environment

plain atlas
#

lol the macos are ran on github's cloud

bright glacier
#

Isn't PyPy supposed to be faster overall? I wonder what's holding it back.. is the built-in ast module really slow or something?

plain atlas
#

although... technically azure and gh's cloud is the same owner

plain atlas
dense jungle
bright glacier
#

Hmm to be fair the PyPy tests are running in a subprocess to work around a bug apparently

dense jungle
#

I wish github would sort the checks by their status so I don't have to scroll scroll scroll to find the one that's failing

plain atlas
#

hmm, this might be an #internals-and-peps question but how is jit faster if cpython compiles them to start with?
Wouldn't the short time wasted with compiling be faster once it starts running it?

bright glacier
#

I have basically no knowledge of JITs but given how much test data we throw at black during the test run I'd've assumed it would be warmed up enough

plain atlas
#

them = the written code in python to be ran

dense jungle
#

Though broadly while CPython does have a compile step, it "compiles" to a very high-level language (CPython bytecode), while PyPy's JIT can compile to machine code

bright glacier
#

is there a way to apply a patch generated from git show HEAD -p? git am didn't like the file

#

I can always use git apply and then do a manual commit but the whole point of using the patch flag was so I didn't need to do that

dense jungle
#

git apply?

bright glacier
#

wow my github inbox is already spammed

#

what a lovely problem to have knowing what it signifies😄

dense jungle
plain atlas
#

Seems good to me now that Jelle got his edit in as well! So how bout a merge?

#

@dense jungle what pronouns?

dense jungle
plain atlas
#

👌

bright glacier
plain atlas
#

gotcha

bright glacier
#

I guess it doesn't hurt merging the tiny PR

dense jungle
#

Honestly this seems just redundant then

#

It's right on the next line

bright glacier
#

For some reason I'd feel really bad closing it myself :)

bright glacier
#

Re. psf/black#1879 I just assumed we would merge and enable the formatting this before the stable policy goes into effect but I'm OK with putting it under the --future(?) flag

dense jungle
#

Mostly because that means when I upgrade black at Quora I have to reformat a bunch of code

bright glacier
#

Ahaha that's fair no worries

#

I'm over here using # fmt: on/off more than I have ever used to so I'm on the other side of the spectrum

dense jungle
bright glacier
#

We just haven't yet

dense jungle
#

Let's do it then

#

done

bright glacier
#

I was in the middle of doing that, but I got slowed down by 1) doing a clean clone, and 2) I totally forgot what git commands I had to run

#

You can mostly blame pipenv lock for why I do clean clones so much more often these days

bright glacier
#

I was opening it when you said "done" 😄

#

I suspect Shivansh-007's PRs might take a while to get reviewed and landed ... they touch more than I initially expected

dense jungle
#

We can maybe move forward with the --verbose one, I would want to look at it more before I do anything

bright glacier
#

Yeah that's my overall feeling too, seems good on paper but the implementation and design decisions probably need some work

#

oh for goodness sake the pypy PR caused more merge conflicts on the mypyc PR

dense jungle
#

oh no, I'm sorry 😦

flat krakenBOT
flat krakenBOT
flat krakenBOT
flat krakenBOT
flat krakenBOT
bright glacier
#

No worries :)

plain atlas
bright glacier
#

Uh what?

plain atlas
#

like

plain atlas
dense jungle
#

I think he was just referring to merge conflicts 🙂

flat krakenBOT
#

The implementation of the new backtracking logic depends heavily on deepcopying the current state of the parser before seeing one of the new keywords, which by default is an very expensive operations. On my system, formatting these 3 files takes 1.3 seconds.

 $ touch tests/data/pattern_matching_*; time python -m black -tpy310 tests/data/pattern_matching_*             19ms
All done! ✨ 🍰 ✨
3 files left unchanged.
python -m black -tpy310 tests/data/pattern_matching_*  2,09s user 0,04s...
flat krakenBOT
#

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

I plan to start using Python 3.10 and wonder what I can specify as --target-version!?

Describe the solution you'd like

black --help shall list how I specify a Python 3.10 target version.

Describe alternatives you've considered

I installed Pyrhon 3.10 and the latest black version to see if black --help lists an appropriate target version.

Additional context

I looked through open issues h...

bright glacier
#

FWIW there's a hotfix for -t py310 we need to do before releasing 21.11b0

#

currently only the match statement is attached to that TargetVersion when a bunch more features need to be attached

dense jungle
#

we also may not support PEP 614 (decorator syntax) but that was already in 3.9

bright glacier
# dense jungle hm what else? parenthesized with?
~/programming/oss/black on main [$?⇡] via Python v3.8.5 (black) 
❯ black test.py --diff --color -q
--- test.py    2021-11-15 21:31:38.652666 +0000
+++ test.py    2021-11-15 21:32:00.444694 +0000
@@ -1,2 +1,6 @@
-def daylily(this_is_a_long_parameter_name_because_i_am_testing, something, **related_to_target_version_py310):
+def daylily(
+    this_is_a_long_parameter_name_because_i_am_testing,
+    something,
+    **related_to_target_version_py310,
+):
     pass

~/programming/oss/black on main [$?⇡] via Python v3.8.5 (black) took 427ms 
❯ black test.py --diff --color -q -t py310
--- test.py    2021-11-15 21:31:38.652666 +0000
+++ test.py    2021-11-15 21:32:04.028799 +0000
@@ -1,2 +1,6 @@
-def daylily(this_is_a_long_parameter_name_because_i_am_testing, something, **related_to_target_version_py310):
+def daylily(
+    this_is_a_long_parameter_name_because_i_am_testing,
+    something,
+    **related_to_target_version_py310
+):
     pass

notice how the second call with --target-version py310 doesn't add a trailing comma?

late dewBOT
#

src/black/mode.py lines 102 to 115

TargetVersion.PY39: {
    Feature.UNICODE_LITERALS,
    Feature.F_STRINGS,
    Feature.NUMERIC_UNDERSCORES,
    Feature.TRAILING_COMMA_IN_CALL,
    Feature.TRAILING_COMMA_IN_DEF,
    Feature.ASYNC_KEYWORDS,
    Feature.ASSIGNMENT_EXPRESSIONS,
    Feature.RELAXED_DECORATORS,
    Feature.POS_ONLY_ARGUMENTS,
},
TargetVersion.PY310: {
    Feature.PATTERN_MATCHING,
},```
dense jungle
#

Oh I see, we should just add the 3.9 stuff in there too

bright glacier
#

Mhmm

red sedge
#

POS_ONLY_ARGUMENTS is a humorous name

old spruce
#

can black read from stdin / print to stdout?

bright glacier
#

yes!

#

echo "print('daylily')" | black - > out.py

old spruce
#

nice, seems to work. I'm trying to work out a simpler integration with vim, since vim-black seems to break whenever I upgrade my python version

#

nnoremap <buffer> <F5> :%! black - --quiet 2>/dev/null <CR> this works, but it moves my cursor to the top of the buffer (understandable) so I'll try to tackle that next, but it's a vim question 🙂

slow ibex
#

sublack (black plugin for sublime text) with option "black_on_save": true, sometimes freezes sublime forever
with "black_on_save": false, everything is ok (sublime not freezes after formatting)

lament crow
#

You should report this issue to the plugin author as it's not maintained by the same people that maintain Black

#

Btw, LSP can be used for auto-formatting too if you set it up with pylsp server

slow ibex
bright glacier
#

I don't recall seeing them here

lament crow
#

nope, that's not the package they were talking about

bright glacier
#

I guess the main problem with emitting parenthesized withs starting from 3.9 would be that the code wouldn't be safe for other Python implementations as it was technically an implementation detail in that feature version. Otherwise I'd say ignoring the undocumented nature of it is probably fine.

#

We could keep the detection code and use it as a marker of 3.9+ but then don't emit parenthesized withs until -t 3.10 but that's rather hacky and I don't even know if we pass enough state for that to work.

dense jungle
#

yes. I guess that's mostly a theoretical problem since pypy is still working on 3.8

#

though I suspect they'd aim for bug-for-bug compatibility with CPython and support parenthesized with

flat krakenBOT
bright glacier
#

They in general do aim for bug-for-bug compatibility but there's more implementations of Python than just PyPy and CPython at this point

bright glacier
# flat kraken

What did you want me to review in particular w/ this by the way? I got distracted writing this detection code.. would've reviewed after.

dense jungle
#

oh yes I did and then forgot about it and merged anyway. mostly wanted to make sure this didn't interfere with any of your blib2to3 changes

flat krakenBOT
bright glacier
#

I'll update 3.10's features to include the ones from 3.9 and then I'll check the mypyc branch and hopefully fix the PyPy issues as well

dense jungle
#

And then we merge it and make a release

bright glacier
#

sounds good to me

tired shard
#

Jelle wdym by https://github.com/psf/black/pull/2525#discussion_r749860027

If we have test_replace.toml (root)

[tool.black]
config = "_black_config.toml"
verbose = 0
color = false

and _black_config.toml

[tool.black]
verbose = 1
color = true

The resulting owuld be verbose = 1 and color = True... that's what the comment says

dense jungle
#

I mean that we should do the opposiite

flat krakenBOT
tired shard
#

that's what me, richard and felix agreed with 🤷‍♂️

bright glacier
#

I don't know honestly, I haven't taken a look at your PRs in a long while and I've forgotten most of the context

dense jungle
#

I'm struggling to see a good use case for the current behavior

dense jungle
tired shard
#

maybe we can document that behaviour in the docs?

bright glacier
#

Sigh, OK I do see Jelle's point now. It would be confusing at best

dense jungle
#

that's what i wrote on the PR 🙂 I still feel overwriting the other way makes more sense though, assuming it's not too hard to implement

bright glacier
#

To be honest I already have a hard enough time figuring out how our configuration system works and I didn't want to add another merge rule on top of all of it :p

dense jungle
#

we need a merge rule either way

tired shard
#

nope.. not hard... should be 2 lines change

bright glacier
#

Fair. I guess if a config file contains --config PLUS other configuration, any configuration from --config overwrites the parent config?

#

I kinda need to make myself a diagram to check I'm not misunderstanding here 😅

bright glacier
#

alright I'm just as confused then

dense jungle
#

So the original use case here was someone who has a ton of different Python projects in some sort of shared structure

#

They want a single shared config file for the megaproject, then just write config = ../parent/pyproject.toml in all the other subprojects

#

Then it seems most helpful to me that they can adjust some config options in the per-project config files

tired shard
#

ok, i see your point... root config should be highest level in that case, yeah

bright glacier
#

OK, so merging all the way then I suppose

dense jungle
#

what's our current behavior when you have both a config file and a command-line option?

tired shard
#

commnad line option is highest level

bright glacier
#

CLI -> project-root-config / CLI --config -> any nested --configs -> ... -> defaults

#

so this is the proposed flow, correct?

dense jungle
#

good, I feel like the behavior I'm proposing is consistent with that

#

the most specific config wins

tired shard
#

yeah richard

bright glacier
#

Alright, fwiw I'm going to want some decent tests for this as there's a lot of ways this could go wrong :)

dense jungle
#

Yep and we should still document it

tired shard
#

👍

bright glacier
#

Gosh I just realized this would get immensely confusing if we added automatic nested pyproject.toml support

#

hopefully we won't have to do that with nested configs but oh dear that'd suck

#

Well explicit nested configs wouldn't work as 100% complete workaround for implicit nested pyproject.toml support.

#

I was going to explain why it isn't a perfect workaround but I got too confused trying to explain it 😅

tired shard
#

Can I add another argument to read_pyproject_config saying return_config_dict, which would return the config early (before setting it to ctx.default_map

#

it would make the implementation easier

bright glacier
#

ughhhh I'm soo confused about this feature

bright glacier
#

anyway it's far too late for me to be thinking about this -- I'll think about this later when I'm not a little tired

#

I should get up and take a break from screens ... cya y'all for a little bit

tired shard
#

cya

dense jungle
bright glacier
#

Oh yeah and I forgot we supported user level configuration

bright glacier
#

@dense jungle assuming the mainline tests succeed (not too worried about primer tbh) in particular the PyPy ones, let's merge psf/black#2431 for once and all

toxic stormBOT
tired shard
#

HOw do you make a note tag in the docs?

bright glacier
#
```{note}
```
tired shard
late dewBOT
#

You are not allowed to use that command here. Please use the #bot-commands channel instead.

tired shard
#

smh

bright glacier
#

```{note}
```

tired shard
#

k ty

dense jungle
tired shard
#
If you are using the linked configuration feature i.e. have `config` in your black configuration,
the root config values i.e. the config values found in the file which was containing the `config`
the key would overwrite them.

Sounds confusing... any way to word it better

dense jungle
#

I feel like we need a precise term for each of the two config files involved

#

Child and parent config?

tired shard
#

Linked configuration sounds more obvious IMO

bright glacier
#

I was wondering, what should we do for CI once we start enforcing no formatting changes and support the --future flag? Ideally we would have two sets of jobs, one where it'd error out if any changes were detected between main and the PR, and another where it'd show the formatting changes if the --future flag was passed but given we're already maxing out our CI resources that would easily slowdown CI a lot.

tired shard
#

and parent config for the root config containing the config value

bright glacier
#

The reason why I'm suggesting two sets and not two jobs or whatever is that Cooper likes to run primer (although in this case it'll be diff-shades) against the whole testing matrix if possible to discover environment-specific bugs. It's a fair argument and is generally doable for now, but doubling the job count / workload per job to support the two modes would suck.

flat krakenBOT
dense jungle
#

I would be fine with dropping a few builds. Maybe we can drop the coveralls builds, and run macos/windows on only one Python version each.

bright glacier
#

It seems like the only workable solution for now. 20 free jobs is great, but kinda limiting for projects of our size unfortunately :(

#

Anyway this is one more thing to add to my list of "I need to think through this more and come with a more fleshed out proposal or summary" 😄

#

You delete the squashed commit message jelle?

#

it's not a big deal as no one will be reading that but it seems unnecessary to drop the context :)

dense jungle
flat krakenBOT
#

Description

To avoid this situation:

~/programming/oss/black on main [$?⇡] via Python v3.8.5 (black) 
❯ black test.py --diff --color -q
--- test.py    2021-11-15 21:31:38.652666 +0000
+++ test.py    2021-11-15 21:32:00.444694 +0000
@@ -1,2 +1,6 @@
-def daylily(this_is_a_long_parameter_name_because_i_am_testing, something, **related_to_target_version_py310):
+def daylily(
+    this_is_a_long_parameter_name_because_i_am_testing,
+    something,
+    **related_to_targ...
bright glacier
#

Is there anything else we need to merge or should we release 21.11b0 soon?

#

I can't think of anything important or useful-enough to warrant extra attention.

dense jungle
#

I don't think so. Let's do a release tomorrow?

bright glacier
#

Sure, I'll be rather busy for first half of the day tomorrow but I don't expect many fires for this release

flat krakenBOT
tired shard
dense jungle
tired shard
#

config

plain atlas
#

what kind of configuration is this gonna be? wait-- use me as a fresh set of eyes on this when you have something that makes sense and i'll see if i can understand what it does 😛

dense jungle
#

a pyproject.toml file

#

file A has config = ./path/to/fileB.toml

plain atlas
#

ping me when you have it figured out

dense jungle
#

what do we call file A and file B when we explain the behavior?

tired shard
#

A is the parent file and B is the linked configuration file

muted haven
tired shard
#

@plain atlas Done, see the docs change of psf/black#2525

toxic stormBOT
red sedge
#

ah the whole toml CR thing is amazing

tired shard
#

CR full form? (Google didn't help)

red sedge
#

it's a problem if you open a file in text mode and pass it to tomli

#

because python normalized LF CRLF and CR to \n

mint barn
flat krakenBOT
gaunt pecan
#

does black not support match case?

dense jungle
gaunt pecan
#

how do I update to the main branch?

dense jungle
little parrot
#
pip install -U "black @ git+https://github.com/psf/black@main"
gaunt pecan
dense jungle
#

probably need to pip install wheel first

#

or just wait for tomorrow and install the new version of black

bright glacier
#

Shall we do it in 40 minutes or whenever I get home? 😄

dense jungle
#

apparently I broke the vim plugin, that PR needs to get merged

#

in a couple hours I can figure out how to install the plugin to test my fix

bright glacier
#

ah, fair enough - waiting for a review from a vim user?

dense jungle
#

yes

bright glacier
#

(and no I don't count as I've never really looked into vim plugins)

dense jungle
#

me neither but I just pattern matched the code 🙂

flat krakenBOT
dense jungle
#

ok, @bright glacier release time?

bright glacier
#

sure!

dense jungle
#

I can prepare it

dense jungle
bright glacier
#

Our wheel sizes are getting so much bigger from what I remember

dense jungle
#

155 kb isn't too bad

bright glacier
#

not that it matters at sub-metabytes levels but :p

#

metabytes 😔

#

Probably a term used at FB

#

Thank you for doing the release by the way @dense jungle !

dense jungle
#

the instructions make it very easy

flat krakenBOT
#

Describe the bug
black failed to format all single quotes in the dict as double quotes

To Reproduce
For example, take this code:

xpath_dict = {
    'login_page': '//*[@id="top_nav"]/nav/ul/li[5]',
    'account': '//*[@id="dlg_login"]/form/div[1]/div[1]/table/tbody/tr[1]/td[2]/input',
    'password': '//*[@id="dlg_login"]/form/div[1]/div[1]/table/tbody/tr[2]/td[2]/input',
    'login': '//*[@id="dlg_login"]/form/div[1]/div[2]/input[1]',
    '三楼北区': '//*[@id="item_...
plain atlas
#

Thanks to black, I can write my code as bad as I want

#

and black will turn it into this neat pile

mint barn
lament crow
#

the original really doesn't look that bad, ye LUL
Not to say that if I had to look at that code, I wouldn't be a bit annoyed by its formatting :P

slow ibex
glacial drum
#

So I've noticed black formats code like this ```py

my_code = """
... @whitelist.command(name="remove", aliases=("delete", "rm",))
... def foo(ham: int):
... pass
... """
from black import format_str, FileMode
print(format_str(my_code, mode=FileMode()))
@whitelist.command(
name="remove",
aliases=(
"delete",
"rm",
),
)
def foo(ham: int):
pass

#

Is this expected and/or configurable?

#

If the first question is yes I am guessing the second is no anyway 😄

little parrot
#

Yes this is expected

#

It's got a trailing comma so it gets exploded

glacial drum
#

aha, right, thanks 😄

dense jungle
#

The --skip-magic-trailing-comma argument turns this behavior off

glacial drum
#

Thanks 😄

flat krakenBOT
#

Describe the style change

When using conditional imports, if the next line is on the same indentation level, should there be an indent? My experience has been that when I have used a conditional import, its normally followed by 1 or 2 lines, and I am always surprised when I see Black add a space between them.

Examples in the current Black style

if settings.ENABLE_DEBUG_TOOLBAR:
    import debug_toolbar

    urlpatterns.append(path('__debug__/', include(debug_t...
red sedge
#

I like how each of the flags for black are arguments

flat krakenBOT
#

Latest 21.11b01 release includes https://github.com/psf/black/commit/117891878e5be4d6b771ae5de299e51b679cea27#diff-431968a04535c5ee2570855fe3a3473527050ed0e6d5cb5a9544bcef254d0590 which references the regex.Pattern class.

But this was only added in regex==2021.4.4 and black depends on regex>=2020.1.8 so running with an older regex version gives..

AttributeError: module 'regex' has no attribute 'Pattern'
dense jungle
#

^ that seems worthy of a hotfix release

bright glacier
#

ignoring pipenv I suppose? lol

plain atlas
#

use poetry

bright glacier
#

That's not a short term solution arl

tired shard
#

even the pipenv needs to be updated ig ^

#

">=2020.1.8" won't work

plain atlas
bright glacier
bright glacier
plain atlas
#

ah

#

delegate someone else to do it

tired shard
#

yeah samething, it didn't load when I was typing for some reason

dense jungle
plain atlas
plain atlas
#

yknow

#

does pipfile.lock even need to be commited?

dense jungle
#

it's kind of the point. I guess it ensures a consistent dev environment

silent apex
#

That's the entire point of a lockfile, is it not? To ensure consistency across dependency installs?

dense jungle
#

but to be honest I've never used it, and it doesn't really seem worth the pain it's causing

plain atlas
#

I'd argue given that black is for consumers, since its versions are not pinned strictly in the requirements.txt, it means that the dev environment is better than the actual consumer environment

plain atlas
bright glacier
#

It'll be annoying but I got the know how 😄

plain atlas
#

looks mostly fixed, but that added these?
added appnope at v 0.1.2
added matplotlib-inline??

bright glacier
#
  File "/home/ichard26/programming/oss/3.6venv/lib/python3.6/site-packages/pipenv/utils.py", line 917, in _get_hashes_from_pypi
    session = _get_requests_session(self.project.s.PIPENV_MAX_RETRIES)
  File "/home/ichard26/programming/oss/3.6venv/lib/python3.6/site-packages/pipenv/utils.py", line 66, in _get_requests_session
    import requests
  File "/home/ichard26/programming/oss/3.6venv/lib/python3.6/site-packages/pipenv/vendor/requests/__init__.py", line 48, in <module>
    from pipenv.vendor.charset_normalizer import __version__ as charset_normalizer_version
  File "/home/ichard26/programming/oss/3.6venv/lib/python3.6/site-packages/pipenv/vendor/charset_normalizer/__init__.py", line 30, in <module>
    import pipenv.vendor.charset_normalizer.api as CharsetDetector
AttributeError: module 'pipenv.vendor' has no attribute 'charset_normalizer'
✘ Locking Failed!
#

nvm pipenv locking still sucks even w/ way too much experience

flat krakenBOT
dense jungle
#

@bright glacier @neon loom (and anybody else listening in) do you agree this is worthy of a hotfix release?

bright glacier
#

It's simple enough to do a release that I don't really care either way

#

Given how new of a regex we are now restricting to a hotfix seems like a good call tho.

neon loom
#

Good old regex causing us “fun”

plain atlas
#

yay regex!!

bright glacier
#

To be fair this is more on me for not noticing the type class was only added in 2021.4.4

neon loom
#

I see no problems releasing often personally but I have no context and I’ve just got home from the pub so I won’t be any help

plain atlas
#

neat

#

i think that's the first time i've seen a minute count

dense jungle
#

pypi will give you seconds if you're fast enough 🙂

plain atlas
#

oh dang

dense jungle
#

I'll warn you next time

plain atlas
#

lol

#

you have a lot of packages that you've probably seen that on 😛

flat krakenBOT
#

<!--
Please make sure that the bug is not already fixed either in newer versions or the
current development version. To confirm this, you have three options:

  1. Update Black's version if a newer release exists: pip install -U black
  2. Use the online formatter at , which will use
    the latest main branch.
  3. Or run Black on your machine:
    • create a new virtualenv (make sure it's the same Python version);
    • clone this repository;
    • run pip install -e .[d,python2];
      ...
flat krakenBOT
errant barn
gusty grail
#

hey @granite crown . I've deleted your question since it has nothing to do with this channel. You can re-ask your question in an off-topic channel.

lament crow
#

oh wait, that link actually links to black LUL

#

not as off-topic then!

flat krakenBOT
#

<!--
Please make sure that the bug is not already fixed either in newer versions or the
current development version. To confirm this, you have three options:

  1. Update Black's version if a newer release exists: pip install -U black
  2. Use the online formatter at , which will use
    the latest main branch.
  3. Or run Black on your machine:
    • create a new virtualenv (make sure it's the same Python version);
    • clone this repository;
    • run pip install -e .[d,python2];
      ...
granite crown
gusty grail
#

lol, okay

granite crown
#

👌

flat krakenBOT
#

Black violates PEP8: E203 (Whitespace before ':')

Tested on PyPi release: black-21.11b1 platformdirs-2.4.0 regex-2021.11.10 typing-extensions-4.0.0
Tested on Black Playground: Stable: 21.11b0 | Main: @d0b04d
Issue is present in all branches tested.

This only occurs in some situations in which list splicing contains an operator (see example below).

To reproduce:

Example code to be formatted with Black:

d...
silent apex
#

There are no current plans to drop support, but most likely it is bound to happen. Sometime. Eventually.
This part, specifically

#

Unless deprecation doesn't signal that support will be dropped? If so, apologies, I'm terrible at these terms

dense jungle
#

Good point, we should change that

bright glacier
#

Where's the warning?

#

Oh, we need to update the stable tag...

dense jungle
#

Oh yeah. There's still that issue though with the user claiming we need to pin regex even further

bright glacier
#

What system are you on?

#

I wonder if it's a system specific thing

dense jungle
#

I tried on macos

#

it also worked on our company system, where I think we had regex 2021.8

bright glacier
#

2021.4.4 works for me on x86-64 Linux 🤷

dense jungle
#

yeah and looking at the regex code I don't think this should have any weird dependencies. it's just defined in the global namespace of the Python part of the library

bright glacier
#

Indeed. I'm a bit surprised by the three +1s on that issue. Maybe it's folks still on 21.11b0 getting confused?

dense jungle
#

that seems like a good explanation