#black-formatter

1 messages ยท Page 34 of 1

neon loom
#

What Discord bot do we use with GitHub here?

neon loom
#

Legend. Thanks

gusty grail
#

with cloudlfare workers

bright glacier
#

I don't know whether cibuildwheel can produce a pure python wheel

neon loom
#

I don't want it to and don't get why it is

bright glacier
#

usually you would do the sdist and pure wheel outside of cibuildwheel

#

I've seen some discussion about sdists in the issue tracker, but I don't know what that meant

#

Oh, you meant that cibuildwheel was building a pure python wheel locally

neon loom
#

Yes

bright glacier
#

uhhhhh, probably something to do with the envvars, but I have never ran cibuildwheel locally

neon loom
#

My goal was to try and get a local way to test it to learn

#

So I thought try move as much as I could to the pyproject.toml since that's supported now

#

How did you test it all, trial and error with the aciton?

bright glacier
#

yup.

neon loom
#

I got the docker image and it was building in there, but for some reason was trying to build a native wheel

bright glacier
#

the only thing that comes to mind is that configuration is faulty since the BLACK_USE_MYPYC environment variable should've been set in the docker container

#

I would love to try it myself, but I'm busy today

neon loom
#

That's cool - I might play again later

#

Giving bandersnatch it's once a year overhaul / love today

#

I want to update pypi's install but I can never get movement / agreement there ... They still on 4.4.0

#

and old requests + deps with bugs ๐Ÿ˜

mild stratus
#

Hi folks!

Is there any Pycharm/IntelliJ plugins for black?
I'm find out well plugin like scalafmt on intellij.
In official docs, recommend use external tools

mint barn
mild stratus
flat krakenBOT
flat krakenBOT
flat krakenBOT
#

Restrict the GitHub token permissions only to the required ones; this way, even if the attackers will succeed in compromising your workflow, they wonโ€™t be able to do much.

https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions

https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs

[Keeping your GitHub Actions a...

lament crow
# flat kraken

re: this, might be worth changing the workflow default in repository settings to read-only once this is merged so that by default the token has the minimum permissions

flat krakenBOT
lament crow
#

wasn't entirely sure if you had access to repository settings, guess you do then ๐Ÿ˜„

dense jungle
#

I have great powers

lament crow
#

and great responsibilities

neon loom
#

And the right person for the job

brave epoch
#

what exactly is this?

flat krakenBOT
neon loom
neon loom
# flat kraken

Interesting - As this is fixing a bug/regression - Does this go under --preview or not?

dense jungle
neon loom
#

Ok, thanks. Was being lazy and didn't want to go re-read the policy

neon loom
#

I haven't checked, but lets make sure development docs state about preview style + link to it - I'll try get to it today

flat krakenBOT
flat krakenBOT
#

Hi! Thanks for the PR. I like the idea, since it's easier to just put a file in a folder rather than having to edit a list somewhere else. We could definitely do this for all the test categories. I'd be okay with doing it in a future PR, but thought I'd mention it already.

The changes themselves look alright to me. And to the best of my abilities I tried to verify that the correct files were indeed moved ๐Ÿ˜„ Nicely done!

carmine parcel
#

!cban 550341177585434635 racism

late dewBOT
#

:incoming_envelope: :ok_hand: applied ban to @broken stratus permanently.

molten hare
#

!cban 550341177585434635 racism

late dewBOT
#

:x: User is already permanently banned (#71094).

#

:x: Failed to apply ban.

carmine parcel
#

hah

molten hare
flat krakenBOT
#

This is a slight perf win for use-cases that don't invoke reformat_many(), but more importantly to me today it means I can use Black in pyscript or pyodide - i.e. client-side in the browser.

I admit that I wouldn't use it for https://black.vercel.app/ - the heavier initial load is probably worse than some server round-trips - but it's indispensable for demos like https://zhd.dev/ghostwriter/ which allow the user to run arbitrary code. In fact, that demo is using a custom wheel from ...

flat krakenBOT
flat krakenBOT
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];
    • run `...
flat krakenBOT
flat krakenBOT
errant barn
#

'Tis not the channel for it mate, try the dedicated helps!

lethal valley
#

Where? If you dont mind me asking?

errant barn
#

Also just posting an exercise without showing what you've done to solve it yourself could be considered impolite ๐Ÿ˜„ The various help channels are in the "available help channels" topic ๐Ÿ‘๐Ÿฟ

errant barn
#

Better to show some effort I mean

lethal valley
#

Yea lol i got to the function but that al.

flat krakenBOT
mint barn
#

jI

flat krakenBOT
misty solstice
#

hello, is there any easy way to get black and isort working nicely together in a github workflow?

lament crow
#

just run one after the other

misty solstice
#

got it

lament crow
#

since it's in CI, I suggest running both without any diff flag and running git diff after both complete so that one can see what changes need to be made to make both black and isort happy

dense jungle
#

isort has a black-compatible profile to make sure they don't fight over formatting

misty solstice
#

But I just didn't know if I could add it in a similar way in the workflow

lament crow
#

I personally would suggest running isort after black due to some magic trailing comma stuff

lament crow
austere lava
#

I wonder if we should mention this in our docs

misty solstice
#

thank you! ๐Ÿ˜„

rigid gorge
#

what is the recommended way to use black with pytest? pytest-black hasnt been updated since october 2020 and shows deprecated warnings with the latest pytest

bright glacier
#

ah looks I need to ignore the tracebacks while comparing analyses for that weird diff-shades issue

rigid gorge
#

i could fix it myself and i believe there's a pending pr that fixes it but i dont want to use the pending pr because that'd involve installing a dependency from git as well as fixing myself and publishing a release could take a while

bright glacier
#

I have never used black with pytest and I don't see any warnings from black's side so I'm of little help.

rigid gorge
#

ah

#

was just wondering if anyone knows of alternate ways to use it with pytest i guess

austere lava
#

im curious why do you need it in pytest?

rigid gorge
#

we've been enforcing formatting by making a pytest test for whether code is properly blacked

#

so tests fail if the code isn't formatted properly

little parrot
#

have you had a look at pre-commit?

austere lava
#

right, as opposed to a custom CI step that runs black check?

rigid gorge
#

i have but that requires everyone who contributes to use it (which is possible to enforce, but kinda hard)

rigid gorge
errant barn
#

or a tox run

rigid gorge
#

we use tox to test multiple python versions, can it test for black formatting too?

errant barn
#

yup

rigid gorge
#

oh

#

using a module on pypi or is it builtin

errant barn
#

surely you can just make an environment and run black there, no?

#

as you would any other tool

late dewBOT
#

.github/workflows/lint.yml lines 27 to 28

- name: Lint
  uses: pre-commit/action@v2.0.3```
austere lava
#

in our case this runs precommit as part of the CI suite, which in turns run black check

rigid gorge
#

oh github lets you automatically apply code before a merge?

austere lava
#

no, you just get a red signal saying your formatting is broken

#

same as a broken test

rigid gorge
#

oh

#

that'll work, thanks for showing me!

errant barn
#

so I guess it would be: PR red flag -> go for CI, local test run -> go for tox env

bright glacier
#

you can use pre-commit.ci to have fixes automatically applied, some folks might like it, but it can be nice

glacial swan
#

hey friendos

#

is there a way to run black on commits automatically?
so I can check with a pr if it's ok but run if black thinks it's sus?

errant barn
#

the aforementioned pre-commit!

glacial swan
#

Can you help me set it up?

errant barn
late dewBOT
#

.pre-commit-config.yaml line 7

- id: black```
errant barn
#

I'm sure pre-commit has lots of good example resources

glacial swan
#
name: CI

on: [push, pull_request]

jobs:
  black:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Run linter
        uses: psf/black@stable
        with:
          options: "--line-length 120 --check"
          src: "."
#

this is what I use right now

errant barn
#

Oh do you mean running it online instead of before every commit locally?

rigid gorge
glacial swan
#

Yes

#

Please

errant barn
#

the convergence

glacial swan
#

I want black to be ran online if possible

#

with only the stuff it needs

#

in the speacil .yml for it

glacial swan
errant barn
#

then a similar job with black --check will work just fine!

glacial swan
#

what do you suggest I do in this?

#

black . 120?

#

I don't know what to do to autoformat on commits?

errant barn
#

oh sorry, I misunderstood

glacial swan
#

I am also a bit overwhelmed rn

#

I don't care if I make it autoformat prs and stuff, I just want it to check the workflow if it fails, to autoformat to 120

bright glacier
#

I'll note that you should define version right now since the action version is independent from the black version

errant barn
#

So to reiterate, you'd like for your CI run to automatically format the code with black and produce another commit to a PR?

glacial swan
#

Yes

errant barn
#

Or just check if the code is formatted correctly?

glacial swan
#

if it fails

bright glacier
hot beacon
#

JD, that isn't what we are asking for

glacial swan
#

I would rather it autoformat when the pr fails and updates

errant barn
#

Who are "we" :D

hot beacon
#

@errant barn He misunderstood, he just want it to autoformat on commits.

hot beacon
#

only one person to be specific with me

glacial swan
#

I think Autoformatting on prs and stuff if black fails is better tho

errant barn
#

I'm so confused

hot beacon
#

We just want autoformat when new commit comes.

#

Not PR commit or anything, just repo commit

bright glacier
#

so on the main / master branch only?

glacial swan
#

that works for me but I still want the workflow check

hot beacon
bright glacier
#

So in essence:

MAIN / MASTER:

  • run black
  • and push changes in a new commit

EVERYTHING ELSE:

  • run black
  • do nothing but fail the workflow
glacial swan
#

I would to keep my workflow though for new users

glacial swan
#

as I now no longer need to push a black fix

#

and it's done automatically

#

will it commit if black passes, I would rather it not commit if it passes with flying colors, i.e. black has no change?

bright glacier
#

Well given I don't think a prebuilt solution exists, it's going to be custom.

mint barn
#

What are you guys talking about

glacial swan
#

There's no way to do this on github currently?

#

you can't autochange it?

mint barn
#

Is anyone gonna answer my question

glacial swan
#

and you know not commit when there's no changes

bright glacier
#

well it is possible, but it requires some custom GHA logic

glacial swan
hot beacon
glacial swan
#

I am a big newbie to workflow

bright glacier
#

if black pushes a commit to main, should that workflow fail still?

hot beacon
#

what do you mean ?

bright glacier
bright glacier
bright glacier
#

continuous integration, basically running automated checks against a changeset before deployment

mint barn
#

Oh

#

Sounds easy enough

bright glacier
#

this kind of workflow is not simple though

mint barn
#

I've worked with the lighter workflow of the year and a half years old when he was the first

errant barn
#

pre-commit could make it easier, if you're open to having the check and correction locally

hot beacon
#

well, how about,

MAIN/MASTER:

  • format, then push change to new commit

only

mint barn
#

Guys how about both

glacial swan
#

not everyone is going to have black installed locally

#

so

mint barn
#

Find a way to make it with both

glacial swan
#

There's no way to get a workflow check?

#

you can't like

#

check commit

#

then recheck?

mint barn
#

Make 2 different ones

bright glacier
#

I am working onn it

glacial swan
#

alr

#

thank you man

bright glacier
#
name: CI

on: [push, pull_request]

jobs:
  black:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Run linter
        uses: psf/black@stable
        with:
          options: "--line-length 120"
          src: "."

      - name: Commit & push changes (main only)
        if: github.event_name == 'push' && github.ref_name == 'main'
        continue-on-error: true
        run: |
          git config user.name "github-actions"
          git config user.email "github-actions@example.com"
          git add -A
          git commit -m "[ci] Autoformat with black"
          git push

      - name: Fail job if changes were made (PR only)
        if: github.event_name == 'pull_request'
        run: git diff-index --quiet HEAD -- || (git diff && exit 1)

@glacial swan this should work

#

I'm getting pretty decent at writing gha workflows ๐Ÿ˜…

#

not that I recommend what I shared as I provide no guarantees, but if it works I guess why not

glacial swan
#

And this should work?

bright glacier
#

I just took the original yaml file you gave us earlier and added the bits to support what you wanted

glacial swan
#

alr

#

alr

#

let's see

bright glacier
glacial swan
lament crow
#

you should use an email of a bot in order for it to not show on the Contributors tab in repo's Insights

bright glacier
#

I'll note that since the job is run twice (once for the push event and another time for the pull event) on local PRs, the one triggered by the push event is kinda useless / ignored / ran without doing anything meaningful

#

GitHub unfortunately still doesn't provide any good way of cancelling / skipping jobs triggered by the push event when the pull_request event (and its copy of the jobs) is also going to trigger

#

You can block push events from firing on all branches except main, or skip the pull_request job if it's coming from the target repository but either of these are not ideal.

#

Anyway I got some work to do now, so I got to go.

glacial swan
#

it does this

bright glacier
#

what is the problem?

glacial swan
#

No

#

it looks to work

#

I mean

#

does this look fine to you?

#

oops

#

no it doesn't autoformat

glacial swan
rigid gorge
# bright glacier ```yaml name: CI on: [push, pull_request] jobs: black: runs-on: ubuntu-l...

looks a bit complicated, i got this to work for my similar use case:


name: Lint

permissions:
   contents: write

on:
  push:
    branches:
      - main

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Run black check
        uses: psf/black@stable
        with:
          options: "--check --diff"

      - name: Run black format
        if: failure()
        uses: psf/black@stable
        with:
          options: ""

      - name: Commit black format
        if: failure()
        uses: stefanzweifel/git-auto-commit-action@v4
        with:
          commit_message: "Apply black to code"
#

this only runs the commit for fixing code with black if there was any code to fix in the first place

#

and it only runs for pushes to the main branch, but that's easy to change

glacial swan
#

so

#

why does mine

#

not push then?

glacial swan
#

I can even dm the github if you want

bright glacier
#

oh master?

#

you'll need to change the main string to master in the workflow

glacial swan
#

oh

#

Thanks man

glacial swan
#

okay one issue

glacial swan
bright glacier
#

What?

glacial swan
#

Look

bright glacier
#

Yea that's expected, that's why there is continue-on-error

#

so it doesn't mark the job as failed, only the step

glacial swan
#

ah

#

right it doesn't say failed

glacial swan
bright glacier
#

Look, I can fix it tomorrow, but I'm busy now.

glacial swan
#

ok

#

Can you please dm me a fix when you are available if possible ?

#

Thank you in advance

dense jungle
#

@glacial swan what's the problem you're having? I might be able to help

glacial swan
#

the check passes

#

but I get a black

#

error like this

dense jungle
#

can you link to the workflow on GitHub?

glacial swan
#
name: CI

on: [push, pull_request]

jobs:
  black:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Run linter
        uses: psf/black@stable
        with:
          options: "--line-length 120"
          src: "."

      - name: Commit & push changes (main only)
        if: github.event_name == 'push' && github.ref_name == 'master'
        continue-on-error: true
        run: |
          git config user.name "github-actions"
          git config user.email "github-actions@example.com"
          git add -A
          git commit -m "[ci] Autoformat with black"
          git push
      - name: Fail job if changes were made (PR only)
        if: github.event_name == 'pull_request'
        run: git diff-index --quiet HEAD -- || (git diff && exit 1)
#

Here's the workflow file

glacial swan
dense jungle
glacial swan
#

the workflow passes

#

I just don't want to see black complaining

#

if it can't commit as it's an empty commit

dense jungle
#

on the run you linked Black didn't seem to want anything changed

#
25 files left unchanged.
glacial swan
#

Yep

#

I need it to not to attempt to commit

#

only if it needs to be changed

dense jungle
#

then you need to write some more complicated shell script than you have

#

could also consider using pre-commit.ci for this, it takes care of applying the changes for you

glacial swan
#

wouldn't it error if people

#

don't have black tho?

dense jungle
#

no, that runs in CI

#

despite the name it doesn't require people to use local pre-commit hooks

glacial swan
#

so it just autoformats on every commit unless it good?

dense jungle
#

yes

glacial swan
flat krakenBOT
#

For some reason, the shorter line is formatted but the longer one isn't

To Reproduce
These lines of code:

PW_PATTERN = "08 00 00 00 09 00 00 00 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 00 00 00"
ID_PATTERN = "01 00 00 00 0B 00 00 00 0D 00 00 00 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 00 00 00"

Will be formatted like this:

PW_PATTERN = (
    "08 00 00 00 09 00 00 00 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 00 00 00"...
jovial coral
#

Should I expect black to move the key to the next line assuming the default line length of 80/88?

GGG = {
    "12345678901234567890123456789012345678901234567890": "12345678901234567890123456789012345678901234567890"
}
flat krakenBOT
flat krakenBOT
#

Description

This PR is a continuation of #3034.
The end goal of thus PR is to move all cases in the tests/data directory into subdirectories and remove all hardcoded cases lists.

Checklist - did you ...

  • [X] Add a CHANGELOG entry if necessary?
  • [X] Add / update tests if necessary?
  • [X] Add new / update outdated documentation?
flat krakenBOT
flat krakenBOT
flat krakenBOT
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];
    • run `...
flat krakenBOT
#

Describe the style change

Black did made this unusual ugly change to my code after I made the string longer.

Examples in the current Black style

    webbrowser.open(
        "https://github.com/Matiiss/" f"pygame_examples/tree/main/pgex/examples/{name}"
    )

Desired style

    webbrowser.open(
        "https://github.com/Matiiss/"
        f"pygame_examples/tree/main/pgex/examples/{name}"
    )

Additional context

The ...

peak wolf
#

do you know how I can fix Dubugger?

flat krakenBOT
#

Python type checkers supports enclosing type annotations in a string to make forward references possible. Although from __future__ import annotations makes that unnecessary in type annotations, it's still needed in type aliases.

Example:

# All these are equivalent from the point of view of the type checker 
x: "Union[A, B, C, D]"
x: Union["A", 'B', """C""", '''D''']
x: Union[A, B, C, D]

# Same here
y: TypeAlias = Union[A, B, C, D]
y: TypeAlias = "Union[A, B, C, D]"
y: Type...
flat krakenBOT
#

Describe the style change
I have an assert statement that checks a condition on the last element in an array. To me what black does to the statement makes it less readable:

assert self.ref_transitions[-1].terminal.all(), "Last ref transition must be terminal."

Examples in the current Black style

        assert self.ref_transitions[
            -1
        ].terminal.all(), "Last ref transition must be terminal."
        self.initial_state = sel...
flat krakenBOT
wild haven
#

Image to ASCII (Pillow Required)
For it to work, there has to be an image with the python code in the same folder and you have to typeout its full name + extenion.

import PIL.Image

# ascii characters used to build the output text
ASCII_CHARS = ["@", "#", "S", "%", "?", "*", "+", ";", ":", ",", ".", "1", "2", "3", "4", "5", "6", "7", "9", "8", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "T", "U", "V", "W", "X", "W", "Y", "Z", "0", "`", "~", ",", ".", "/", ";", ":", ";", "[", "]", "|", "-", "_", "="]

# resize image according to a new width
def resize_image(image, new_width=100):
    width, height = image.size
    ratio = height/width
    new_height = int(new_width * ratio)
    resized_image = image.resize((new_width, new_height))
    return(resized_image)

# convert each pixel to grayscale
def grayify(image):
    grayscale_image = image.convert("L")
    return(grayscale_image)
    
# convert pixels to a string of ascii characters
def pixels_to_ascii(image):
    pixels = image.getdata()
    characters = "".join([ASCII_CHARS[pixel//25] for pixel in pixels])
    return(characters)    

def main(new_width=100):
    # attempt to open image from user-input
    path = input("Enter a valid pathname to an image:\n")
    try:
        image = PIL.Image.open(path)
    except:
        print(path, " is not a valid pathname to an image.")
        return
  
    # convert image to ascii    
    new_image_data = pixels_to_ascii(grayify(resize_image(image)))
    
    # format
    pixel_count = len(new_image_data)  
    ascii_image = "\n".join([new_image_data[index:(index+new_width)] for index in range(0, pixel_count, new_width)])
    
    # print result
    print(ascii_image)
    
    # save result to "ascii_image.txt"
    with open("ascii_image.txt", "w") as f:
        f.write(ascii_image)
 
# run program
main()
errant barn
#

not the channel for it mate

flat krakenBOT
flat krakenBOT
potent mango
#

hi everyone,
any idea why my black is not setting the trailing comma? It is doing the line break but not setting the trailing comma itself.

#

my pyproject.toml has only 2 lines:

[tool.black]
line-length = 120
exclude="file/path/"
errant barn
#

is it only on a single line?

potent mango
#

I have a dict like this

    {
        "a": fun(msg, "ts"),
        "id": ...,
        "key": ..., "created": ...
    }

and running black . in console will make the linebreak to

    {
        "a": fun(msg, "ts"),
        "id": ...,
        "key": ..., 
        "created": ...
    }

but its not setting the last comma at the end

errant barn
#

hmm, oh!

potent mango
#

(cool website btw with the black example formatting

errant barn
#

and putting it onto the same line does produce the trailing comma

#

the comment I mean

potent mango
#

true, so I guess I found a bug ๐Ÿ™‚

errant barn
#

yeah, at least I can't come up with a reason as to why that would be :D

#

feel free to submit if you'd be so kind!

potent mango
#

man, I dont envy you developer dealing with all these edge cases xD

errant barn
#

:D feel free to also contribute ๐Ÿ˜œ envy is a grave sin you know

potent mango
#

sure, I can open a ticket on github about it.

#

๐Ÿ˜„ feel free to also contribute ๐Ÿ˜œ envy is a grave sin you know
I might actually give it a try ๐Ÿ‘

errant barn
#

or which way it goes, anyhows

potent mango
#

thank you for your help and have a nice day ๐Ÿ‘

flat krakenBOT
potent mango
# errant barn cool, we'll be there to help!

sooo, I got the black dev environment locally up and running (great job with that btw, worked on the first try) and set up the test case that is failing, and went into black._format_str_once with a debugger to understand what is happening
I landed at black.linegen.delimiter_split() where I think the source of the issue lies, but I am not sure about that.

#

I got to this chunk of code, where the current_line is checked and always the last leave is selected and checked. If I understand correctly by some backwards looping through the line leaves

#

When I let the debugger iterate and always check, what current_line.leaves[-1] prints, it prints the last lcomment line # "longkey": ...

errant barn
#

also, great to hear that the initial process was smooth :D

errant barn
#

i.e. submit an issue and discuss more there

potent mango
#

I will do that, ๐Ÿ˜Š๐Ÿ‘

austere lava
#

it's client-side black ๐Ÿ™‚

little parrot
#

Webasm?

austere lava
#

Yes, indirectly. Through py script. Check the source

#

It's funny

dense jungle
#

very creative use of mocking

lament crow
#

fyi, two single quote issues (#633, #1794) have been necroed :P

flat krakenBOT
#

Describe the bug

When running black on a dictionary with a comment, a trailing comma is not set correctly
The example

{
    "a": fun(msg, "ts"),
    "longggggggggggggggid": ...,
    "longgggggggggggggggggggkey": ..., "created": ...
    # "longkey": ...
}

is being formatted to

{
    "a": fun(msg, "ts"),
    "longggggggggggggggid": ...,
    "longgggggggggggggggggggkey": ...,
    "created": ...
    # "longkey": ...
}

where the , is missing after ` "...

violet canyon
#

Can I share that link to gh repo?

austere lava
#

that's how products are developed right?

bright glacier
#

lol you're not that wrong

#

I'm just doing regular web development with pure JS, HTML, and CSS right now ๐Ÿ˜„

austere lava
#

you could be writing python instead! ๐Ÿ˜„

bright glacier
#

I only have to clean up this messy JS so I think I'm good for now. Anyhow, how long did that website take you?

austere lava
#

you mean to write it?

bright glacier
#

yeah

austere lava
#

about 3 hours net total

bright glacier
#

oh wow that's not long at all

austere lava
#

yeah and I had no idea how to use py-script before ๐Ÿ˜„

#

not counting my wife's pixel-pushing that resulted in the wonderful css

bright glacier
#

haha, it's wonderful

#

how is the performance would you say?

#

it's obviously going to be slow as this is first-gen tech, but I have a lot of stuff open right now (discord's and vscode's electrons are not being kind to my CPU)

austere lava
#

Much better than I expected, that site reformats on every keypress and it's usable

bright glacier
#

oh that's great to hear

mint barn
#

who else loves tkinter

flat krakenBOT
#

Version information

pre-commit version: 2.19.0

> pre-commit --version
pre-commit 2.19.0

pre-commit black version: 22.3.0 (https://github.com/ludwig-ai/ludwig/blob/master/.pre-commit-config.yaml)

- repo: https://github.com/psf/black
    rev: 22.3.0
    hooks:
      - id: black
        name: black

command line black version: 22.3.0

> pip show black
Name: black
Version: 22.3.0
Summary: The uncompromising code formatter.
Home-pa...
bright glacier
#

hmmm the first thing that comes to mind would be mypyc

#

.. which would be concerning

#

can't reproduce the issue

#

os or python version dependent?

stuck vapor
#

no idea, couldn't reproduce this either

mint barn
#

!format

late dewBOT
#

String Formatting Mini-Language
The String Formatting Language in Python is a powerful way to tailor the display of strings and other data structures. This string formatting mini language works for f-strings and .format().

Take a look at some of these examples!

>>> my_num = 2134234523
>>> print(f"{my_num:,}")
2,134,234,523

>>> my_smaller_num = -30.0532234
>>> print(f"{my_smaller_num:=09.2f}")
-00030.05

>>> my_str = "Center me!"
>>> print(f"{my_str:-^20}")
-----Center me!-----

>>> repr_str = "Spam \t Ham"
>>> print(f"{repr_str!r}")
'Spam \t Ham'

Full Specification & Resources
String Formatting Mini Language Specification
pyformat.info

mint barn
#

how do i format my code

austere lava
#

```python
print('test')

#

like so

errant barn
#

what kind of sorcery is that :D

#

are there escapes for backticks?

austere lava
#

yeah

#

\

bright glacier
#

!raw 975377672714731530

late dewBOT
#
== Raw message ==

\`โ€‹`โ€‹`โ€‹python
print('test')
`โ€‹`โ€‹`โ€‹
errant barn
#

sick :D

buoyant grove
#

Guys, I have this code:

oldfile = open("FILE-%s.csv" % (state),'r')
newfile = open("FILE2-%s.csv" % (state),'w')
newfile2 = open("FILE3-%s.csv" % (state),'w')
for line in oldfile:
    if re.search('\$1,5',line) or re.search('\$1,6',line) or re.search('\$1,7',line) or re.search('\$1,8',line) or re.search('\$1,9',line) or re.search('\$2,',line) or re.search('\$3,',line) or re.search('\$4,',line) or re.search('\$5,',line) or re.search('\$6,',line) or re.search('\$7,',line) or re.search('\$8,',line) or re.search('\$9,',line) or re.search('\$10,',line) or re.search('\$11,',line) or re.search('\$12,',line) or re.search('\$13,',line) or re.search('\$14,',line) or re.search('\$15,',line) or re.search('\$16,',line) or re.search('\$17,',line) or re.search('\$18,',line) or re.search('\$19,',line) or re.search('\$20,',line):
        newfile.write(line)
    else:
        newfile2.write(line)```
#

I was trying to filter out any lines which contains $1,5xx,xxx, $1,6xx,xxx,... all the way up to $20million, meaning filter out anything that have value of $1,5 million and up. Now, I realize this is not how to do it. Because it's also removing $1,500, $1,600... $20,000 (not the million 7-digit value).

#

Not sure how to improve /fix the above

lament crow
buoyant grove
mint barn
#

๐Ÿ˜

bright glacier
#

is this on topic for this channel @mint barn ?

mint barn
#

what is

bright glacier
#

that eval command

mint barn
#

what eval command

bright glacier
#

Ugh whatever. Just don't do that again.

mint barn
#

i have no idea what ur talking about ๐Ÿ˜ ๐Ÿ‘

errant barn
#

Please refrain from advertising projects on this channel, it's for Black development

flat krakenBOT
flat krakenBOT
#

Describe the bug

A fresh conda env with minimal install of

  • black
  • jupyterlab
  • jupyterlab_code_formatter

still shows the long known (#2681 , #1143) "Writing grammar tables.... Writing failed" bug:

Generating grammar tables from /home/maye/mambaforge/envs/black_bug/lib/python3.10/site-packages/blib2to3/Grammar.txt
Writing grammar tables to /home/maye/.cache/black/22.3.0/Grammar3.10.4.final.0.pickle
Writing failed: [Errno 2] No such file or directory: '/home/maye/.ca...
flat krakenBOT
#

Describe the bug

When a # fmt: skip is on a given line, any preceeding comments directly above the given line will be deleted.

To Reproduce

For example, take this code:

# Comment about this line below
data = [ True,  True, False]  # fmt: skip
$ black file.py --target-version py310

The resulting file is:

data = [ True,  True, False]  # fmt: skip

Expected behavior

The comment line should have remained uncha...

bright glacier
#

ugh, we still can't run CI on Python 3.11-dev on GHA for some reason

#
      creating build/temp.linux-x86_64-cpython-311/aiohttp
      gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/home/runner/work/black/black/.tox/ci-py/include -I/opt/hostedtoolcache/Python/3.11.0-beta.1/x64/include/python3.11 -c aiohttp/_websocket.c -o build/temp.linux-x86_64-cpython-311/aiohttp/_websocket.o
      aiohttp/_websocket.c:198:12: fatal error: longintrepr.h: No such file or directory
        198 |   #include "longintrepr.h"
            |            ^~~~~~~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/gcc' failed with exit code 1
      [end of output]

I thought the new Cython release today was supposed to fix this ... >.<

#
gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/home/runner/work/black/black/.tox/ci-py/include -I/opt/hostedtoolcache/Python/3.11.0-beta.1/x64/include/python3.11 -c frozenlist/_frozenlist.c -o build/temp.linux-x86_64-cpython-311/frozenlist/_frozenlist.o
      frozenlist/_frozenlist.c: In function โ€˜__Pyx_AddTracebackโ€™:
      frozenlist/_frozenlist.c:432:62: error: dereferencing pointer to incomplete type โ€˜PyFrameObjectโ€™ {aka โ€˜struct _frameโ€™}
        432 |   #define __Pyx_PyFrame_SetLineNumber(frame, lineno)  (frame)->f_lineno = (lineno)
            |                                                              ^~
      frozenlist/_frozenlist.c:7127:5: note: in expansion of macro โ€˜__Pyx_PyFrame_SetLineNumberโ€™
       7127 |     __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
            |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
      error: command '/usr/bin/gcc' failed with exit code 1
      [end of output]

looks like the interpreter core optimisation work still breaks frozenlist

dense jungle
#

if so they need to recompile and release

bright glacier
#

I'd guess not given the traceback file is build/temp.linux-x86_64-cpython-311/aiohttp/_websocket.o

#

although tbf I don't know how included C would work when being built from a sdist

dense jungle
#

I checked, there's .c files in the sdist

bright glacier
#

yeah me too

bright glacier
#

my only comment on https://github.com/psf/black/pull/3035 is that if we remove immediate newlines after blocks, that might effectively decide black's stance on newlines after class signatures nevermind, please see below!

GitHub

Description
Fixes #902
Newlines are great. They help us organize our code and leave room for the coders and reviewers to breath.
However, too many newlines can make simple code gigantic and massive...

#

I don't remember enough of the discussion in regards to classes and following newlines, but I do know they are somewhere in the issue tracker

#

I'm still +1 on the change though.

bright glacier
#

!remind 5H audit recent code style changes to make sure our style documentation covers 'em

late dewBOT
#
Okay.

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

late dewBOT
flat krakenBOT
bright glacier
#

that invite link is for the whole server, not this channel specifically as is currently

flat krakenBOT
#

Nice! I quite like the idea of having atomic test cases in each file, but it's different from the current setup where a category of tests is contained in a single file (or a few files). I don't feel strongly about it, but perhaps it would be worth considering just to be consistent.

The doc is also good, although in my personal opinion we could keep it terse since we have similar generic newline speak in the ["current style" doc](https://black.readthedocs.io/en/stable/the_black_code_style/c...

flat krakenBOT
#

This issue is not a feature request, but it concerns about testing. Please remove the "enhancement" label

Description
We've made a lot of progress improving the testing process in #3034 and #3062.

A problem that still remains is that the existing cases data files are ENORMOUS. those data files can contain up to 300 lines (and even more), which is way too much for a test. Cases files, and tests in general, should be short and concise in order for us to track down errors as e...

loud whale
#

!raw 975377672714731530

late dewBOT
#

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

rigid inlet
#

Hola!
I really like black and we use it in our project at work.
We also recently added http://www.pydocstyle.org/ to our checks. A feature I wish black would have is to format D400 - First line should end with a period . If I create a PR that autoformats a period on docstrings, what is the probability for it to get accepted?๐Ÿค”

dense jungle
rigid inlet
lament crow
#

Black's aim is to make no changes to AST

#

If you want to automatically make changes like this, you should probably consider other tools

#

Instagram's Fixit perhaps?

rigid inlet
lament crow
#

Yeah

molten hare
#

And a ping 1 2

dense jungle
#

@bright glacier thanks for diff-shades!

bright glacier
#

sigh, OK so these notification settings will not work. Thanks for the messages!

flat krakenBOT
#

Describe the bug

Black generates an INTERNAL ERROR with a file that has a docstring that contains a backslash with a trailing space character. Removing the trailing space solves the issue.

To Reproduce

Create a file file.py with the following content. Note, the 5th but last line (i.e., just above the line with other option) contains a trailing space after the backslash!

def foo():
    """
    Some description
                            ['some option'...
surreal socket
#

Guys how to enable black formatter on new projects in vsc? I have it in User Settings but on new project its not working, i installed it on project venv.

#

when i use it from terminal on file it is working, but cant get it owrking on save in vsc on new project

rigid inlet
rigid inlet
surreal socket
#

I have venv python interpreter selected

still brook
#

Did you already pip install black in your .venv?

#

And setting VSCode to format on save

surreal socket
#

yes i installed but didnt set the format on save

#

though this settings will be imported from my user settings

surreal socket
still brook
#

I think you need install black for every .venv, but for setting u don't if you have login with github in vscode the setting will sync automatically

rigid inlet
#

If you look at output->python you can see what vscode executes. eg: ~/code/py/**/.venv/bin/python -m black --diff --quiet ~/code/py/***/bulletin.py

flat krakenBOT
flat krakenBOT
flat krakenBOT
#

Often as result of refactoring I end up with f-string with no
{substitutions}, and my editor (integrated with flake8) keeps
reminding me about it.

With some stretch one can argue that this is actually formatting issue
and as such within scope of black(1). Would you be interested in patch
that implement this proposal?

print(f"Hello")

to become

print("Hello")
flat krakenBOT
#

Description

As promised, I came with patch that mostly does what is discussed in #3081.
Code quality is back-of-envelope, and not all tests are converted. I will fix
it once we decide what to do with the most major issue:

Black produced code that is not equivalent to the source

I can't argue that it is very good and valuable sanity check, and just turning
it off seems reckless. Ideas?

flat krakenBOT
flat krakenBOT
#

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

Black currently does not format Doctests in Docstrings. This issues was reported in https://github.com/psf/black/issues/745 which was superseeded by https://github.com/psf/black/issues/144. As the latter was closed though, nothing was done about the Doctests.

Describe the solution you'd like

I would be keen for black to format Doctest.

For example, given the following Python Doctests code:

bright glacier
#

@dense jungle was this you? ๐Ÿ˜„

dense jungle
bright glacier
#

(the other pageload is probably some bot)

dense jungle
#

for pyanalyze I have a similar workflow to black where the PR number goes in the changelog, so I bookmarked the page

bright glacier
#

Ah neat, Python Discord is starting to use the same changelog workflow too so now I have four main users ๐Ÿ˜…

#

I rewrote the codebase a week-ish ago; it was my first serious webdev project.

dense jungle
#

I think I only learned about the url parameters because you mentioned it here at some point, that was a big usability improvement for me

bright glacier
#

Yeah it's an open issue to advertise that feature better. Someone did come by and make Next PR Number update the URL to include the query parameters if you do a query which helps a little bit.

#

I should just add a little lightbulb admonition somewhere that mentions the URL query parameters

bright glacier
#

webdev is just โœจ great and totally not soul-suckingโœจ

flat krakenBOT
#

Description

This change introduces the Pants build system to the Black repo, on an experimental basis.

It does not change any of the existing build mechanisms for running tests, formatting, linting,
typechecking, building distributions etc. Developers in this repo can remain unaware of Pants if they choose.
Others may be interested in playing around with it.

For context: While chatting with @ambv at PyCon 2022 he expressed interest in seeing wh...

plain atlas
#

๐Ÿ™ƒ

#

lmfao its able to be installed on stable but not insiders

lunar gulch
#

.black

#

!black

west crown
errant barn
#

As you mentioned in the last comment, we'd still need at least another review. We've agreed it's the better style, but an approving review is still needed. Also, still no comments about removing the class body newline. And to that end: did you consider the effect of previous code wrt. defs along with class bodies? Which is line 505 in the diff.

west crown
#

Hey @errant barn , I pinged it here so other reviewers could take a look at it ๐Ÿ™‚ Wasn't sure if this is the right place or I should have just add another comment in the PR (please let me know for next time!).

Surely this needs more review. No questions about that

errant barn
#

That's ok, we're all here ๐Ÿ˜„

#

If there's something to discuss then it's better to do it on the issue, so that we leave the paper trail

west crown
#

I still think that classes should be an exception to the rule and should still be formatted according to the existing rule, due to the example I presented there

errant barn
#

Fair, although personally I prefer to remove them ๐Ÿ‘๐Ÿฟ but what I meant was: defs trigger the previous formatting as well. So are there similar exceptions there?

west crown
#

I agree that further discussions should be in the PR. This was just a gentle ping ๐Ÿ˜‹

#

I'm not sure what you mean. If you could please explain it better in the PR itself, I would really appriciated it

errant barn
#

Actually, going through the code once more addressed my concern already! So don't worry about it

flat krakenBOT
wary pollen
#

Hi,
Could anyone please tell, how to add exclude folder in the setup.cfg

Following does not work:
[black]
exclude = folder/example/some_folder/

But this one works:
black --check . --exclude=folder/example/some_folder/

flat krakenBOT
#

Hi,
I have a project with precommit hook that calls [black --check --diff] and fails commit on non-empty diff.
Collegue of mine suddenly added space after last character in line but diff looks confusing:

-) 
+)

I could see the source by checkout his branch and running black over it but this is a long way.
Could black show trailing spaces in some explicit way? It will be appreciated even by specifying some CLI option.
Thank you.

flat krakenBOT
#

Describe the bug

Black should put parentheses and wrap this tuple over multiple lines:

def asdf():
    for item in items:
        yield item, "this is a really long string describing item. you'd expect black to put parentheses around the tuple."

To Reproduce

https://black.vercel.app/?version=stable&state=_Td6WFoAAATm1rRGAgAhARYAAAB0L-Wj4ADxAK5dAD2IimZxl1N_WlbvK5V8JNI77iY4W6dVOfyLjNFiaj70Bl3KDmvzUGa515Sxf8PkVW3bG3ae8JNP373LwFgPbvHVIPAE-XJtpbaXte5disESbEB-JtiPSKxPO...

bright glacier
#

It probably shouldn't have taken 79 insertions(+) and 10 deletions(-) but oh well lol

slow ibex
#

some my suggestions:

  1. format content of annotations in quotes: x: "Union[X,Y]"->x: "Union[X, Y]"
  2. replace 'X'->X in annotations if from __future__ import annotations enabled or python>=3.11
  3. remove from __future__ import <smth> if this future import is pointless for target python version
bright glacier
#

All of those suggestions sound reasonable at first sight, but all of them are also AST-unsafe and I'm wary of adding more unsafe transformations.

#

We could add a --ast-unsafe flag or whatever, but that would hurt black's goal of minimizing configurability

slow ibex
#

just noticed that black can format match-case syntax, cool!

bright glacier
#

Given we maintain our own CST LL(1)ish parser, we can use whatever hacks we like to support PEG syntax lol

#

not exactly maintainable, but welcome to an aging codebase

errant barn
cunning thunder
#

Is this formatter avilable for pycharm?

flat krakenBOT
#

We often get proposals for formatting changes that could be useful, but that change the AST or are otherwise unsafe. Examples include:

  • Import sorting (#333)
  • Formatting stringified annotations (#3067)
  • Dropping useless f-strings (#3081)
  • Aspects of docstring formatting (#144, #2150)
  • not (x in y) (#212)

Many of these proposals make sense as an extension of Black's mission to create a single, consistent style for Python code, but users have legitimate concerns about the safet...

bright glacier
#

I gotta say I like reading these GH embeds as a super duper condensed summary of what happened. Sometimes I'm too lazy to open 13 emails or whatever ๐Ÿ˜…

red sedge
#

@dense jungle seems like an ast bug still. Where does peephole optimization and constant folding fit?

dense jungle
#

yeah I assume it gets optimized away later

#

but IIRC ast.parse is before the peepholer

#

ast.parse("1 + 1") also doesn't get constant folded

red sedge
#

Black's promise should probably only apply after peephole and constant folding

#

f"ABC" r"ABC" and u"ABC" all make the same pyc?

dense jungle
#
              0 RESUME                   0

  1           2 LOAD_CONST               0 ('abc')
              4 RETURN_VALUE
>>> dis.dis('r"abc"')
              0 RESUME                   0

  1           2 LOAD_CONST               0 ('abc')
              4 RETURN_VALUE
>>> dis.dis('u"abc"')
              0 RESUME                   0

  1           2 LOAD_CONST               0 ('abc')
              4 RETURN_VALUE
red sedge
#

I think black should promise the same pyc and not worry about the ast

bright glacier
#

The pyc doesn't sound very stable imo

dense jungle
#

I feel like that's a harder promise to implement since the pyc format is much less stable

#

If we can simply say "ast.parse is the same before and after, no ifs or buts", that's a much more convincing promise

red sedge
#

The same ast means the same pyc right? So it's a looser promise?

dense jungle
red sedge
#

Maybe there's some IR that cPython could commit to

dense jungle
#

That feels like a lot of work for very little gain

#

The cases where we could make ast-unsafe changes that are pyc-safe are pretty obscure

red sedge
#

f-string normalisation

dense jungle
#

And under my proposal, we'd still do minor AST-unsafe changes (like useless fs) by default, we could just offer an additional mode that guarantees zero AST changes

red sedge
#

I'd have expected this to be removed in the AST phase

dense jungle
red sedge
#

.>

#

f-strings being integrated into the peg parser seems like this could get fixed up

#

r/f/u prefix is a CST concern imho

dense jungle
#

Black already drops u prefixes for what it's worth

red sedge
#

Does the AST expose u prefixes?

dense jungle
#

no

red sedge
#

Hmm redundant f prefixes is definitely an ast bug then

#

Are redundant r prefixes in the AST?

dense jungle
#

no triple quoting either

red sedge
#

Points to redundant f strings being exposed to the AST being a bug

#

And related to the fact that f-strings get parsed in a second pass

dense jungle
#

Yes, it's definitely unexpected. When I tried it I expected it to be the other way around, because we removed fs from implicitly concatenated strings and that is AST-safe

#
"Module(body=[Expr(value=JoinedStr(values=[FormattedValue(value=Name(id='x', ctx=Load()), conversion=-1), Constant(value='a')]))], type_ignores=[])"
>>> ast.dump(ast.parse('f"{x}" f"a"'))
"Module(body=[Expr(value=JoinedStr(values=[FormattedValue(value=Name(id='x', ctx=Load()), conversion=-1), Constant(value='a')]))], type_ignores=[])"
red sedge
#

Seems like a public python function to peephole optimise an ast and return a new one would be popular

flat krakenBOT
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];
    • run `...
bright glacier
#

Black is not a linter so nope

#

And don't worry you have found the right place!

#

Yes. You could run black manually with the --diff to see what would be changed but that's it

#

What would you want to see?

#

What kind of problems?

#

Yeah that's out of the picture since black doesn't operate by first detecting issues and then fixing them. It only knows how to turn some code into properly formatted code. Kinda like setting something in a silicon mold

#

The line (number) would be a lot easier but that's still unlikely

#

I have no idea, I don't use VSCode often and I have never really used its formatting integration

austere lava
#

I don't think format on type is supported by Black at the moment

#

(nor any other python formatter I'm aware of)

little parrot
austere lava
#

not really

#

at the moment

#

well, it depends. If you wanna format unfinished files while you're typing, that would need an error-recoverable parser

#

which neither libcst nor black has at the moment

#

there are plans for libcst to gain this feature though

#

there are many other considerations though. People often use Black to detect syntax errors; that wouldn't be as easy with such a solution

little parrot
#

People use black to detect syntax errors yert?

silent apex
austere lava
#

yeah and it'd require rewriting Black

silent apex
austere lava
#

the parser is generated using PEG at the moment

silent apex
#

got it, got it

austere lava
silent apex
#

oh yeah, I remember looking through that. I haven't had a very good experience with autogenerated parser and good error reporting/resilience.

austere lava
#

well, CPython has a generated parser ๐Ÿ™‚

#

it's the only mainstream language implementation I know of that doesn't hand-roll its parser

silent apex
austere lava
#

yep

#

I mean it technically can find multiple errors but just reports the furthest one

silent apex
#

yeah, for the python parser I've been writing, I've pretty much resigned myself to handwritten for error recovery >.<

austere lava
#

not even close to error recoverable

#

why are you writing a parser?

silent apex
#

I honestly don't know, beyond "I felt like it"

austere lava
#

best reason 100%

silent apex
#

does black operate directly on the libcst CST?

austere lava
#

I wish

silent apex
#

sorry, not libcst, but whatever other lib (blib2to3?)

austere lava
#

it uses its own forked lib2to3

#

yeah

#

the code is tightly coupled to the parser

flat krakenBOT
#

Describe the style change

If a function/class is defined at the start of a non-scoping indent (e.g. if, for) a blank line is inserted before the function.
I would like this removed, since:

  • If an indent is scoping (e.g. def, class) no blank line is inserted, style should be consistent.
  • I believe this is redundant since the indent already separates the function definition well enough.
  • Blank lines are not inserted for normal code, so I don't see the point of adding i...
slow ibex
#

I guess it works, but when you type your file has invalid syntax and black cant do anything

flat krakenBOT
flat krakenBOT
drifting trellis
#

How can I make black not go insane on lists like this for command line arguments

#

I'd rather it use word wrap in this example than add 40 lines into my program.

bright glacier
#

You will have to disable black via # fmt: off/on or # fmt: skip

drifting trellis
#

I'm still interested in using black, just specifically not on this one list.

bright glacier
#

Hence the formatting control comment ^^

drifting trellis
#

Oh, didn't know that was even a thing. Didn't understand what you meant ๐Ÿ˜„

#

Thanks!

bright glacier
#
# fmt: off
a = 'a'
# fmt: on

a = 'a'  # fmt: skip
#

that's an example

drifting trellis
#

๐Ÿ‘ ty

drifting trellis
hot egret
bright glacier
#

I honestly don't know. I personally will try to avoid # fmt: skip since I don't trust it

#

the implementation is pretty buggy and I've been meaning to improve it but obviously that hasn't happened yet

#

I'm pretty familiar with # fmt: off/on though

lament crow
bright glacier
#

๐Ÿ‘€ my goodness

dense jungle
#

I love it

quartz stag
#

small request, i need a pep 9001 black formatter

silent apex
#

So you'd basically need to rewrite the whole project.

red sedge
red sedge
drifting trellis
#

In this context, this is simpler to understand.

bright glacier
#

@dense jungle how would you like to be credited in my mypyc blog series? I can do full name and link to your github profile, or would you like something else?

#

I'm still in the process of editing it, but I'm working on it again. Hopefully I can finish editing today ๐Ÿคž

exotic stratus
#

Hey, I've been trying out black and find its results pretty nice for the most part, but this is something I don't quite understand; why would the compact format (single line) be considered better by black? Imho, it's less readable when passing multiple kwargs in. Wondering about a second opinion on this.

little parrot
fluid hearth
bright glacier
little parrot
#

This is an interesting read thanks for writing this up

solid adder
plain atlas
#

(in case it gets buried on /newest)

solid adder
#

Please don't link to the submission directly

#

Bumping from a direct link doesn't do anything

bright glacier
#

lol, I'm not enough of a nerd to know how to use HN. I don't even have an account there, thanks y'all

solid adder
#

It's annoying the link has to be dug out of /newest but it's how the game is played

dense jungle
#

do you know for sure that's true? I've heard it before but who knows whether they changed the rules

solid adder
#

I don't know anybody at Y Combinator if that's what you're asking

#

But it's a well known rumor at least

fast heart
#

@bright glacier Which tool produced this graph?

#

I saw something like it on the discourse

bright glacier
#

I thought I linked 'em?

fast heart
#

I skipped the important line and looked at scalene ๐Ÿ’€

bright glacier
#

but either way I used cProfile and then used gprof2dot (the yelp fork, not the original one) piping the output into the dot linux utility

#

it is really useful

solid adder
silent apex
#

oh no I can't find it anymore

flat krakenBOT
#

Describe the bug

When run with python3 -m black (used by vscode) black keeps the current working directory inside sys.path which can result in a crash if there are name conflicts between black's imports and the files in the current working directory

To Reproduce

  • touch ast.py
  • Run python3 -m black ast.py

Output:

python3 -m black ast.py 
Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 188, in _run_module_as_main
    mod_nam...
quartz stag
# bright glacier it is really useful

heya, if i had some questions re: mypyc could i ask them here or is it strictly black? although i might have to do with it in the future re: async

tight walrus
#

Hi

flat krakenBOT
#

The latest release, 22.3.0, issue #2918, PR #2942, has broken formatting for function definition and call. In previous versions of Black the following:

def intentional_comma(a: int, b: int, c: int,) -> int:
    return a + b + c

def intentional_comma(a: int, b: int, c: int,):
    return a + b + c

intentional_comma(a=10, b=20, c=30)

Would be formatted to:

def intentional_comma(
    a: int, 
    b:...
flat krakenBOT
flat krakenBOT
#

Nightly CI failed due to Setup jobs failed to start

Current runner version: '2.291.1'
Operating System
  Ubuntu
  [2](https://github.com/redhat-performance/benchmark-runner/runs/6704381902?check_suite_focus=true#step:1:2)0.04.4
  LTS
Virtual Environment
  Environment: ubuntu-20.04
  Version: 20220529.1
  Included Software: https://github.com/actions/virtual-environments/blob/ubuntu20/20220529.1/images/linux/Ubuntu2004-Readme.md
  Image Release: https://github.com/actions/virt...
flat krakenBOT
#

Describe the style change

Currently, black does not add a space after unary operators like unpacking, but does around binary operators. When operator hugging seems to contradict precedence, should black insert parentheses?

Examples in the current Black style
In all cases, multiplication occurs before unpacking, but it appears that unpacking happens first.

(*2 * (0,), 0)
(*(0,) * 2, 0)
s = (
    *(0,)
    * a_long_variable_or_expression_that_evaluates_to_2...
flat krakenBOT
flat krakenBOT
flat krakenBOT
flat krakenBOT
flat krakenBOT
#

I got latest Black from PyPI, and got all latest libs for it.
I got lib2to3 from
https://github.com/python/cpython
and renamed its folder to 'blib2to3'.
now I run CudaText plugin 'Black formatter' and get errors

Traceback (most recent call last):
  File "/home/user/.config/cudatext/py/cuda_fmt/__init__.py", line 227, in format
    res = helpers.get_props(lexer)
  File "/home/user/.config/cudatext/py/cuda_fmt/__init__.py", line 148, in get_props
    return self.get_item_props(i...
flat krakenBOT
#

Describe the bug
this becomes

return (
    flu(files)
    .map(to_path)
    .flatten()
    .collect()  # type: ignore
)

this.

return flu(files).map(to_path).flatten().collect()  # type: ignore

To Reproduce
Run above code with these arguments:

$ black --target-version py310 -- test.py

Expected behavior

intentional parenthesis around method chains should be respected and not break into single statement.

Environment

...

bright glacier
#

what were they even thinking?

austere lava
#

I'm glad at least they provided reasonable repro steps instead of just the error ๐Ÿ™‚

lament crow
# flat kraken

was it always like this? I know that call chains are at least somewhat preserved if they're longer than line length but did black always join it into one line if it fit?

austere lava
#

IIRC it's been like this for a long while now

dense jungle
#

yes

flat krakenBOT
bright glacier
#

wtf

#

I'll respond to it btw, Jelle if you're on it already lol

flat krakenBOT
#

I try to update Black in CudaText plugin
https://github.com/cudatext-addons/cuda_fmt_python_black

and now after update of all libs I got this (Ubuntu x64 Python 3.8.10)

Traceback (most recent call last):
  File "/home/user/.config/cudatext/py/cuda_fmt/__init__.py", line 227, in format
    res = helpers.get_props(lexer)
  File "/home/user/.config/cudatext/py/cuda_fmt/__init__.py", line 148, in get_props
    return self.get_item_props(item)
  File "/home/user/.config/cudatext...
bright glacier
#

oh, wow this plugin is quite outdated

bright glacier
#

they are the maintainer of that plugin given the repo is owned by them..?

#

either way, I'm not sure if they know how python packaging works

flat krakenBOT
#

CudaText plugin used this old code which didnt support Py 3.9 and 3.10

import sys
import os
import re
import json
from cuda_fmt import get_config_filename

PY_OK = sys.version_info[:2] >= (3, 6)
if PY_OK:
    sys.path.insert(0, os.path.dirname(__file__))
    from . import black
    from .black import TargetVersion as Ver

    ver35 = {
            Ver.PY35,
            Ver.PY36,
            Ver.PY37,
            Ver.PY38,
            }
    ver36 = {
          ...
bright glacier
#

sigh

#

does anyone actually maintain this plugin?

flat krakenBOT
#

I have old code from 2020 which used 'attr' lib in Black.
folder of 'attr':

$ ls
_cmp.py     converters.py   filters.py   __init__.pyi  setters.py      _version_info.py
_cmp.pyi    converters.pyi  filters.pyi  _make.py      setters.pyi     _version_info.pyi
_compat.py  exceptions.py   _funcs.py    _next_gen.py  validators.py
_config.py  exceptions.pyi  __init__.py  py.typed      validators.pyi

I dont see .pyc files created here! so its not used?

dense jungle
bright glacier
#

what is even going on

errant barn
#

honestly

dense jungle
#

can we politely tell them to stop opening issues

#

and we're not going to fix their project for them

dense jungle
#

interestingly CudaText has nothing to do with CUDA the GPU programming thing, it's an actual text editor

#

written in Pascal of all things

bright glacier
#

Yeah, I was going to say the CUDA team should know Python better but nope, it's not even CUDA related

frozen yacht
#

I'm running into a case where I pass a file to black e.g. black module.py but it just says "No Python files are present to be formatted. Nothing to do"

#

Yet when I paste the code into the playground it does format it.

#

What gives?

bright glacier
#

What is emitted when you pass --verbose to the command?

frozen yacht
#

Ah

#

ignored: matches the --force-exclude regular expression

bright glacier
#

It sounds like --force-exclude is being applied.

#

yup.

frozen yacht
#

The file is snekbox/nsjail.py

#

What I have is force-exclude = ["snekbox/config_pb2.py"]

#

How does that match?

bright glacier
#

I have no idea but force-exclude's type is a string

frozen yacht
#

oh

bright glacier
#

hence regular expression in the output

frozen yacht
#

I though it was a list of regexes

#

In hindsight I suppose that doesn't make much sense

bright glacier
#

Ah fair enough, no worries. I wonder if the help output could be any clearer. I think we state it's a regex though.

frozen yacht
#

I think i just didn't read carefully

#

Or maybe confirmation bias from excludes of the same file for other tools requiring a list

dense jungle
#

wonder if we could give an error if it's a list

frozen yacht
#

That would be nice

#

Or more generally reject config files if they don't conform to the schema

#

Instead of having some silent behaviour

bright glacier
#

OK I really need to sit down and review some PRs.

#

I've been kind of out of it lately, but I have some spare time

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];
    • run `pip install...
flat krakenBOT
flat krakenBOT
flat krakenBOT
flat krakenBOT
red sedge
#

probably want to run pytest with filterwarnings=error

flat krakenBOT
earnest gust
#

can anyone help me with how to use it? i dont really understand the doc

#

ive installed it from github using terminal

halcyon rain
flat krakenBOT
#

Describe the bug

If a line that exceeds the character limit has parameter comments, the function won't be moved to a new line inside parentheses.
Without parameter comments, Black will move the function inside parentheses.
Black should be consistent with these cases.

To Reproduce

For example, take this code:

long_variable_name = long_function_name(
    arg1,
    # comment
    arg2,
)

long_variable_name = (
    long_function_name(
        arg1,
      ...
earnest gust
#

for python only

earnest gust
#

thank you

fast heart
#

Is this expected?

def benchmark(function=None, **kwargs):
    if kwargs:

        def _inner_decorator(function):
            _benchmark(function, **kwargs)

        return _inner_decorator
    if function is not None:
        _benchmark(function)
    else:
        raise TypeError("benchmark requires a function to benchmark")
#

Referring to the blank line after the if statement

#

Black seems to be enforcing it

errant barn
toxic stormBOT
fast heart
flat krakenBOT
#

Please add the skip_new label to this PR

Description

Removed the hard coded SOURCE list from test_format.py. Now, black is run as part of the Lint CI and looks for sources automatically.

Checklist - did you ...

  • [ ] Add a CHANGELOG entry if necessary?
  • [X] Add / update tests if necessary?
  • [ ] Add new / update outdated documentation?
flat krakenBOT
#

Hello ! I'm facing an issue while trying to use black to lint a file.

When trying to lint my piece of code (either with pre-commit or running black itself), the below error happen. Unfortunately, i can't provide any example as it's not my property.

The resulting error is:

error: cannot format core/nomenclature/tests.py: INTERNAL ERROR: Black produced code that is not equivalent to the source. Please report a bug on https://github.com/psf/black/issues. This diff might be helpful...

flat krakenBOT
#

Description

This is one possible fix for: https://github.com/psf/black/issues/3040

I have added the --project-root command line argument which can be used to force black to evaluate paths relative to that root. Otherwise, black will pick up things like .git folders in submodules and use the submodule path as the project root instead.

We want to auto-format our code in Visual Studio Code but want to exclude 3rd-party git submodules by specifying them in pyproject.toml. Thi...

flat krakenBOT
errant barn
#

"Any color you like" is a reference to Henry Ford

flat krakenBOT
#

Describe the bug

Black's --preview mode produces invalid code in the first pass, causing second pass to fail.

To Reproduce

For example, take this code:

some_dict = {
    "something_something":
        r"Lorem ipsum dolor sit amet, an sed convenire eloquentiam \t"
        r"signiferumque, duo ea vocibus consetetur scriptorem. Facer \t",
}

And run it with these arguments:

$ black --preview file.py

The resulting error is:

error...
flat krakenBOT
flat krakenBOT
bright glacier
#

I can't remember what it looks like though.

bright glacier
#

myst-parser likes to pin sphinx hence the combined PR

flat krakenBOT
bright glacier
#

We have 31 open pull requests ๐Ÿ‘€

#

Either way, I'm probably done for the night. I still have a lot of things to pick up, but at least I have a start now ๐ŸŽ‰

#

Can't wait until this goes down again ๐Ÿ˜„

austere lava
flat krakenBOT
bright glacier
#

Thanks for clarifying!

fast heart
#
some_dict = {
    "something_something":
        r"Lorem ipsum dolor sit amet, an sed convenire eloquentiam \t"
        r"signiferumque, duo ea vocibus consetetur scriptorem. Facer \t",
}
#

Under preview, what should this be mapped to?

#

I think the issue is related to the fact that r-strings aren't merged with StringMerger

#

Then I think StringParenWrapper makes a mistake

neon loom
#

ichard action spamming my inbox ๐Ÿ˜

flat krakenBOT
bright glacier
flat krakenBOT
#

Description

Added a new feature in preview mode: Black now knows how to trim trailing whitespaces inside f-strings.

For example the following code:
``python
print(f"there are { 2 } unnecessary spaces in this f string")
print(f"there are { 3} unnecessary spaces on the left")
print(f"there are {3 } unnecessary spaces on the right")
print(f"you should trim { 'me' } and { 'me!' }")
print(f"trimming is easy as { 1 + 1 } == {2}")


will transform to:
```python
pr...
austere lava
#

re #3119 above, I don't know if we should accept partial solutions like this. I fully get that a majority of fstrings only have trivial expressions (names or attributes) in them, but i'm not entirely sure the added complexity is worth the benefit

neon loom
#

Or am I missing something

bright glacier
#

Yeah, it's definitely redundant. They have a point that it shouldn't probably be in the test suite though

errant barn
#

Oh is his most recent point true, that even our dev pre-commit runs with the latest released version? In that case the redundancy would be justified

errant barn
austere lava
#
  1. I don't see Black ever gaining support
  2. There are other tools that already do a great job (isort and usort come to mind)
errant barn
#

big +1

neon loom
neon loom
#

Both are way slower so I donโ€™t want that slowness in black

austere lava
#

well, isort is much faster than black

neon loom
#

O super interesting

#

Usort needs some love there

lament crow
#

Since isort 5 got released with proper black support, there really isn't a good argument to support optimizing imports in Black

#

and now there's also usort

#

The state of things is a lot better than it was back when the issue was made.

#

Once isort 5.11 is released, the only discrepancy I'm aware of - magic trailing commas - will be properly supported as well.

austere lava
#

๐Ÿ˜„

#

on a related note, fastero is pretty cool; gotta remember to use it instead of timeit

neon loom
#

This how you profiled?

austere lava
#

Nah I used py-spy for profiling

late dewBOT
#

.pre-commit-config.yaml lines 7 to 13

- id: black
  name: black
  language: system
  entry: black
  minimum_pre_commit_version: 2.9.2
  require_serial: true
  types_or: [python, pyi]```
bright glacier
#

we run black over the project as a system hook, so effectively we're just running black as a shell command

#

now if the black command doesn't point to the dev version of black, then it'll probably use the pypi version that's available somewhere on the system

#

for CI, we install the dev / currently being tested revision of black before running pre-commit

late dewBOT
#

.github/workflows/lint.yml lines 22 to 28

- name: Install dependencies
  run: |
    python -m pip install --upgrade pip
    python -m pip install -e '.[d]'

- name: Lint
  uses: pre-commit/action@v3.0.0```
bright glacier
#

not sure why we install with the [d] extra to be honest, but we are using the development version

flat krakenBOT
#

Description

Updates and closes https://github.com/psf/black/pull/3120:

The new https://github.com/actions/setup-python/releases/tag/v4.0.0 now requires setting a Python version via python-version: or python-version-file:.

Let's use python-version: "*", already used for one of the workflows:

https://github.com/psf/black/blob/162ecd1d2cf9471efefb5b61c17d28b73acb79a1/.github/workflows/upload_binary.yml#L39

Checklist - did you ...

  • [n/a] Add a CHANGE...
mint barn
#

sussy baka

cloud tapir
#

Hi Team! May I have a pointer to whatโ€™s the difference between black and black[jupyter]? I searched in Black Repo and documentation. It seems that black[jupyter] adds extension based on Black to support formatting Jupyter notebooks. Iโ€™m curious if there are any features in vanilla black but not in black[jupyter]? Thanks a lot!

errant barn
cloud tapir
#

Thanks!

flat krakenBOT
flat krakenBOT
worn zenith
#

I just want to share with the black team that all roughly 40 different python containers we run at my job are now entirely scrubbed by black and it is a pre-commit hook now too. We used to have little tiffs over standards and personal preferences, but having an outside decision maker helped us a ton by removing any agency on the matter. We just set the line length limit to 120 and forced to keep trailing commas in pyproject.toml files, which is also great, because now that we have the pyproject.toml standardized we've started to standardize our pytest env on that too.

#

So thanks for the work.

austere lava
trim cobalt
#

is that pico seconds?

mint barn
austere lava
#

I used the fastero pypi package

flat krakenBOT
neon loom
#

Error: Invalid value for 'analysis': File 'preview-changes-main-6c1bd08f16.json' does not exist.

#

Also, when we targeting next release. I've been slack here. Looking at our changes - i think it's well past time?

dense jungle
#

yes, we should do it soon

neon loom
#

I'll take a look later today and get a PR up for the release and the someone can panic and say they want something merged first like always happens ๐Ÿ™‚

bright glacier
#

hmm I'm not sure if I agree with removing black from pre-commit

#

I guess from a purity standpoint, it's not great, but functionally it's mostly fine.

bright glacier
#

It compiles black before testing it because it actually saves time. I can make it fall back to running black under interpreted if compilation fails if you'd like.

bright glacier
#

pre-commit for this situation is far from perfect as it doesn't always pick up the dev version of Black (usually when you don't activate a virtual environment) when checking the project, but IMO it's better than not having it.

#

I'm OK with moving the self-check outside of the test suite, but assuming we can work around pre-commit's flaws, then I'd suggest keeping black in pre-commit.

#

Pretty sure we could disable the black hook in lint CI if we so wanted.

neon loom
neon loom
#

I also fine running the stable version will cause confusion and pain if we have formatting changes locally but the stable version does not - This will happen in next release we move preview changes onto main by default in late December

#

I also personally don't have the energy to debate, so if people want it back, feel free to restore it. I just find it wasteful, potentially causing confusion and we don't get pre-commit running on our differnet supported environments.

Ideally it would be nice to have pre-commit to install black from the local commit.

errant barn
#

Hi, sorry but this channel is for Black development, try the #help category!

wicked schooner
#

ok

grand hatch
#

?

errant barn
#

Hi, sorry but this channel is for Black development, try the #help category!

bright glacier
#

psf/black#3111 makes no sense to me.

toxic stormBOT
bright glacier
#

I'll check the sdist for a few of the reported versions, but according to the tags, ParameterSource should exist ยฏ_(ใƒ„)_/ยฏ

#

I wonder if a redistributor of click messed up

austere lava
#

hm yeah click.core.ParameterSource has been a valid name since click 8.0

fast heart
#

I assumed it would be ubuntu or debian but I couldn't reproduce in a ubuntu VM or in a ubuntu docker image

#

And the debian package worked fine in a virtual environment

#

Perhaps it could be something like conda causing two different versions to be installed and whichever python install is running black is using the wrong version

#

Ubuntu seems to have 5 python-click packages, 3 of which are out of date so Ubuntu isn't entirely ruled out

#

Ubuntu's package management system scares me ๐Ÿ˜‚

#

Oh interestingly, all of them are out of date. It's just that 3 of them have versions < 8.0 the other two are 8.0.3

flat krakenBOT
#

I discoverd an different beheavior between "change" and "check":

If I run "black" to my project, it reports no changes.

$ black --diff *.py
All done! โœจ ๐Ÿฐ โœจ
12 files would be left unchanged.

But "--check" reports an issue

$ black --check --preview --diff *.py
--- get_curve.py	2022-06-17 07:38:10.719823 +0000
+++ get_curve.py	2022-06-17 07:39:26.411995 +0000
@@ -31,11 +31,12 @@
         sens_data, sens_ext_datal, sens_owm_data, t1, t2, t3 = extract_pg_data(
       ...
flat krakenBOT
little parrot
#

What's the reason black splits strings that are too long at the end of a word and moving the white space to the start of the new line?

dense jungle
lament crow
flat krakenBOT
flat krakenBOT
flat krakenBOT
flat krakenBOT
#

Describe the bug
Black currently inserts an empty line before functions when they are defined inside a block.
I don't want that to happen if a function is the first thing defined in a block, so I try to add a skip (see also #3089).
I get an error as a result:

INTERNAL ERROR: Black produced different code on the second pass of the formatter.

To Reproduce

def func():
    try:
        if True :# fmt: skip
            async def another_func():
                pass...
mild abyss
#

i wish

flat krakenBOT
flat krakenBOT
flat krakenBOT
flat krakenBOT
flat krakenBOT
#

For golang projects, the formatter can reorder import statements, which makes the code look cleaner.

For C++ projects, the code style also contains guidance on the order of include statements.

That being the case, why doesn't black consider reordering the Import statements?

exotic stratus
#

Two questions:

  1. is there a reason other than character length per line that black decides to put quotes in own lines? (see picture)
  2. if I have max-line-length set in my .flake8, does black consider it? Or should the line adjustment be made to some other config file?
dense jungle
exotic stratus
dense jungle
#

not sure what you mean by (1), I don't see quotes on its own line

exotic stratus
#

Sorry, brackets

#

Black pushed the line onto 3 lines

bright glacier
#

Yup, presumably when it's collapsed it violates the line length limit hence why it's split.

exotic stratus
#

The github readme mentions reading opts from pyproject.toml. Should I use that, or own config file that was mentioned above?

dense jungle
#

that's the file I meant

bright glacier
#

Jelle was unclear, Black only looks at pyproject.toml by default

dense jungle
#

I never misspeak ๐Ÿ˜›

bright glacier
#

Or make typos.

exotic stratus
#

Alright, seems like [tool.black] is the key

#

Thank you

#

Confirming that it was the line length

#

Excuse me for bothering further, is there a verbose option when running black via the CLI or otherwise, where each change is explained with the reasoning and which black rule it met for the adjustment?

dense jungle
#

and it doesn't have a concept of "rules" even internally

#

rather most of the complexity is in a big algorithm for how to fit the code within the line length

exotic stratus
#

Ah, I intuitively thought it was some sort of a priority-based rule engine. My fault for not digging into the sources. Thank you regardless

dense jungle
#

for completeness, there is a verbose mode, but it mostly prints info about where it finds the config and what files it looks at

steep void
#

Has anyone run into this? - Currently running black v20.8b0 in my environment and running into issue when running pip install I hit the following error

Collecting black==20.8b0
  Using cached https://nexus.jx.cicd/black-20.8b0.tar.gz (1.1 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  ร— Preparing metadata (pyproject.toml) did not run successfully.
  โ”‚ exit code: 1
  โ•ฐโ”€> [51 lines of output]
      Traceback (most recent call last):
        File "/private/var/folders/0t/f4fb584j0d9d7bb4g6f05vy40000gp/T/pip-build-env-pbooiros/overlay/lib/python3.7/site-packages/setuptools_scm/_entrypoints.py", line 72, in <module>
          from importlib.metadata import entry_points  # type: ignore
      ModuleNotFoundError: No module named 'importlib.metadata'
bright glacier
#

huh.

#

I have never seen this issue before

steep void
#

It just started happening today

#

If I upgrade the version to one of the latest versions of black I dont see the issue pop up anymore

bright glacier
#

I wonder if the latest setuptools-scm release broke things, again.

steep void
#

@bright glacier I think you maybe right, I see new versions of setuptools-scm

bright glacier
#
  Preparing metadata (pyproject.toml) ... done

can't reproduce on Python 3.7 with black==20.8b0

steep void
#

if you uninstall black and importlib.metadata manually then install black, I was able to reproduce

bright glacier
bright glacier
steep void
#

black==20.8b0 upgrade ==> 21.12b0

#

I couldnt go to latest because of conflicts with click but this is two versions back

bright glacier
#

yeah we have wheels available for 21.12b0 so that does eliminate setuptool-scm entirely

steep void
#

@bright glacier thanks for the help on this, I'll test more on the setuptool-scm recent release but I think we'll just stick with the newest version (21.12b0)

bright glacier
#

I still can't reproduce the issue even if I uninstall importlib.metadata before install black==20.8b0

steep void
#

weird

#

I wonder if I have something else in play that might be producing this

dense jungle
#

what is your pip version?

steep void
#

pip 22.1.2

#

@bright glacier could this possible be the issue that we were talking about

#

importlibs with python 3.8 or higher

bright glacier
#

It was an issue with setuptools-scm. I chatted with the setuptools-scm maintainer and they confirmed.

steep void
bright glacier
#

Ah that's good to know, thanks for investigating further!

#

If you encounter other packaging weirdness (well except for poetry or PDM, those aren't PyPA projects), just know discord.gg/pypa exists

#

If it's related to Black, obviously ask here first, but just in case it comes in helpful ^^

steep void
#

thanks for sending this, I'll join this, I like finding weirdness in code and tracing its source

bright glacier
#

I'm going to see if I can work on the release CI situation to hopefully unblock a new release

#

I'd appreciate it if someone could go through the commit log / changelog and make sure any code style changes have been (sufficiently) documented in the (future) Black Code Style documentation