#black-formatter

1 messages Β· Page 32 of 1

flat krakenBOT
muted haven
#

@dense jungle I plan to merge this since there are code in the wild (as the user reported) that use this syntax, and I don't think being too permissive for black is a problem. WDYT?

dense jungle
muted haven
#

Ah, that is also fine. I am not too sure it will be reverted, but who knows

dense jungle
#

yeah I'd lean towards not reverting, but Pablo seems to think it's a possibility πŸ™‚

flat krakenBOT
#

When a comment starts with a '#' character and after that two or more blank spaces, other tools like flake8 report

E262 inline comment should start with '# '

indicating that a comment should start with a '#' character and only one blank space.

I think it would be great if black handle this replacing two of more blank spaces after a comment start with a single blank space. Would this be a nice addition to the black formatting style?

bright glacier
#

I've been debugging why my power fix PR is changing formatting behavior when it shouldn't for over 40 minutes and I'm no where closer 😦

#

I know what function call in trans.py causes it but I have no idea what it is doing under the hood causing the weird behaviour

dense jungle
bright glacier
#

I haven't found a meaningful difference at the Leaf level yet

#

I have no idea.

ruby trench
lament crow
lament roost
#

Pre-commit definitely feels faster after bumping black's version to latest

bright glacier
#

hmm that's weird since doesn't pre-commit clone black instead of using PyPI? and on top of that 22.1.0 has a stability hotfix which reduces formatting throughput by 50%

#

I suppose the 3.10 parsing improvements might be what is responsible for the speedup you feel since the above is only applicable for changed files thankfully.

lament roost
#

I'm running the local black through pre-commit instead of the normal one

lament crow
#

eww

#

:)

humble tulip
#

How is everyone doing? My name is James. This is my favorite channel. God bless, James!

unique mulch
#

So this is a setting in VS Code, just something to take note of

#

Maybe something to add to the Editor Integration part of the docs

lament crow
#

This is a Python server, not a Dart one.
Technically, Black's goal is to let you forget about formatting so the ruler shouldn't really matter as Black will wrap the code appropriately on its own.

flat krakenBOT
#

Describe the bug

Error formatting python sources in https://github.com/pytorch/fairseq

To Reproduce

Clone fairseq and run black on offending files:

fairseq $ black --version
black, 22.1.0 (compiled: yes)

fairseq $ black --check \
  examples/simultaneous_translation/modules/monotonic_multihead_attention.py \
  examples/speech_text_joint_to_text/criterions/text_guide_cross_entropy_acc.py \
  examples/wav2vec/unsupervised/scri...
unique mulch
flat krakenBOT
#

The Python team for VS Code has been working on putting various tools we support behind LSP and breaking them out into their own extensions This work is now far enough along that we wanted to share the extension prototypes for your tool with you and see if you had any interest in owning the extension or the Python-based LSP server backing it yourself?

If you don't want to take on that res...

bright glacier
#

looks like we procrastinated for too long on that blackd PR :p /lh

golden swallow
#

how do i connect black with pycharm

teal goblet
#

do you have black[d] installed?

unborn lion
#

How can I avoid deadlock(mysql) in python multithreaded script?

short forge
teal goblet
#

Black somehow turned this. ```py
if sys.version_info >= (3, 10):

TypeAlias added in python 3.10

from typing import TypeAlias

else:
from typing_extensions import TypeAlias

Into this. ```py
if sys.version_info >= (3, 10):
peAlias added in python 3.10
    from typing import TypeAlias
else:
    from typing_extensions import TypeAlias
bright glacier
#

πŸ‘€ What version?

teal goblet
#

22.1.0

teal goblet
#

just changing the line-length to 79 for flake8

bright glacier
#

still not reproducible hmmm

teal goblet
#

could also be a isort thing.

#

Yeah, it was isort doing it.

elder tusk
dense jungle
#

Black itself is also unlikely to have this sort of bug for similar reasons

#

we do an AST safety check that makes sure the output is valid Python equivalent to the source

little parrot
#

isnt there an atomic mode for isort?

elder tusk
mint barn
#

Hi

#

How to learn coding

#

with python

lament crow
#

this must be a troll right...

errant barn
#

:D

#

damn.

#

gotta close my personal one too

muted haven
#

I got the same exact reply on my repo, so who knows maybe it is a bot after all

lament crow
#

I'm not sure honestly

#

they fill out CLAs

bright glacier
#

so they ignore the fact you need permission from all contributors to relicense (which can be covered by the CLA) but sign CLAs...

lament crow
#

I can't explain it any other way than them being a troll

#

I know there are some die-hard fans of GPL but this doesn't even contain any reasoning why you would want to change license (not that it would change anything of course lol)

errant barn
#

they responded with reasons so I'm calling "no troll" :D

teal goblet
#

Why would you switch to a more restrictive license than MIT?

lament crow
#

Since you're just creating derivative work under stricter license which MIT doesn't disallow

#

Hence why it's permissive :D

tired shard
#

If anyone got time, would appreciate some reviews on my PRs lemon_cowboy

flat krakenBOT
#

Description

One of the things discussed in issue #144 was quote placement. Reading through the discussion, there seemed (to me, at least) to be general support for normalising this.

This does two things. For very short docstrings,

def foo():
    """
    Why is this on its own line?
    """

becomes

def foo():
    """Why is this on its own line?"""

and for docstrings of more than one line, a single newline at the start and (pre-indent) end a...

dense jungle
#

^ um probably not

supple birch
#
print ('pp')
bright glacier
#

seems like a little unnecessary, no?

ivory pumice
#

seems necessary to me cheif

eternal egret
#

Does the psf/black vim plugin run a version of black sourced from the repo?

#

the vim plugin is running out of date black despite both my venv and system black being up to date

#

does something in the repo need to be updated separately for the vim plugin that got missed?

eternal egret
#

ahah, you need to separately run BlackUpgrade

mint barn
#

(I know very few things of Python) I just had an idea: can somebody write a programm that makes student notes more eco-friendly? For instance, I have notes on a course but all the pictures and word use a lot of space and inkt. I put it in that programm and is so adjusted that nothing will be deleted, but the best usage of space and as little inkt as possible is used. Still the notes are comprehensive etc. Can somebody make that??

glacial drum
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 `...
topaz rapids
#

Hi

flat krakenBOT
flat krakenBOT
#

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

It would be nice to be able to just use black src in both CI and local development.

Describe the solution you'd like

When black reformats any file, its return code would be 1 rather than 0.

Describe alternatives you've considered

Run black via pre-commit, which always returns 1 if a tool would've modified a file. This is fine for projects which use pre-commit, but (IMO, unfortunatel...

bright glacier
#

I think I'm beginning to understand why the power op comment PR is changing formatting although it's still unclear what the root cause is

#
❯ black test2.py --check --diff --color -l 79 --fast
transforming line
running transformer: <black.linegen.rhs object at 0x7ff5f41136d0>
called trailers
calling rhs via LOOP 0 set()
rhs called
rhs called
aaaaaaaaaaaaaa = 111111111111111111111111111111111111111111111111111111111111 + (
 --     a ** a
 -- )

calling rhs via BEST EFFORT
rhs called
rhs called
aaaaaaaaaaaaaa = 111111111111111111111111111111111111111111111111111111111111 + (
 --     a ** a
 -- )

transforming line
running transformer: <black.linegen.rhs object at 0x7ff5f4dc0310>
called trailers
calling rhs via LOOP 0 set()
rhs called
<black.linegen.rhs object at 0x7ff5f4dc0310> No brackets found
running transformer: <function hug_power_op at 0x7ff5f3f1fdc0>
<function hug_power_op at 0x7ff5f3f1fdc0> No doublestar token was found in the line.
transforming line

always fun debugging like this :P

thick hazel
bright glacier
#

Well yeah I just added a handful print calls to figure out what's going wrong in a patch I'm currently working on :)

celest sorrel
#

um guys

#

as a joke i made my black format to line length 5

#

and when i try and change it back to 120 its all kind of...fucked

#

is there a way to force 120 for everything? o.O

#

like

#

im scarred

#
from __future__ import (
    annotations,
)
dull olive
#

checkout your previous commit?

celest sorrel
#

im literally gonna cry

celest sorrel
#

is there a formatter that forces a line length of 120?

bright glacier
#

turn off the magic trailing comma

#

-C

celest sorrel
#

MY HERO

bright glacier
#

let this be a lesson in don't run any code rewriter unless you're OK with the changes being not undoable ^^

celest sorrel
#

πŸ™‡

bright glacier
#

unless you're using a SVC tool like git

celest sorrel
#

black betrayed me

#

i thought it was my friend 😒

flat krakenBOT
flat krakenBOT
#

Thanks for writing this up and putting it under the preview style.

I'm not yet convinced we should do this, since it could be disruptive. diff-shades currently gives us results only for pyanalyze (which happens to be my code), because it runs black with preview = True. As you see, I currently use a different docstring style :)

I'd be curious to see the result on more open-source code. Could you push a change to enable the new style without preview mode, so that we can see the diff-sha...

flat krakenBOT
bright glacier
#

@dense jungle I do have a work in progress patch to update diff-shades to force --preview, I can probably get it PRed soon

(I've just been having fun writing an "optimization" patch for mypyc and it was so engaging I ignored basically all notifications lemon_sweat )

dense jungle
#

and have fun optimizing mypyc πŸ™‚

bright glacier
#

the C compiler is still mad at me so I got some more work left but that doesn't sound too bad.

flat krakenBOT
bright glacier
#

Yup, that's why I said it was "in-progress", I still had to write the other workflow asserting stability

dense jungle
#

ah right πŸ™‚

#

I guess in that workflow we should skip projects like pyanalyze that turn on preview style

bright glacier
#

I was a little discouraged from writing it since a) it's probably a fair bit of work, and b) it involves changes to diff-shades itself since there's no way to force preview=False easily

#

... or yeah we could just skip them I guess

dense jungle
#

I think it's probably only pyanalyze, at least for now

bright glacier
#

hmmm, the diff-shades baseline run shouldn't be taking 8+ minutes. I wondered if I messed something up.

#

oh wait, I forgot I'm passing --preview ... anyway there's a crash

dense jungle
#

nice catch, I guess it gets confused about the comment in the middle of an implicit concatenation

kind idol
#

hi

#

there is blockchain code here

bright glacier
#

No blockchain is involved here, we instead like to play with tree structures πŸ™‚

bright glacier
mint barn
#

What is this project about?

silent apex
mint barn
#

Wow that’s awesome. Is it similar to HTML one where you press control shift f (or something) and it formats it to the right indexes.

silent apex
#

erm, it's often run from the command line, but a lot of editors have extensions to run it on save

mint barn
#

Sweet, great work!

silent apex
#

I've done nothing for it haha, thank all these wonderful people in purple

flat krakenBOT
#

Thanks for creating and maintaining black it is by far my favorite code styling tool (:

On some cases black's may be incompatible with Flake8's E501 (line too long).

For example, consider code like this:

func(
    long_long_long_long_long_long_long_long_long_long_long_arg=
    long_long_long_long_long_class.long_long_long_long_attr
    )

(less than 88 characters lines)

Black will edit it to:

f(
    long_long_long_long_long_long_long_long_long...
lament crow
#

how did you...

#

make it look like a label

#

lol

foggy trout
#

You use three `

#

and close it with 3 `

#

You can also add .py to the first ones

lament crow
#

talking about this

#

not the code blocks

foggy trout
#

Oh, well never mind lol

silent apex
# lament crow make it look like a label

If you just put the link https://github.com/psf/black/labels/F%3A%20linetoolong, github is smart and autoformats it. There's probably another way, but that's one I know of.

flat krakenBOT
#

Describe the style change

When an long expression contains function calls and joining operators black will choose to break the function call if the arguments exceeds the maximum line length. This can look pretty ugly. Instead, I think that black should break the outmost (least nested) parts of the expressions before inner parts of the expression.

Examples in the current Black style

    def parse_assign_stmt(self) -> Optional[ast.AssignStmt]:
        if isinstan...
safe fog
civic plume
#

who likes my idea

versed trout
#

Hi everyone, i want to ask u if anyone build befor a recommender system using ML ?

lament crow
#

@civic plume, @versed trout this is not a proper channel for this. Read the channel topic.

loud nebula
#

does anyone wanna play minecraft with me

bright glacier
#

!ot - A little off-topic for this channel :) perhaps ask in a OT channel?

late dewBOT
lusty crag
#

Sup, I'm working on a legacy python project and naturally it uses every python code style under the sun. I'm trying to introduce black in order to standardize it but there is quite a bit of resistance from the old devs. Chiefly they don't like:

  • """ Foo """ becomes """Foo"""
  • foo(very_long_line) becomes foo(\n\tvery_long_line\n)
  • 'this string' becomes "this string"
  • no alignment on "=" for variable assignments which are right next to each other

can I change these settings in black? From the docs it seems that fiddlin with small stuff like this is not really supported, am I out of luck/need to look to another automatic code formatter?

#

jikes, sorry for the formatting

errant barn
#

No, we provide very minimal style options unfortunately.

#

And deliberately so

lusty crag
#

Ok, thanks for the response πŸ™‚

flat krakenBOT
ancient depot
#

Good morning my name is Raj Mukherjee and I am new to this community. I am pursuing my B.Tech degree from Srm University in artificial intelligence and I am working on python for quite a few years and I have also started working on Data Science, Artificial Intelligence and Machine Learning so as per my interest I would like help and contribute something to this community

south ridge
ancient depot
#

Ok i will check it out

bright glacier
#

wat is CI doing ...

#

I wonder if this is just that edge case where the fact the PR isn't tested with main merged in

dense jungle
#

oh I think it intersected with another PR I merged

#

will fix

flat krakenBOT
flat krakenBOT
flat krakenBOT
flat krakenBOT
bright glacier
#

hmmm I don't really like this furo update

#

concretely I feel like the headings are now too bold, I could see how they could've seemed too dim previously but this feels like the other side of the spectrum πŸ™‚

#

Also, it's not that clear IMO that 22.1.0 is a higher heading than Highlights

fossil estuary
#
print('format deez nuuuuuuuuuuuuuuuuuuuuuuutz')
#

breh dis bot not werkin

lament crow
flat krakenBOT
#

Description

I saw pycln (which is a formatter for finding and removing unused import statements) a good addition to the current pre-commit hooks which I believe would ensure a high code quality standard besides black itself.

Also, I've two things to mention:

  • I'm the author of pycln.
  • This is not my first black contribution.

Anyway, feel free to ask any questions and/or reject/close this PR if you don't want to add more QA tools to black's pre-commit hooks.
...

lusty oasis
#

I want to customize black by cmd

plain atlas
#

I've found furo beautiful but also not beautiful

flat krakenBOT
#

Describe the style change

The following code:

def foo(a)
    print(a)

foo(a=([1, 2, 3]))

Should be changed into:

def foo(a)
    print(a)

foo(a=[1, 2, 3])

Examples in the current Black style

As for now, the example above is not changed.

Desired style

When circular brackets are not used to break up command parameters into different lines, it should be removed entirely

Additional context

I use python 3.9 on Windo...

dense jungle
#

the windows docs build is real slow

bright glacier
#

Seems to be a one off

radiant iris
#

HiImManh#2550

#

everybody add this account to the dead toxinloght

#

beacause he make a lot of thing that make problem

flat krakenBOT
#

A few thoughts:

  • This is going to make even more people upset for similar reasons as #2150. And I can't blame them; it's easy to imagine a change like this breaking some docstring processing system, and Black's AST safety guarantee is an important feature. Perhaps we should bite the bullet and add an option to disable docstring processing entirely. Such an option would disable both this PR and the existing docstring changes. New options aren't great, but an option that allows users to opt...
bright glacier
#

Given the initial negative feedback I'm inclined to reject the PR from a birds-eye view.

#

I haven't actually looked at the PR in detail yet.

dense jungle
#

what negative feedback? the downarrow emoji?

#

I think I mostly like it now, it really isn't much worse than the docstring processing we already do

#

I'm mostly scared of the backlash πŸ˜„

bright glacier
#

Yeah.. and I'm not particularly fond adding another option for this. I suspect there isn't enough consensus to make this feasible longterm.

dense jungle
#

what we choose creates the consensus for how Python is formatted

#

I'm mostly not joking

bright glacier
#

Yeah although I'm acutely aware of the issues that will get opened when there's any room for disagreement in style. I guess that's unavoidable though regardless if we change the style or not.

dense jungle
#

just means we get to close more

flat krakenBOT
#

I have a problem when tf.string.to_number make operation , I RESOLVED the issue.

This is because the last line of the conlleval train_data.txt it's blank , if we want to comprove this we can make:

pandas.DataFrame.from_dict(conll_data["train"]) and we can see the last row --> row NΒΊ 14041 have lists without nothing .

SOLUTION :
Go to data folder , open train_data.txt and delete the last row , it's work fine for me

little parrot
errant barn
#

Do reckon adding an option for docstring processing or more broadly AST safety would be better?

dense jungle
errant barn
#

psf/black#212 would be another one, but I'm totally ok with just the docstring thing

toxic stormBOT
errant barn
#

but that is also another one where an option for it would be odd

#

at least with docstrings it makes some sense

dense jungle
#

yes, I don't think an option for that would be necessary, unless we can really find a case where it makes a difference in practice

#

Docstrings are actually visible at runtime and there are lots of tools that parse them, so it's more plausible that reformatting them will break something

errant barn
#

I guess I just unnecessarily worry about future cases

#

yep

topaz rapids
#

What are you all talking about

errant barn
#

what do you want to know? :D

#

in general?

flat krakenBOT
flat krakenBOT
#

Description

MD5 is unavailable on systems with active FIPS (Federal Information Processing Standards) mode, such as RHEL or CentOS. That makes black crash when run on such systems:

python -m black --config pyproject.toml --check pcs/ pcs_test/
Traceback (most recent call last):
  File "/usr/lib64/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File...
flat krakenBOT
flat krakenBOT
dense jungle
#

we should probably do a new release soon

bright glacier
#

Yeah, I would've brought it up sooner but .. I'm still the blocker. The mypyc build workflow is still not up. Given my terrible mental state it would probably be better to just do it manually again, maybe even asynchronously for this next release.

#

Thanks for holding down the fort while I've been checked out by the way, it's nice not having to stare at unreplied-to emails.

dense jungle
#

no worries! take care of yourself

neon loom
#

Yeah, personal life first mate. Can we/I help with any of the wheel build flow?

flint cedar
#

why does black turn

SomeClass(
    param=(
        "Lorem ipsum dolor sit amet"
        "I forgot the other parts"
    )
)

into

SomeClass(
    param=(
        "Lorem ipsum dolor sit amet" "I forgot the other parts"
    )
)
dense jungle
#

because we haven't turned --experimental-string-processing on by default yet πŸ˜„

flint cedar
#

so i can just turn that on and it will leave the string alone?

#

it doesn't, it joins the two together into one string

dense jungle
#

yes, if it fits in one line

flint cedar
#

in my case the string is >79 chars long

#

why doesn't it wrap

dense jungle
#

default line length is 88

flint cedar
#

...what

#

okay i guess, i thought it was 80 πŸ˜‚ thanks

crude blade
#

is black first or third party?

errant barn
#

first to us πŸ˜„

neon loom
#

What does that even mean?

bright glacier
#

we're not affiliated with the PSF or CPython project other than the former giving us some administrative help

#

We aren't the official formatter for Python if that's what you were asking

#

There's no such thing

lunar nova
#

anyone using black in neovim here?

#

I have the plugin working, but formatting using = still formats differently

bright glacier
#

Today's new furo release should fix the heading typography issues -- I'mma test it locally and then merge

#

Yeah it's a lot better -- still not perfect IMO, but it's actually readable

flat krakenBOT
dense jungle
#

I've been procrastinating that for a while now πŸ˜„

bright glacier
#

I've been procrastinating on documentation changes for even longer πŸ˜…

flat krakenBOT
#

Describe the bug

The = specifier was added to f-strings in Python 3.8, but Black does not yet distinguish it from any other f-string, and therefore detects the version as 3.6+. This leads to missed formatting opportunities, and sometimes problems in downstream projects since this is invalid syntax under earlier versions. (e.g. https://github.com/Zac-HD/shed/issues/31, prompting this issue)

To Reproduce

from black import detect_target_versions, parsing

code =...
long frigate
#

(I'm sorry, I open the worst issues...)

dense jungle
#

and thanks for reporting this!

dense jungle
bright glacier
#

man, I remember reading this great source on sphinx refs, just gotta find it

bright glacier
#
Yes. _Black_ is strictly about formatting, nothing else. Black strives to ensure that
after formatting the AST is
[checked](the_black_code_style/current_style.md#ast-before-and-after-formatting) with
limited special cases where the code is allowed to differ. If issues are found, an error
is raised and the file is left untouched. Magical comments that influence linters and
other tools, such as `# noqa`, may be moved by _Black_. See below for more details.
#

it works here?

#

I wonder if we could just sidestep the issue by folding usage and configuration into a single document

#

Anyway I'mma see if I can create a reproducer because I have no idea what's wrong here

#

!remind 3H documentation is hard

late dewBOT
#
Aye aye, cap'n!

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

late dewBOT
mint barn
#

!remind 100Y yert

late dewBOT
#
I'll allow it.

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

mint barn
#

My son/daughter will get the reminder hideThePainHarold

#

!remind 0s Hello

late dewBOT
#
Bad argument

0s is not a valid duration string.

mint barn
#

!remind delete 4187

late dewBOT
#

There does not seem to be anything matching your query.

mint barn
#

!remind 1s Oo

late dewBOT
#
Can do!

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

late dewBOT
#
Alright.

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

#

@mint barn

It has arrived!

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

mint barn
errant barn
#

please don't spam this channel (or any channel for that matter)

mint barn
#

oh

bright glacier
#

#bot-commands exists for a reason @mint barn ^^

flat krakenBOT
#

Describe the style change

Black ignores line length limit for dictionaries that have long key / value values, but could be split into 2 lines.

Examples in the current Black style

my_dict = {
    "my very long key that cannot be shortened": "my very long value that unfortunately also cannot be shortened :(",
}

Desired style

my_dict = {
    "my very long key that cannot be shortened":
        "my very long value that unfortunately a...
proper rampart
#

did someone face this issue before?

proper rampart
#

??

flat krakenBOT
#

first pip doesn't work for
mac@MBP-de-mac site-packages % pip --version
zsh: command not found: pip
I did pip3 and it worked for me as you can see
mac@MBP-de-mac site-packages % pip3 --version
pip 22.0.4 from /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip (python 3.10)

when i do pip install black doesn't work for
mac@MBP-de-mac site-packages % pip install black
zsh: command not found: pip
With this one i did pip3 also as you can see
mac@MBP-...

little parrot
#

Do python3.10 -m black .

teal goblet
#

you may need to activate a virtualenv if you have it installed in one.

proper rampart
#

first pip doesn't work for
mac@MBP-de-mac site-packages % pip --version
zsh: command not found: pip
I did pip3 and it worked for me as you can see
mac@MBP-de-mac site-packages % pip3 --version
pip 22.0.4 from /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip (python 3.10)

when i do pip install black doesn't work for
mac@MBP-de-mac site-packages % pip install black
zsh: command not found: pip
With this one i did pip3 also as you can see
mac@MBP-de-mac site-packages % pip3 install black
Requirement already satisfied: black in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (22.1.0)
Requirement already satisfied: mypy-extensions>=0.4.3 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from black) (0.4.3)
Requirement already satisfied: pathspec>=0.9.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from black) (0.9.0)
Requirement already satisfied: click>=8.0.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from black) (8.0.4)
Requirement already satisfied: tomli>=1.1.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from black) (2.0.1)
Requirement already satisfied: platformdirs>=2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from black) (2.5.1)

But I can't work with black i don't know why
mac@MBP-de-mac web3_py_simple_storage % black .
zsh: command not found: black

Please can someone help me

little parrot
proper rampart
#

i did it but the black option doesn't work

little parrot
#

Wdym?

flat krakenBOT
proper rampart
#

as you can see here

#

this is the problem that i face

little parrot
#

Oh idk what you'd need to do to fix it in vsc

proper rampart
#

like how please

#

because i did install black with pip3

flat krakenBOT
#

Describe the style change

Given the following docstring, black shouldn't insert a leading space.

""""Cookie eaters" are the set of people that eat cookies."""

Examples in the current Black style

""" "Cookie eaters" are the set of people that eat cookies."""

Desired style

""""Cookie eaters" are the set of people that eat cookies."""

(Which is how docformatter leaves it)

Additional context

flat krakenBOT
glacial swan
#

question does black have an official in python api?

#

or has that not been added?

bright glacier
#

Nope, it's all unofficial still. We want to define one eventually, but it's been low priority for time being.

glacial swan
#

ah alr

#

I am still doing my formatter function thing

#

Can't wait to do it officailly πŸ™‚

tawdry sorrel
#

HEY

flat krakenBOT
flat krakenBOT
flat krakenBOT
#

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

In https://github.com/pandas-dev/pandas/pull/46279 someone wants to make the pandas codebase adhere to PEP484, so they add None return annotations to some __init__ methods. This is a bummer that this is manual. It would be nice if this could be included in pandas's code checks in CI, so the entire code base was consistent.

Describe the solution you'd like

It would be nice if black added this annotation automat...

main flume
tired shard
#

Ok my exams are almost over, one remaining, will resume work on my PRs from Friday tada

#

And maybe open some more ;)

flat krakenBOT
bright glacier
#

!remind push diff-shades changes..?

late dewBOT
#
Bad argument

push is not a valid duration string.

bright glacier
#

!remind new 2H push diff-shades changes..?

late dewBOT
#
You're the boss!

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

late dewBOT
mint barn
#

@main flume This channel is for discussions about the Black formatter - please try out commands in #bot-commands next time

hexed tangle
#

@hallow bane Do not spam the eval command in random channels. Please see #bot-commands for that

errant barn
#

Please observe the channel topic

hallow bane
#

K

bright glacier
#

!remind 50d can we test CPython 3.11-dev on GHA yet?

late dewBOT
#
Yeah okay.

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

bright glacier
#

that's roughly when the first beta should be available, currently yarl and aiohttp fail to compile due to a header file being deleted / moved upstream

topaz rapids
#

Hi

main flume
#

Hi

#

@topaz rapids chat me private

tired shard
#

@dense jungle psf/black#2525 should be ready for review now, sorry for the delay

toxic stormBOT
tired shard
#

So is psf/black#2770

toxic stormBOT
tired shard
#

(all are ready)

dense jungle
#

ok will take a look in the next few days

flat krakenBOT
#

Describe the style change

Align quotation marks for multi-line string breaks (using --preview) if the resulting strings are a mixture of f-strings and normal strings.

Examples in the current Black style

Before black:

def f():
    stuff, things = 1, 2
    long_string = f'When you create an f-string that contains so much {stuff} it has to be split over multiple lines, some splits might not "contain" interpolation in them. That makes the quote {things} not alig...
bright glacier
#

Currently working on rewriting the diff-shades integration to add a job that forces the stable style and fails on changes.

#

Unfortunately it's a bit of a mess since it will require changes on diff-shades' end ... and the CI is still failing due to that ineffective monkeypatch.

#

Also this adds parallelization AND a pre-configuration job to the workflow so I think I'm going to be the only one capable of maintaining this for the forseeable future...

#

I guess more documentation that details how it works couldn't hurt.

#

I realize we haven't used the workflow dispatch feature of the workflow and it continues to be a thorn when adding features since often it doesn't need the same level of automation as pushes and PRs. It might be worth removing since I can't really think of a situation we'd use it anyway.

#

And even if it was useful, it's 100% feasible to do the same kind of thing locally, it's just more effort which is probably fine for such a rare usecase. It was easy to implement within the original requirements, but it's not worth it anymore.

#

Phew, I wasn't too indecisive this time.

dense jungle
#

good call!

bright glacier
#

the only minor issue is that the PRs we do make that stabilizes any preview formatting changes will be red thanks to diff-shades but that seems fine

#

at most it'll be a yearly occurrence done by a maintainer who should know what's up

tired shard
#

have a label to decide whether we want to run preview diff-shdaes or non preview?

bright glacier
#

the planned design runs both, one to preview changes and one to fail on stable changes

#

and I don't think it's worth keeping a label for these one off events

tired shard
#

yeah, I guessed that, but you said it would be red for preview formatting changes, so we can decide on which of the diff to follow from that? if you get what i mean

bright glacier
#

what?

#

it would be red ONLY if the stable style changes

tired shard
#

oh ok, i read that wrong. my bad

bright glacier
#

the only minor issue is that the PRs we do make that stabilizes any preview formatting changes will be red thanks to diff-shades but that seems fine

bright glacier
tired shard
#

ok, are we running preview formatting or just the stable formatting on black?

#

i see the tests are failing when i include preview formatting changes in the source

dense jungle
#

I changed it recently to format Black itself with preview style

tired shard
#

even the tests?

#

like the test to check if source is formatted

#

ok nope

#

should i include that in 2770 or make a new one, i belive thats something we want as we are formatting with preview style

#

otherwise the tests would be fialing

#

dunno why that doesn't happen now with main branch pithink

bright glacier
#

oh hmm I wonder the test isolation recently added is overriding the preview=True in pyproject.toml

tired shard
#

uhhh which test isolation? could you point to the commit

bright glacier
#

like adding --config=tests/empty.toml everywhere

tired shard
#

ah, yeah that's it

bright glacier
#

Hmm actually I doubt it since the test checks per file and that would skip the configuration file anyway

#

I'm AFK tho so I can't check

tired shard
#

ok, i don't think we are adding empty config for the test_source_is_formated

#

can't see anything in the related code

late dewBOT
#

tests/test_format.py line 154

check_file(str(path), DEFAULT_MODE, data=False)```
tired shard
#

there ^

bright glacier
#

ah default mode, that'd do it

tired shard
#

Right, one more test is failing of test_piping in BlackTestCase

     If the ``.ipynb`` originally had a trailing newline, it'll be preserved.
     """
-    trailing_newline = (src_contents[-1] == "\n")
+    trailing_newline = src_contents[-1] == "\n"
     modified = False
     nb = json.loads(src_contents)
#

none of the tests are adding --preview

#

should i just add them by default to BlackRunner or add them spearately to each?

dense jungle
tired shard
#

even expressions.diff test?

dense jungle
#

why not?

tired shard
#

no, i was just confirming

#

k

#

pushed, should be good now.

tired shard
#

In the feature enum, if want to add anew feature for the detection purpose, what number will i give? And what are these numbers? Can't really understand them from just looking at them

tired shard
#

ok, so i will just choose the next number for F_STRING_EQEQUAL_DEBUGGING feature, couldn't find a better name for f"{x=}"

dense jungle
tired shard
#

ok, that's what i had earlier, found the feature names a bit more explicit, so included the operator name

#

Also, for the detection, I am just using "=" in code_inside_braces_of_string", or there are edge cases to this which i am not aware of?

dense jungle
tired shard
#

oh oi forgot about those, yep i think regex would be a good fit then

dense jungle
#

though there's also stuff like f"{'=:'}"

#

maybe we do actually need to parse it

tired shard
#

but wouldn't the parsing fail if we have a hanging =?

#

we can only parse x= in f"{x=]" since we don't have f-string support yet

#

or we check if the first char isn't ' or "? since if it is not and they are included after a var, then it is invalid syntax

dense jungle
#

not sure what you mean, f"{x+'=:'}" is also valid

lament crow
#

:=

dense jungle
#

you can in fact use walrus inside an f-string ```>>> f"{(x:=3)}"
'3'

x
3

#

(please don't)

tired shard
#

oh wow i didn't know tht

bright glacier
#

!file 18H file some visual output suggestions to rich-click to add more newlines

late dewBOT
#

Thanks to discord.py, sending local files as embed images is simple. You have to create an instance of discord.File class:

# When you know the file exact path, you can pass it.
file = discord.File("/this/is/path/to/my/file.png", filename="file.png")

# When you have the file-like object, then you can pass this instead path.
with open("/this/is/path/to/my/file.png", "rb") as f:
    file = discord.File(f)

When using the file-like object, you have to open it in rb mode. Also, in this case, passing filename to it is not necessary.
Please note that filename can't contain underscores. This is a Discord limitation.

discord.Embed instances have a set_image method which can be used to set an attachment as an image:

embed = discord.Embed()
# Set other fields
embed.set_image(url="attachment://file.png")  # Filename here must be exactly same as attachment filename.

After this, you can send an embed with an attachment to Discord:

await channel.send(file=file, embed=embed)

This example uses discord.TextChannel for sending, but any instance of discord.abc.Messageable can be used for sending.

bright glacier
#

ah fantastic

#

!remind new 18H file some visual output suggestions to rich-click to add more newlines

late dewBOT
#
Yep.

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

bright glacier
#

It's very nice and I want to add it to diff-shades but it's a young project and has a lot of rough edges imo

#

also, yeah the lack of typing support is a hard no (fixed on main apparently tho)

flat krakenBOT
lament crow
#

aww, I looked at this diff, noticed Preview.hex_codes_in_unicode_sequences in self.mode and thought I somehow missed that you can actually enable a single preview feature rather than go all in

errant barn
#

Well not from the command line though

#

it's intended just for converting specific features to stable

late dewBOT
#

src/black/mode.py line 157

def __contains__(self, feature: Preview) -> bool:```
lament crow
#

I think the reason it's done like this is due to experimental string processing flag but anyhow, I know it's not possible from cli that's why I was sad lol

#

"aww" was for sad

errant barn
#

yeah ESP is a special case

tired shard
#

once esp is merged in? would this still remain or preview would be handled as a single config?

errant barn
#

will still remain, although the 2 lines specifically for ESP will be deleted of course

lament crow
#

would be nice if the preview flag was granular, not gonna lie

#

experimental string processing is a bit much for me while it's still experimental but a feature like the one above would be nice to enable sooner

errant barn
#

Sorry, it won't be πŸ˜…

lament crow
#

too many different possibilities of people setting these flags in I guess

errant barn
#

Having feature flags is the last thing we want

#

yep

flat krakenBOT
#

Describe the bug

A comment #fmt:skip with no internal space causes INTERNAL ERROR: Black produced different code on the second pass of the formatter

Also the same code, if run with --fast creates incorrectly formatted code with multiple copies of the comment on the next line.

To Reproduce

For example, take this code:

import re

line = "some dummy data"
log_search = re.search('CLOCK:\s*(\[.*\])--(\[.*\])\s*=>\s*(\d*:\d*)', line)  #fmt:skip

And...

bright glacier
#

I can't reproduce it in a windows terminal -- I bet rich changed something on windows

#

could also be a windows-specific rich bug, it seems it only occurs when a non-interactive terminal is detected

lament crow
#

rich 12.0.0 dropped colorama

#

though it should support legacy windows console on its own now

bright glacier
#

somehow printing is fully broken on the new terminal too, this makes no sense

#

I just love windows, it's totally not the source of many bugs over the years :) /s

#

(notepad++ may or may not be frozen right now thanks to windows update)

calm shuttle
#

e

bright glacier
#

yeaa according to the test output it's straight up not printing anything to stdout in a subprocess :/

lament crow
#

does it only happen in CI or can you repro it locally too

bright glacier
#

locally too if I'm not using a terminal directly

lament crow
#

strange

#

what about when you change command prompt's settings to use legacy console mode

bright glacier
#

I feel like it must be my fault somewhere since this would be a very bad bug but I have no idea where to start debugging lol

#

what even ...

#

i-

#

@lament crow have you seen something like this?

lament crow
#

I suppose that installing rich 12 again breaks it?

bright glacier
#

yup πŸ˜•

lament crow
#

you got my curiosity up so I'm gonna clone diff shades lol

bright glacier
#

you don't need to clone it

#

the reproducer is literally two lines lol

lament crow
#

oh, right

#

nvm

bright glacier
#

This makes no sense though since running a rich application through a subprocess with stdout attached to a pipe should be tested on windows

#

and even if this somehow wasn't tested in their CI, it should've been reported by now!!! but I can't find an issue

lament crow
#

I can't repro

bright glacier
#

fun fun fun

lament crow
#

hmm, try uninstalling colorama

bright glacier
#

still broken

lament crow
bright glacier
#

(don't mind my mindless paste lol)

lament crow
#

tried powershell as well, still works

bright glacier
#
(venv) PS R:\Programming\diff-shades> pip freeze
atomicwrites==1.4.0
attrs==21.4.0
black==22.1.0
click==8.0.4
commonmark==0.9.1
coverage==6.3.2
-e git+https://github.com/ichard26/diff-shades.git@d33bf5ae691f9e702e99a148ba521d207b6e8fb9#egg=diff_shades
iniconfig==1.1.1
mypy-extensions==0.4.3
packaging==21.3
pathspec==0.9.0
platformdirs==2.5.1
pluggy==1.0.0
py==1.11.0
Pygments==2.11.2
pyparsing==3.0.7
pytest==7.1.0
pytest-cov==3.0.0
rich==12.0.0
tomli==2.0.1
typing_extensions==4.1.1
#

I guess isolated virtualenv time?

lament crow
#

oh ugh

#

I didn't realise your subprocess code doesn't use venv

bright glacier
#

hmm?

lament crow
#

it's using my global env

bright glacier
#

I'm in a virtualenv, it's diff-shades' tho

lament crow
#

I don't have 12 there lol

#

I'm in venv too

#

but subprocess.run(["python", ... runs the global python

#

apparently...

#

but how

bright glacier
#

oh hmm

#

although that doesn't explain why rich!=12.0.0 is fine

lament crow
#

okay, now I can repro

bright glacier
#

still strangely broken

lament crow
#

I have no clue why it's using wrong python though,

#

like, shouldn't subprocess use PATH to determine this...

#

well, whatever >.<

bright glacier
lament crow
#

by actually using right python by passing sys.executable

cerulean agate
#

!code

lament crow
#

my global env's rich is not 12

bright glacier
#

ah lol

lament crow
#

I just didn't realise it's using that

bright glacier
#

I don't have rich in my global env AFAIK

lament crow
#

my global env on this system is a mess

#

nowadays I'm using pipx...

plain atlas
#

once, I practically nuked my global env

bright glacier
#

I stop using windows day to day by the time I learned to not install everything in the global env

lament crow
#

I mean, the thing I have in global env work fine :)

plain atlas
#

then apt would not work

lament crow
#

totally have them all installed as admin so that pip can write to C:\Python38\lib\site-packages

plain atlas
#

so I went to another machine running Linux and copied some of the files

#

apt works again

bright glacier
#

I mean on my ubuntu install I gave myself ownership of some files under /opt to make my python installations work lol

lament crow
#

alright

#

so this is not just old cmd issue

#

time to look into this I guess

bright glacier
#

Probably worth a bug report because I'm running out of ideas (or I guess we could ping will here, but that sounds rude :) )

#

unless you have more ideas on how to debug these weird windows issues :p

lament crow
#

it assumes that a non-terminal is legacy console

#

and therefore uses Windows APIs to write to console rather than use stdout

bright glacier
#

hmm it's just stdout broken

lament crow
#

ye, it only has special handling for first stream

#

I assume the Windows APIs work that way

bright glacier
#

I've reached the limit of my rich and windows knowledge so I'm just listening :)

lament crow
#

I mean, you should report it to rich

bright glacier
#

I was just waiting on you whether you'd all of sudden discover why :)

#

I will do so though.

lament crow
#

I'm pretty sure it's because it can't use WriteConsole API (the one that's used for legacy console printing) when it's piped because output from WriteConsole is not capturable

#

but I haven't used those APIs so I can't say that for certain

#

WriteConsole fails if it is used with a standard handle that is redirected to a file

#

well

bright glacier
#

(I have never written C code on windows)

lament crow
#

I guess I could just read documentation then

bright glacier
lament crow
#

I wrote a bit in university but like, not much...

#

well, not much in terms of the amount of different API functions that I used

#

because winapi is pretty extensive πŸ˜„

#

certainly never worked with console apis

bright glacier
#
import subprocess
import sys

code = """\
import sys
from rich.console import Console

console = Console(file=sys.stdout)
console.print("spam")
"""
err_code = code.replace("sys.stdout", "sys.stderr")

cmd = [sys.executable, "-"]

print("[capture_output=True via sys.stdout]")
proc = subprocess.run(cmd, input=code, capture_output=True, encoding="utf-8")
print(f"{proc.stdout=} {proc.stderr=}")

print("[capture_output=True via sys.stderr]")
proc = subprocess.run(cmd, input=err_code, capture_output=True, encoding="utf-8")
print(f"{proc.stdout=} {proc.stderr=}")

print("[capture_output=False via sys.stdout]")
proc = subprocess.run(cmd, input=code, capture_output=False, encoding="utf-8")

reproducer made

lament crow
#

seems fine

#

I would include this excerpt from WriteConsole's documentation:

WriteConsole fails if it is used with a standard handle that is redirected to a file. If an application processes multilingual output that can be redirected, determine whether the output handle is a console handle (one method is to call the GetConsoleMode function and check whether it succeeds). If the handle is a console handle, call WriteConsole. If the handle is not a console handle, the output is redirected and you should call WriteFile to perform the I/O.
https://docs.microsoft.com/en-us/windows/console/writeconsole

bright glacier
#

Anyway I guess I'll just ban rich==12.0.0 on windows. I need to get diff-shades functional in the time I wait for a response.

late dewBOT
thick coyote
#

!e

bright glacier
#

This is probably the wrong channel, no?

thick coyote
#

my bad

#

XD

flat krakenBOT
#

Black exempts single-element tuple literals from the usual handling of magic trailing commas: (1,) will not have a newline added (as would happen for lists, sets, etc.).

I'd like to be able to write type annotations for a tuple-of-one-element in the same way, so that I can write either tuple[int,] or tuple[int, ...] without looking quite so much like list[int]. However, Black's current add-a-newline code style makes this pattern unattractive, so I'm unlikely to write a linter ...

long frigate
# flat kraken

I got annoyed at the way list[int] tempts people to write tuple[int] for their type annotations, and decided to write a linter which forces tuple[int,] if you meant the latter (instead of tuple[int, ...] for variable-length).
Except that Black makes that too ugly to expect much adoption, so...

flat krakenBOT
flat krakenBOT
flat krakenBOT
flat krakenBOT
bright glacier
#

I promise to get diff-shades ready for post-stable use soon! I'm just following up on the rich bug and then I need to test out the integration patch ^^

#

OK so bug.py is working correctly on master but diff-shades' test suite is still failing

#

I guess it's something specific to Console(record=True) now .... ducky_australia

#

@lament crow what the hell

import subprocess
import sys

code = """\
import sys
from rich.console import Console

console = Console(file=sys.stdout, record=True)
console.print("spam")
print(f'recorded: {console.export_text()}')
"""
err_code = code.replace("sys.stdout", "sys.stderr")
cmd = [sys.executable, "-"]

print("[capture_output=True via sys.stdout]")
proc = subprocess.run(cmd, input=code, capture_output=True, encoding="utf-8")
print(f"{proc.stdout=} {proc.stderr=}")

print("[capture_output=True via sys.stderr]")
proc = subprocess.run(cmd, input=err_code, capture_output=True, encoding="utf-8")
print(f"{proc.stdout=} {proc.stderr=}")

print("[capture_output=False via sys.stdout]")
proc = subprocess.run(cmd, input=code, capture_output=False, encoding="utf-8")
#
(venv) PS R:\Programming\diff-shades> python .\bug_record.py
[capture_output=True via sys.stdout]
proc.stdout='spam\n' proc.stderr="Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='cp1252'>\nOSError: [Errno 9] Bad file descriptor\n"
[capture_output=True via sys.stderr]
proc.stdout='recorded: spam\n\n' proc.stderr='spam\n'
[capture_output=False via sys.stdout]
spam
recorded: spam
#

and now export_text is just plain broken

#
(venv) PS R:\Programming\diff-shades> python .\bug_record.py
[capture_output=True via sys.stdout]
proc.stdout='spam\nrecorded: spam\n\n' proc.stderr=''
[capture_output=True via sys.stderr]
proc.stdout='recorded: spam\n\n' proc.stderr='spam\n'
[capture_output=False via sys.stdout]
spam
recorded: spam

running with rich==11.2.0 works as expected

lament crow
#

report that on the issue

bright glacier
#

windows. just wonderful

lament crow
#

the committed solution was a bit too naive

#

I guess

bright glacier
#

minor correction, the recording stuff works but printing is still acting up

#

If I switch to using console.print instead of the built in print with 12.0.0 I get this weirdness

#
(venv) PS R:\Programming\diff-shades> python .\bug_record.py
[capture_output=True via sys.stdout]
proc.stdout='spam\n' proc.stderr='Traceback (most recent call last):\n  File "<stdin>", line 6, in <module>\n  File "R:\\Programming\\diff-shades\\venv\\lib\\site-packages\\rich\\console.py", line 1642, in print\n    self._buffer.extend(new_segments)\n  File "R:\\Programming\\diff-shades\\venv\\lib\\site-packages\\rich\\console.py", line 841, in __exit__\n    self._exit_buffer()\n  File "R:\\Programming\\diff-shades\\venv\\lib\\site-packages\\rich\\console.py", line 799, in _exit_buffer\n    self._check_buffer()\n  File "R:\\Programming\\diff-shades\\venv\\lib\\site-packages\\rich\\console.py", line 1935, in _check_buffer\n    with open(file_no, "w") as output_file:\nOSError: [WinError 6] The handle is invalid\n'
[capture_output=True via sys.stderr]
proc.stdout='' proc.stderr='spam\nrecorded: spam\n\n'
[capture_output=False via sys.stdout]
spam
recorded: spam
#

although that doesn't explain why the test suite is failing, I feel like I'm missing something

#

OK actually stuff is still pretty broken

#

recording, using the built print, and even printing again with console's print are all failing in different ways with STDOUT

#

OK they've been reported.

bright glacier
#

hmm, sqlalchemy is still failing, unfortunately diff-shades doesn't let you just ignore errors for a project or file.

#

the best interim option would be not fail the workflow on file failures

plucky dock
#

Hey, I'm looking for volunteers who could help with the script benchmarks.

Just download this repository and inside from the terminal position type

python3 main.py "test" "test" 130 90

I need this data to make a table comparing password cracking times for a specific processor.

https://github.com/53jk1/distributed-cipher-cracking

bright glacier
#

This is probably the wrong channel, no? Not sure how this is related to the psf/black oss project ^^

bright glacier
#

so close! but I need to rewrite the log file name or else this confusing diff difference will occur >.<

#

It's kinda scary how much time this one task has taken me, but this integration is probably one of more helpful improvements to developer experience so it's worth it πŸ˜„

bright glacier
flat krakenBOT
flat krakenBOT
flat krakenBOT
#

https://github.com/RandyMcMillan/x20bf/runs/5547164070?check_suite_focus=true

error: cannot format /home/runner/work/x20bf/x20bf/x20bf/depends/git/test/performance/test_odb.py: INTERNAL ERROR: Black produced different code on the second pass of the formatter. Please report a bug on https://github.com/psf/black/issues. This diff might be helpful: /tmp/blk__z8nbt2n.log

glacial swan
#
INFO:blib2to3.pgen2.driver:Generating grammar tables from /home/jdjg/JDBot/JDBot/lib/python3.8/site-packages/blib2to3/Grammar.txt
INFO:blib2to3.pgen2.driver:Writing grammar tables to /home/jdjg/.cache/black/21.12b0/Grammar3.8.10.final.0.pickle
INFO:blib2to3.pgen2.driver:Writing failed: [Errno 2] No such file or directory: '/home/jdjg/.cache/black/21.12b0/tmpzys_y126'
INFO:blib2to3.pgen2.driver:Generating grammar tables from /home/jdjg/JDBot/JDBot/lib/python3.8/site-packages/blib2to3/PatternGrammar.txt
INFO:blib2to3.pgen2.driver:Writing grammar tables to /home/jdjg/.cache/black/21.12b0/PatternGrammar3.8.10.final.0.pickle
#

so I installed black into venv

#

I am not sure why this is an issue now

#

didn't have this issue until yesterday

#

Version: 21.12b0

bright glacier
#

You can honestly ignore those, it may say error but black can recover from that one

neon loom
#

Ready to make it an optional install in case someone uses it?

#

Well to point people there?

bright glacier
neon loom
#

I’m cool to just be added as a moderator if you want a second person.

bright glacier
#

I’ll take this and move it to cooperlees/black-primer after the release and if people want it they can install it from there …

#

I didn't misread this, did I?

neon loom
#

Let’s share on the Readme that it’s unsupported and only there for legacy use cases - fork away.

#

Yeah we can do that or im happy if it’s easier to just use yours - I don’t care

#

What ever is easier

bright glacier
#

well my plan was to

  • copy it into its own repo [done]
  • delete black-primer from psf/black
  • profit $
#

I was just trying to save you some effort by making the repo myself and then transferring it to you as you originally planned / stated

neon loom
#

Cheers

#

I just wanted it available in the low chance someone is like what I use primer … etc etc

bright glacier
#

Cool, I had some free time and decided to do part of the work for ya :)

#

glad to hear I didn't misread and wasted an hour lemon_sweat

kind idol
#

hi

#

ΒΏ

nimble bough
nimble bough
bright glacier
bright glacier
# nimble bough can u help?

Seriously, please stop pinging a bunch of random people for help. Or at least provide more context to make the ping worth it.

neon loom
bright glacier
#

I'll resend it

#

oh I see you own it now πŸ˜…

flat krakenBOT
bright glacier
#

I'm actually a bit sad πŸ₯²

dense jungle
# flat kraken

thanks, I was too lazy to find the file myself πŸ™‚

flat krakenBOT
#

Suspect regression. Using v 4.0.1 (Gentoo X86_64). Having just installed black (v22.1.0), reformatting produced multiple W503 messages. Attempted to utilize extended-ignore and reloaded/rescanned project. Warnings persisted. I ensured no W503/W504 ignores were present in code or configuration. Only after adding explicitly W503 to extended-ignore would flake8 be satisfied.

_Originally posted by @scottfurry in https://github.com/psf/black/issues/1661#issuecomment-1048462407_

flat krakenBOT
bright glacier
#

If someone else could walk through this person through the tests and preview that'd be great ^^

topaz rapids
#

Hi

errant barn
flat krakenBOT
#

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

Include all sources of gitignore patterns.
I have user and host specific ignore rules in ~/$USER/.gitignore that Black is unaware of.

>>> cat ~/.gitignore
*.swp
*.swo
.DS_Store
.ropeproject
.mypy_cache
.ccls-cache
.clangd

And just started adding black into my workflow at a project root level instead of an individual call to a specific file.
So the file finding process included python files in the...

tired shard
tired shard
#

yeah :(, mypy can be troubelsome sometimes

dense jungle
#

commented on the PR

tired shard
#

ok, i literally treid everything except that

#

nice

dense jungle
#

you successfully tricked me into reviewing the rest of the PR too πŸ™‚

tired shard
#

ty :D

spare cave
#

just wanted to say we use black in our class and it does make the code much easier to read

#

thank you

flat krakenBOT
#

Currently, the imports exist in any random order as added by the developers (see below), which sometimes makes it difficult to look through them in search of something. Furthermore, it is not very pretty or easy to read.

https://github.com/psf/black/blob/086ae68076de570b0cb1881a3c3b9da592b46ee0/src/black/__init__.py#L52-L59
https://github.com/psf/black/blob/086ae68076de570b0cb1881a3c3b9da592b46ee0/src/black/__init__.py#L6-L11

This is where isort comes in, isort, unlike black is a...

tired shard
#

Felix, finally opened the issue :D

errant barn
#

mint πŸ‘ŒπŸΏ

flat krakenBOT
#

Description

Closes #2914. I've confirmed that C0330 & C0326 checks no longer exist in pylint, therefore we can remove them from the config docs.

Checklist - did you ...

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

hi . intermediate python coder here. i am looking to upskill my coding level, introduce type hinting into my code, use linters etc. i wanted to know what is the difference between black and the linters suggested in my vs code e.g. mypy, pylint, flake, etc.. and what is autopep8... do these all work to conform the code style with PEPs? so what is the difference between them?

dense jungle
#

mypy is a type checker. it looks at type annotations in your code and tells you when you do something like 1 + "x" that breaks the type system

left grotto
#

why are there so many linters? do they all do the same job? and which one is the best?

dense jungle
#

flake8 and pylint are linters, which are kind of in between the two. they find (and sometimes fix) various mistakes or risky bits in your code

left grotto
#

this might seem like a dumb question but why not combine the functionality of autoformatters and linters into one package?

#

black + flake8+pylint all into one?

dense jungle
#

they do very different things internally. you could make a tool that wraps a bunch of them but not sure how useful that would be

#

in particular, autoformatters format code in place and linters and type checkers produce lists of errors, so the output format is very different

flat krakenBOT
vocal fjord
#

what is this bbout???

#

ping if reply

flat krakenBOT
dense jungle
#

(and thanks @tired shard and the PR author for digging up those links πŸ™‚ )

flat krakenBOT
tired shard
#

Btw ichard, would love to see a review on psf/black#2525, seems super close to merge :D

toxic stormBOT
tired shard
#

wow

#

🐒

dense jungle
#

yes GH is having some issues today

tired shard
#

ah yep webhook performance looks degraded

#

new pfp πŸ‘€ is that you?

#

a bit different looking than the previous one

dense jungle
tired shard
#

profile pic

dense jungle
#

oh yes

#

the previous picture was my cats

#

this is me

tired shard
#

nice beard and hat πŸ™ƒ

little parrot
molten kernel
#

how do i configure black in Pipfile, like i can in pyproject.toml

#

i tried [black] and [tool.black]

dense jungle
molten kernel
#

:( why not

dense jungle
#

pyproject.toml is the standard configuration file. we're not interested in adding more config files

molten kernel
#

pipenv is recommended by pypa

#

it may not be standard but really all that has to be done is a check for the Pipfile in the same directory, and look for tool.black in the same way

bright glacier
#

Oh man, it's weird not seeing a cute cat where ever on the internet you're present Jelle.

#

I'm sure I'll get used to this one too, just needs time :)

tired shard
#

you still have the cute cat on their github

#

well atleast till now

bright glacier
dense jungle
#

yes. we have to figure out what to do if both config files are present

#

and whatever we do will probably confuse someone

bright glacier
#

adding Pipfile support might not be that expensive from a maintenance perspective, but there's this good analogy Brett Cannon said: you're presenting us a kitten (it's low cost on its own) but when they grow up it's not so low maintenance / and arguably cute

#

and we have to draw the line somewhere and we prefer to draw the line defensively erring on the side of keeping maintenance sustainable

#

software almost always marches towards gaining limitless complexity from "just one more feature" and we'd like to slow that down at least :)

molten kernel
#

@dense jungle @bright glacier what about PR #2527 ?

#

doesn't that help?

tired shard
#

Since this hasn't been a common request and it would complicate our internals, I'm now inclined to reject this enhancement request. We can revisit that decision if we get more use cases.

errant barn
flat krakenBOT
#

Describe the bug
Black raises INTERNAL ERROR when # fmt: skip has been added at the end of a def function statement

To Reproduce
For example, take this code:

def example(arg1: str, arg2: float):  # fmt: skip
    pass

And run it with these arguments:

$ black file.py

The resulting error is:

cannot format file.py: INTERNAL ERROR: Black produced different code on the second pass of the formatter

"""
--- source
+++ first pass
@@ -1,2 +1,...

molten kernel
#

pithink at the time of that PR black even used Pipenv lol

errant barn
#

Yeah, we've since stopped using it πŸ˜…

tired shard
#

lot has changed since that PR

tired shard
#

will comment when i do

errant barn
#

None of the labelled issues? There are some unstables, but no obvious duplicates, at least at a quick glance

tired shard
#

i remember seeing an issue talking about fmt:off/skip on function definition lines

#

maybe wrong

errant barn
#

would be good to find though!

tired shard
#

ok nah can't find

#

atleast the labeled issues

#

ok found it

#

yeah it isn't labelled

errant barn
#

oh, nice detective work

tired shard
#

lol ty

errant barn
#

uhhhmm, GH having issues?

#

yeah they are :D

bright glacier
#

oh how great

tired shard
#

And for adding isort to our dev dependencies, should I just rename test_requirements to dev_requirements or I have to add it somewhere else?

#

(or usort)

errant barn
#

they are our dev requirements essentially

#

so renaming? why not, but anyways that's where I think they go

bright glacier
#

euh, I disagree with renaming it

#

We don't specify which mypy version we use other than in .pre-commit-config.yaml

tired shard
#

i don't see any better place than πŸ€·β€β™‚οΈ

bright glacier
#

same with flake8

tired shard
#

hmmm

#

i willl just do that then

#

to be consistent with others

#

And if you could put your thoughts on usort/isort, so we can choose one

bright glacier
#

it could be worth it but I'd keep it in a separate file (maybe a larger dev-dependences.txt file) to avoid slowing down the test session setup

tired shard
#

i never had the need of it, so its fine IMO

errant barn
#

that could be nice, since the wider file can include from the test deps, so the dev setup wouldn't be any less convenient

bright glacier
neon loom
#

Imitation is the best for of flattery

flat krakenBOT
#

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

The except clause can accept a parenthesised tuple of exceptions. However, in the case of only a single exception the brackets should be removed.

Black currently leaves both of these examples unchanged:

a = 1
try:
    a.something
except (AttributeError) as err:
    raise err

and

a = 1
try:
    a.something
except (AttributeError,) as err:
    raise err

Describe the solution you'd like...

flat krakenBOT
flat krakenBOT
flat krakenBOT
tired shard
#

not sure how i fix them, haven't messed up with isort yet

#

the config looks correct though

#

atleast if the docs aren't hiding anything

bright glacier
#

you should be using known_first_party not known_third_party for black and friends

#

third_party is for dependencies and first_party is for in tree code

tired shard
#

oh shit yes, i didn't see that. ty πŸ‘

bright glacier
#

also "adds an autoformatter to an autoformatter project" -> proceeds to use inconsistent formatting in the configuration πŸ₯΄ lol

#

plz add spaces around the equal signs, kthxbye

tired shard
#

lol will fix

flat krakenBOT
#

Description

Closes #2930

The formatting changes are part of commit 37356f6940773f0903486da9629b68bd78d47209 and edf37bf708006f12fc7d3cab43c21f19548b3035, the rest are config/chore changes.

Checklist - did you ...

  • [ ] Add a CHANGELOG entry if necessary?
  • [X] Add / update tests if necessary? -> n/a
  • [X] Add new / update outdated documentation? -> n/a
tired shard
#

does it need a changelog?

#

its an internal change

bright glacier
#

no.

tired shard
#

ok πŸ‘

bright glacier
#

Isort: Fix typo third_part -> first_party
the typos are taking no prisoners

#

I'm surprised at the diff size

tired shard
#

the only thing i am not 100% liking

#

i would have liked that to be broken down into 2-3 imports

#

also i still yet to try usort, it seems more promising

bright glacier
#

In general I prefer a single long from import over multiple imports but yeah it could be argued it's a bit much here

tired shard
#

yeah even i do, but this a bit too big

#

i think there is a config option for that

#

will see

#

another one

bright glacier
#

It might be attaching semantic meaning to the comment

#

Isort has some interesting logic keeping sections relatively intact these days

tired shard
#

yeah it does

#

i will give usort a try once

#

and then we could decide

#

but according to the features, i am more on usort

#

that pretty much sums it

#

Β΅sort operates on a strictly-parsed syntax tree of each file as a whole, rather than reading and parsing individual lines of text at a time. This guarantees that Β΅sort is modifying the actual Python syntax elements, along with any associated comments, and generating grammatically correct results after sorting.

#

one down side tho

#

Β΅sort uses case-insensitive, lexicographical sorting for both module names and imported items within each statement. This means uppercase or titlecase names are mixed with lowercase names, but this also provides a more consistent ordering of names, and ensures that frog, Frog, and FROG will always sort next to each other:

#

and there is no config oprtion for that

bright glacier
#

yeah I'd prefer constants in their own little group -> i.e. taking into account casing

tired shard
#

yeah

tired shard
flat krakenBOT
bright glacier
#

It might be better to separate the normal vs preview test data files instead of repurposing the stable ones as preview

dense jungle
#

yes, we haven't really thought about how testing works with stable vs. preview

flat krakenBOT
#

Describe the style change

I think that redundant parentheses should be removed from generators or at least be allowed to stick to next/previous parenthesis. Consider the following source example:

any((
    this_very_long_method_name(obj) or another_long_method_name(obj)
    for obj in this_iterable
))

Examples in the current Black style

Now black (22.1.0) formats it to

any(
    (
        this_very_long_method_name(obj) or another_long_met...
dark kiln
#

Damn, this is some advanced sh*t.

mint barn
#

I wonder for already a really long time

#

It even does not have a profile

#

Mysterious @github#0000

#

Oh, a webhook

#

Than i got it

neon loom
tired shard
#

Any updates on psf/black#2863

dense jungle
teal goblet
#

workaround: black --config ../../pyproject.toml

neon loom
#

This could be a breaking change to people who already exercise this behavior tho in practice

flat krakenBOT
shrewd zinc
#

Is black supposed to fail if it encounters stuff like

f"some text {'\n'.join((f' β€’ {i}' for i in list_of_strings))}"

?

errant barn
#

Does that work in Python 3.10? It fails on 3.9

#

With the same error that Black gives: "f-string expression part cannot include a backslash"

shrewd zinc
#

How do I see black errors in vscode?

#

At least the editor doesn't complain about anything

errant barn
#

I meant that can you run that code at all

#

Presumably you are using 3.10 or 11

shrewd zinc
#

no, 3.8

bright glacier
#

yeah that's illegal syntax pithink

errant barn
#

Yep, not a Black problem then I'm afraid

bright glacier
#

technically you could work around the issue by passing --fast but if the code isn't even valid Python, I don't see the point

shrewd zinc
#

huh

#

I thought it was fine since the editor doesn't show any warning/error

errant barn
#

Can't always trust editors :D

bright glacier
#

!e print(f"{'\n'.join([1, 2])}")

shrewd zinc
#

What specifically is the issue?

late dewBOT
#

@bright glacier :x: Your eval job has completed with return code 1.

001 |   File "<string>", line 1
002 |     print(f"{'\n'.join([1, 2])}")
003 |                                 ^
004 | SyntaxError: f-string expression part cannot include a backslash
errant barn
#

The backslash

shrewd zinc
#

OH

#

I totally missed that backslash lol

#

!e print(f"{'-'.join(['1', '2'])}")

late dewBOT
#

@shrewd zinc :white_check_mark: Your eval job has completed with return code 0.

1-2
red sedge
#

Integrating the f-string parsing with the peg parser makes it possible to parse it

shrewd zinc
#

peg parser?

shrewd zinc
#

Oh, nice

#

nested quotes would also help sometimes

flat krakenBOT
lament crow
flat krakenBOT
#

Describe the style change
I've just encountered an odd situation where black places a list index on a completely separately line.

Examples in the current Black style
Under default parameters, the following code snippet

def f(special_chars):
    return (len([c for c in special_chars[1:] if c.isupper()]) > 0) and special_chars[0].islower()

is converted by black 22.1.0 to:

def f(special_chars):
    return (len([c for c in special_chars[1:] if c...
flat krakenBOT
bright glacier
#

Do I just manually merge the PR or something..?

errant barn
#

at least GHA was a bit slow earlier

flat krakenBOT
bright glacier
# flat kraken

guess who forgot to change the commit author before committing this manually ducky_australia

late dewBOT
#
You got it!

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

bright glacier
#

!remind edit duration 4276 1m

late dewBOT
#
Alright.

That reminder has been edited successfully!

dense jungle
bright glacier
#

I'm not that slow I swear πŸ˜…

bright glacier
#

gosh, why is this diff-shades integration so complex haha

#

anyway I think I should be able to update the PR in 30ish minutes assuming testing passes

neon loom
#

What makes it so complex? Anything I could help on to try not make it so, sorry I've been at a distance with it all

bright glacier
#

The additional features we need πŸ˜… -- originally the integration would only show the impact of black using the projects' own configuration (or the defaults) but now we want to move away from that and instead force the preview / stable style

neon loom
#

ahhh right

#

How you going to ensure preview does what it should? Just toggle if we expect changes or not?

bright glacier
#

had a real fun time trying to fix the latest bugbear error code too btw lol

neon loom
#

Which one? πŸ˜„

#

Glad it found a bug

bright glacier
#

B019, the diff-shades code is a bit hairy so I ended removing the caching altogether

neon loom
#

I just released another one today with more fixes for some false positives on new checks

#

ambv talked me out of removing 3.6 support - Will do it when flake8 itself does it

bright glacier
# neon loom How you going to ensure preview does what it should? Just toggle if we expect ch...

Not sure what you mean, but now the integration has two jobs (well one more for run configuration, but we can ignore that) for PRs:

  • preview-changes: basically what we had originally but now all projects use the preview style (it's more useful this way)
  • assert-no-changes: this is new and will fail on any differences between the baseline and target revisions (it forces the stable style for all projects)
#

For pushes to main, only preview-changes runs.

neon loom
#

Yup cool. Sounds great and answers what I was trying to ask.

bright glacier
#

The more I hack on this the more I think it'd make for a great blog post.. something something about real world testing with downstream :)

#

but I got other things to write about first (and other tasks to finish first before that)

#

hopefully it stays that way and doesn't fail in a way I don't expect

neon loom
#

So I can learn it

#

And @bright glacier - What power do you have now being on events team? Congrats

#

I was like, I like to party, I want a party hat

bright glacier
#

No more power actually, I just now get pings for all of the events python discord are planning and running lemon_ping

neon loom
#

O, I don't want that

#

haha

bright glacier
#

I've been python discord staff for quite a while now

bright glacier
#

Run diff-shades compare --check assert-no-changes-main-450253afaf.json assert-no-changes-pr-15-8b2f244f34.json || echo "Please verify you didn't change the stable code style unintentionally!"
guess who messed up their bash conditional logic :p

#

I forgot to add the exit 1 at the end

neon loom
#

bash is evil

dense jungle
#

set -x maybe?

#

or whatever the thing is that makes it exit if any command fails

neon loom
#

I converted a script at work today to simple python cause I find it easy. from subprocess import run and have at it

bright glacier
#

it is configured but that bash command runs the second command if the former fails and I forgot that basically ignores the return code from GHA's perspective

late dewBOT
#

.github/workflows/changelog.yml lines 18 to 21

run: |
  grep -Pz "\((\n\s*)?#${{ github.event.pull_request.number }}(\n\s*)?\)" CHANGES.md || \
  (echo "Please add '(#${{ github.event.pull_request.number }})' change line to CHANGES.md (or if appropriate, ask a maintainer to add the 'skip news' label)" && \
  exit 1)```
bright glacier
#

see that && exit 1 ? that's what I need

#

Seems off topic for this channel, no? this is for the psf/black autoformatter project

lethal cairn
#

oh, sorry I tought it was for open sorce projects, Im new here

bright glacier
#

this channel is indeed part of the open source project category but each channel is dedicated to a specific one python discord admins has vetted

lethal cairn
#

ooh, I see, thanks man!

bright glacier
#

There's no channel for sharing your project, but the off topic channels usually work well enough assuming you'll doing it in good faith and are following the rest of the rules here.

#

!off-topic

late dewBOT
lethal cairn
#

thanks man!

bright glacier
#

I can do that though, I think I have a wishlist somewhere in notion πŸ€”

neon loom
#

Who likes to code. My code is horrible too.

bright glacier
#

Coding is fun, although I've been doing way more webdev than Python stuff lately

neon loom
#

@bright glacier I'm submitting a talk to a conference in your poutine town