#black-formatter

1 messages ยท Page 26 of 1

dense jungle
#

it would be great to get diff-shades set up in CI, similar to how mypy-primer works on typeshed

plain atlas
#

did someone say ci??

#

ah gotcha

bright glacier
#

I'm not even done the feature that powers those reports -- I just whipped up something quick and dirty in my site-packages install of diff-shades ๐Ÿ‘€

#

Yeah my development practices might not be the best when it comes to personal projects :p

plain atlas
#

i- i see

bright glacier
#

How helpful are the reports I'm attaching by the way @dense jungle ? Is there something you'd like as a fellow maintainer? If I can get the data backend performant enough I plan on adding line count, line additions, line deletions, and files changed statistics.

#

Anything from mypy-primer you'd like is also welcome ๐Ÿ˜„

dense jungle
#

it's unfortunate that the conditional expressions report included the changes from the blank lines PR, I guess that's addressable with a better baseline

bright glacier
#

Yeah that's just me being lazy as each run take 20 minutes to do. I first compile black with mypyc (this ends up being a time saver in the long run!) and then run diff-shades taking 15 minutes.

plain atlas
#

so obviously a workflow would be great

bright glacier
#

Yea but I'm a busy human

plain atlas
#

because also it would only take 2 minutes because 16 cores

#

well gimme

bright glacier
#

16 cores?

plain atlas
#

the runners have at least that many

dense jungle
#

except for the ones used for the rest of CI

plain atlas
#

wdym?

bright glacier
#

the extra projects are just my own :p

#

Linux and Windows VMs have 2 cores while the Mac ones have 3.

plain atlas
#

wut, i've seen one with more cores

#

uh

tired shard
bright glacier
#

is this black from main?

dense jungle
# tired shard uhh

you likely have a different syntax error elsewhere. because of that, black tries the 2.7 grammar which explodes on the print keyword

tired shard
plain atlas
bright glacier
#

jelle's guess seems likely then

plain atlas
#

flake8 will tell you where your syntax error actually is

tired shard
dense jungle
#

or try --target-version py310 or something

tired shard
#

that works

bright glacier
#

Oh do you have pattern matching / parenthesized with?

tired shard
#

yep

bright glacier
#

Yeah that's locked under --target-version py310 at the moment.

tired shard
#

but doesn't it have 3.10 support

#

ah

bright glacier
#

Read the changelog :p

flat krakenBOT
raw comet
#

black can do 3.10 now?

flat krakenBOT
#

Describe the bug
In python3.10 the case black can be written in the same line as the case keyword. However, this breaks black.

To Reproduce
Take this example code

# example.py
x = 5
match x:
    case 5: print("it works")

It runs under python3.10:

python example.py
it works

However, black crashes:

black --target-version py310 example.py
error: cannot format example.py: INTERNAL ERROR: Black produced invalid code on pass 1: exp...
dense jungle
raw comet
#

yayyy

#

time to format my project

bright glacier
#

actually I do have an analysis from the blank line PR that I could use as the baseline for PR #2278's report - I just totally forgot about it ๐Ÿ˜ฆ

dense jungle
#

let's make a new release soon

plain atlas
#

yay 21.12b1

dense jungle
#

I'd like to implement somebody's suggestion that we print a warning suggesting to use -t py310 if we detect match syntax

red sedge
#

"it looks like you're playing with matches, would you like some help" ๐Ÿ”ฅ๐Ÿ“Ž

bright glacier
#

This feels much better already @plain atlas :p

plain atlas
#

waitwhatdidisuggest?

#

if anything

bright glacier
#

honestly nothing, I'm just playing with nox instead of tox

plain atlas
#

ohhhhh

#

my pc is lagging rn so if i'm slow to respond its because my pc is

#

tldr a windows service has a memory leak

#

okay killed

plain atlas
#

I'm a bit excited to try it, however

#

given that its fairly nice, and allows the user to test on multiple environments locally

drowsy sonnet
#

Okay, so... I can't figure out if I'm seeing something that is new -- because I can't find a corresponding issue for this.

Black formats this file as:

"""This is a subpackage because the directory is on sys.path for _in_process.py.

The subpackage should stay as empty as possible to avoid shadowing modules that
the backend might import.
"""
from contextlib import contextmanager
from os.path import abspath, dirname
from os.path import join as pjoin

try:
    import importlib.resources as resources

    def _in_proc_script_path():
        return resources.path(__package__, "_in_process.py")


except ImportError:

    @contextmanager
    def _in_proc_script_path():
        yield pjoin(dirname(abspath(__file__)), "_in_process.py")

All this additional whitespace seems excessive, to the point of hurting readability.

errant barn
#

For me there's only one space before except on the playground. Would you suggest that the space before contextmanager is removed?

errant barn
#

That'd be the main!

#

Probably Richard's recently accepted PR psf/black#2472

toxic stormBOT
drowsy sonnet
#

Yea.

errant barn
#

But what do you think of the spacing otherwise?

drowsy sonnet
#

I think what main does is reasonable!

errant barn
#

Agreed, although I probably would get rid of the space before the function.

#

But that seems to be discussed in psf/black#450

flat krakenBOT
jolly oriole
#

Maybe it's counting that as an operation ยฏ\_(ใƒ„)_/ยฏ

plain atlas
#

@muted haven i was just thinking that you would submit a fix, lol

muted haven
plain atlas
#

I left a review ^^

#

neither comment of which actually applied to the code change itself ๐Ÿ˜‚

muted haven
#

I just add patma related changes end-to-end I guess, not sure if there is an order to follow ๐Ÿ™‚

plain atlas
#

yep Richard got you covered

#

tldr no one cares lemon_sweat

#

which makes sense, by putting it anywhere in that block, it can slightly reduce merge conflicts

dense jungle
#

I might reorganize the changelog a bit before the release

plain atlas
#

aw man

#

it got merged before my review! ๐Ÿ˜‚

bright glacier
#

@plain atlas what do you think of using this?

late dewBOT
#

.github/workflows/ci.yml lines 14 to 16

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
  cancel-in-progress: true```
late dewBOT
#

.github/workflows/lint_test.yml lines 15 to 17

concurrency:
  group: ${{ github.workflow }}-${{ github.repository }}-${{ github.ref }}
  cancel-in-progress: true```
bright glacier
#

basically the idea is that if we rapidly update a PR, the older CI runs would be autocancelled

plain atlas
#

!remind 10M double check this

late dewBOT
#
ROGER THAT

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

late dewBOT
plain atlas
# bright glacier basically the idea is that if we rapidly update a PR, the older CI runs would be...

Thinking about it, it should work, although I would consider using github.ref instead of sha. The sha means it will always run on every commit, and continue to run, unless there is a pull request.

However, that may be desired behavior, as using a mix would mean that it would cancel checks if two consecutive pulls were merged to main.

I suppose my point above is be careful which workflows you put it on ๐Ÿ˜›

Additionally, I would consider github.sha vs github.ref, I have made a context dump here: https://github.com/onerandomusername/context/actions/runs/1536895896

bright glacier
#

Thank you I'll look at it later as I'm helping out in the help channels ATM

plain atlas
#

๐Ÿ‘

#

...wait how did the reminder command work here?

bright glacier
#

I honestly have no idea

plain atlas
#

!src remind

late dewBOT
#
Command: remind

Commands for managing your reminders.

Source Code
late dewBOT
#

config-default.yml lines 261 to 264

reminder_whitelist:
    - *BOT_CMD
    - *DEV_CONTRIB
    - *BLACK_FORMATTER```
bright glacier
#

how do we want to detect when the line the parser fails on is probably a match statement? .startswith("match") but that's a bit imprecise :)

dense jungle
bright glacier
#

oh that works too

#

I'll leave the PR for you to do then as I rather not implement that change - not for technical reasons, I just don't feel like it.

dense jungle
#

sure, writing the code now

bright glacier
#

You're so fast compared to me it surprises me every time ๐Ÿ˜„

dense jungle
#

just procrastinating from doing real work

bright glacier
#

I finished most of my work today, I just have some notes to fill out and I should be good to go for today.

dense jungle
#

what about this ```(black) jelle@mbpt-root black % black t.py
error: cannot format t.py: Cannot parse: 2:10: match something:. Consider using --target-version py310 to parse Python 3.10 code.
Oh no! ๐Ÿ’ฅ ๐Ÿ’” ๐Ÿ’ฅ
1 file failed to reformat.

bright glacier
#

that period after match ... looks weird but I don't know whether that's pre-existing or not. I'm not sure whether the backticks are necessary - but they do look weird imo as we don't use backticks as part of our UI language so far.

#

These are just nitpicks, the overall idea seems fine to me.

dense jungle
#

thanks, I'll take out the backticks

#

I put the period in, feel like we need something to separate the code from the message. Maybe I should put in a newline instead

bright glacier
#

Oh yeah a newline would work better IMO. I thought you had used a newline but it turns out my viewport is just the right size to make it seem like that :p

dense jungle
#

also apparently we support parenthesized with before 3.10 too? ```(black) jelle@mbpt-root black % black -t py38 -c 'with (x as y, y as z): pass'
with (x as y, y as z):
pass

bright glacier
#

Yup, we only use a single grammar and the support for parenthesized with was implemented in the grammar itself. On the other hand pattern matching requires adding some names to the grammar object at runtime (on top of the grammar changes) so the parser knows whether to treat match / case a soft keyword

dense jungle
#

oh interesting, I thought parenthesized with also required backtracking/PEG

plain atlas
#

I'm more present now, daylily richard

#

hi

bright glacier
#
PY310_HINT: Final[
    str
] = "Consider using --target-version py310 to parse Python 3.10 code."

I guess this is what the 25+ issues about splitting on the RHS vs LHS is all about because damn this is not pretty.

dense jungle
#

agree

plain atlas
#

ditto agreeee

bright glacier
#

Pretty happy with this, now time to implement the rest of the show and compare command ๐Ÿ˜„

plain atlas
#

yeah from what you showed me it looks great

muted haven
#

I recall there was a benchmark suite for black @bright glacier, would it be possible to run it with -tpy310 to get some profiling data?

#

I plan to do some improvements over performance today, but it would be nice to learn how slow it is already ๐Ÿ˜…

flat krakenBOT
flat krakenBOT
#

@tanvimoharir hey sorry for such the long wait. The tests you added were good but the second one wasn't necessary as we already have tests that cover that area. I made the first (still relevant) test a bit more of an unit test so changes to --code don't affect it down the line.

Finally I tweaked the error message opting to reuse the message already stored in the TokenError, and fixed the merge conflict. Thank you so much and my apologies once again!

bright glacier
#

What's the status on the TOML bare CR situation btw?

bright glacier
#

!remind 1D look into doing more outreach in regards to testing the mypyc wheels

late dewBOT
#
Sure thing!

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

plain atlas
#

the issue on pypa/pipis still open

bright glacier
plain atlas
#

you've probably already checked them, since it's been 2 hours

bright glacier
#

It's still open unless you mean a different one.

plain atlas
#

I thought it was closed

#

smh

#

I read the last message and told myself "resolved"

red sedge
#

I think you just pass bytes to tomli and let it decide

bright glacier
#

Yeah I suppose

bright glacier
#

I feel like it won't be worth it especially there are files passed to black IRL that are massive

dense jungle
#

I guess it's a nice additional safety but not sure it's really worth it

bright glacier
#

I vote nay then as I don't want to deal with multithreading with mypyc or 3.6. It's on the error path anyway so I doubt it'll be a problem IRL.

flat krakenBOT
#

I believe it would be useful to split up the long list of changes a bit more.

Specific changes:

  • Removed the entry for new flake8 plugins; this is purely internal and not of interest to users
  • Put regex in the packaging section
  • New section for Jupyter Notebook
  • New section for Python 3.10, mostly match/case stuff

Happy to change this though if others have a different opinion.

plain atlas
#

for the longest time i thought lgtm meant 'looks good to merge'

#

and then i learned it meant 'looks good to me'

lament crow
#

you got 3 words out of 4, not bad :P

plain atlas
#

true

lament crow
#

I heard 'let's get this merged' abbreviation in the past too

plain atlas
#

makes sense

flat krakenBOT
lament crow
#

:)

flat krakenBOT
dense jungle
#

@bright glacier we could do another release now, or maybe wait for Batuhan's possible perf improvements?

#

then again, that could just go into the next one

bright glacier
#

OH yeah

#

I guess it doesn't hurt to wait a little bit.

#

This release candidate is quite packed with changes and it's only been 17 days lemon_sweat

sour jay
plain atlas
lament crow
bright glacier
# muted haven I recall there was a benchmark suite for black <@429445826251587616>, would it b...

It turns out 1) blackbench sucks - I had to hack the source code to support this usecase, and 2) the included benchmarks don't really have any usage of match surprisingly enough.

โฏ pyperf compare_to main-9424e795b-normal.bench.json main-9424e795b-py310.bench.json -G
Slower (1):
- parse-black/strings: 74.8 ms +- 7.3 ms -> 231 ms +- 32 ms: 3.08x slower

Benchmark hidden because not significant (16): parse-black/__init__, parse-black/brackets, parse-black/comments, parse-black/linegen, parse-black/lines, parse-black/mode, parse-black/nodes, parse-black/output, parse-comments, parse-dict-literal, parse-flit/install, parse-flit/sdist, parse-flit_core/config, parse-list-literal, parse-nested, parse-strings-list

Geometric mean: 1.07x slower
dense jungle
#

is there a benchmark that calls re.match a lot?

#

also thanks for running this!

bright glacier
#

No, I meant literally any reference to match the word not the statement.

#

I grepped through all of the test files and only black/strings has any ...

#
โฏ blackbench dump black/strings | grep "match" --line-number
17:    overlapping matches.
40:        match = re.match(r"\s*\t+\s*(\S)", line)
41:        if match:
42:            first_non_whitespace_idx = match.start(1)
136:    match = re.match(r"^([" + STRING_PREFIX_CHARS + r"]*)(.*)$", s, re.DOTALL)
137:    assert match is not None, f"failed to match string {s!r}"
138:    orig_prefix = match.group(1)
142:    return f"{new_prefix}{match.group(2)}"
191:        matches = re.findall(
200:        for m in matches:
#

But yeah it does seem to slow down parsing a fair bit if match is used as an identifier

dense jungle
#

oh yeah ```...$ rm -rf ~/.cache/black/ && time black graphql_/schema/search/_definitions.py
All done! โœจ ๐Ÿฐ โœจ
1 file left unchanged.

real 0m0.474s
user 0m0.440s
sys 0m0.028s
...$ rm -rf ~/.cache/black/ && time black -t py310 graphql_/schema/search/_definitions.py
All done! โœจ ๐Ÿฐ โœจ
1 file left unchanged.

real 0m2.744s
user 0m2.692s
sys 0m0.048s

#

this file uses the variable name "match" like 60 times

bright glacier
#

I just hacked up a super simple micro benchmark and yeah it's not great

Mean +- std dev: 
  [main-9424e795b-normal.bench-mini] 20.6 ms +- 1.5 ms
  [main-9424e795b-py310.bench-mini] 194 ms +- 25 ms
9.41x slower
flat krakenBOT
#

This isn't much, but at least a good start (we did 3 overall copies, but seem like the initial one is unnecessary since we never touch that stack, so we do 2 of them now).

main:

$ touch t.py; time black -tpy310 --check t.py > /dev/null
would reformat t.py
Oh no! ๐Ÿ’ฅ ๐Ÿ’” ๐Ÿ’ฅ
1 file would be reformatted.
black -tpy310 --check t.py > /dev/null  0,33s user 0,02s system 99% cpu 0,358 total

this branch:

$ touch t.py; time black -tpy310 --check t.py > /dev/null
would reformat t.p...
bright glacier
#

whyy is the unexpected EOF test crashing ....

muted haven
#

I have no idea ๐Ÿค” will check again

bright glacier
#

oh, CI is failing on main too :(

bright glacier
#

now why did CI not catch on jelle's PR? well to avoid (practically) duplicated workflows, one for the push and one for the pr event, we cancel workflows on psf/black for PR event

#

this means CI doesn't test the revision when the PR would be merged into main

flat krakenBOT
bright glacier
# flat kraken

@muted haven this should fix the failing test, sorry for the noise!

flat krakenBOT
bright glacier
muted haven
#

I did not include one since I though this wouldn't be the only speed-up we are trying to get but I am not sure at this point

#

if I can make more that targets this release

bright glacier
#

It depends how confident you are as we want to release soon :)

plain atlas
muted haven
#

I've looked into more holistic solutions (e.g determining token type on the tokenizer), but it seem very very hard to do so (primarily because of stuff like match ({a: b}) can be either a call to a function named match() or a real match statement). So it would probably require someone (possibly me, but who knows maybe someone else wants to do it) to take a look at my initial implementation for parso, which avoids stack copies at all (It pseduo-emulates the parser stack and DFA pushes).

#

I don't think I will have time during the week, so I'll try to give it a shot at the next weekend. No promises / expectations though ๐Ÿ‘€

muted haven
#

I tried to run the given file with black on an isolated environment, and I've only observed a degredation of 1.6X;

root@bac268808ff0:/# hyperfine 'touch t.py;black --check t.py'
Benchmark 1: touch t.py;black --check t.py
  Time (mean ยฑ ฯƒ):     158.5 ms ยฑ   2.5 ms    [User: 146.0 ms, System: 12.4 ms]
  Range (min โ€ฆ max):   155.7 ms โ€ฆ 165.6 ms    18 runs
 
root@bac268808ff0:/# hyperfine 'touch t.py;black -tpy310 --check t.py'
Benchmark 1: touch t.py;black -tpy310 --check t.py
  Time (mean ยฑ ฯƒ):     243.3 ms ยฑ   4.8 ms    [User: 222.7 ms, System: 20.2 ms]
  Range (min โ€ฆ max):   239.2 ms โ€ฆ 254.9 ms    12 runs
 
root@bac268808ff0:/# black --version
black, 21.11b2.dev26+gd9eee31 (compiled: no)
bright glacier
#

Yeah I suspect it's probably due to black's startup time that the slowdown is less noticable

muted haven
#

Possibly. So I assume you only benchmarked parse()?

flat krakenBOT
#

Describe the style change

When passing dict as a function parameter I often prefer than the dict is split in multiple lines while keeping other parameters in the same line.

Original code:

db.insert('table', {'a': 10, 'b': 11})

Examples in the current Black style

Adding a trailing comma in the dict results in all parameters split, consuming 7 lines, which feel too excessive in the vertical space usage.

db.insert(
    'table',
    {
    ...
bright glacier
#
import tempfile
from pathlib import Path

import pyperf

import black
from blib2to3 import pygram

# First try the relevant function post-refactor in 21.5b1, and fallback
# to old function location.
try:
    from black.parsing import lib2to3_parse
except ImportError:
    from black import lib2to3_parse

runner = pyperf.Runner()
code =  Path(r"{target}").read_text(encoding="utf8")

with tempfile.TemporaryDirectory(prefix="blackbench-parsing-") as path:
    # Block the parser code from using any pre-existing cache.
    pygram.initialize(path)
    runner.bench_func("{name}", lib2to3_parse, code, set((black.TargetVersion.PY310,)))

it's effectively this script

muted haven
#

good to know, thanks! (will definitely use this for the future PRs)

bright glacier
#

note that this script is a bit more complex because it has to handle old versions of black where the APIs changed

#
parse-black/strings
===================

Mean +- std dev: [uhh-default] 67.0 ms +- 2.0 ms -> [uhh-initial] 227 ms +- 27 ms: 3.39x slower
Mean +- std dev: [uhh-default] 67.0 ms +- 2.0 ms -> [uhh-speedup] 154 ms +- 3 ms: 2.30x slower

parse-match-identifiers
=======================

Mean +- std dev: [uhh-default] 21.8 ms +- 2.7 ms -> [uhh-initial] 196 ms +- 23 ms: 9.01x slower
Mean +- std dev: [uhh-default] 21.8 ms +- 2.7 ms -> [uhh-speedup] 135 ms +- 10 ms: 6.19x slower

Geometric mean
==============

uhh-initial: 5.53x slower
uhh-speedup: 3.77x slower

nice win @muted haven ๐ŸŽ‰

#
โฏ pyperf compare_to uhh-initial.json uhh-speedup.json -G
Faster (2):
- parse-black/strings: 227 ms +- 27 ms -> 154 ms +- 3 ms: 1.47x faster
- parse-match-identifiers: 196 ms +- 23 ms -> 135 ms +- 10 ms: 1.46x faster

Geometric mean: 1.47x faster

from a different perspective

muted haven
#

Btw do you ship blib2to3 mypy-c compiled? @bright glacier

bright glacier
#

Not via PyPI yet, but I'm trying to community test the compiled wheels (all of black is compiled, not just blib2to3)

#

I should probably rebuild the current published set of wheels as main has a whole new set of features at this point ๐Ÿ‘€

#

I'll probably get ลukasz or something to tweet this issue out or something because right now I have one successful report for Linux 3.8 which is me ๐Ÿ™ƒ

silent apex
#

ooh ooh ooh I can do this rn, brb

bright glacier
#

Worst come to worse I'll just ask the whole core team to help out as we do have all of the hardware necessary to do so

silent apex
#

so wait, is the command just pip install black --extra-index-url https://ichard26.github.io/black-mypyc-index/simple/?

bright glacier
#

theoretically although you're the second person to try as far as I know

#

you might need the upgrade flag

#

It's hard hosting on your PyPI

silent apex
#

installed fine for me, I think I'm good

#

I have black, 21.11b2.dev14+gb336b39 (compiled: yes)

sour jay
silent apex
bright glacier
#

that's why I hosted my own PyPI style index with github pages :p

sour jay
#

Lol

bright glacier
silent apex
#

okie dokie

#

dang that was fast

bright glacier
#

you don't have to do it now, just sometime after you feel confident in describing your experience with it

#

although the name of the game here is more about quantities of positive field reports because with enough people y'know someone's gonna manage to break your code lemon_sweat

silent apex
#

err how do you clear black's cache? (I assume it does)

plain atlas
#

rm -r ~/.cache/black

bright glacier
#

There's no easy way on Windows

#

lemme find our docs

silent apex
#

ah fun

silent apex
#

tyty

bright glacier
#

I honestly made myself a simple utility to do this because I run into the cache way too much while developing

silent apex
#

wowowowow

#

black-compiled took half the time of regular black in formatting python-discord/bot

#

impressive, great job on this richard

plain atlas
#

neat

bright glacier
silent apex
#

not at all

bright glacier
#

phew

silent apex
#

smooth sailing

#

I have filed a field report

#

and I shall test on WSL for another later

bright glacier
#

thank you :)

plain atlas
#

now test by formatting the stdlib

bright glacier
#

lol

#

ambv would be very pleased of you

plain atlas
#

I've formatted it before

#

followed directly by git checkout .

#

sigh how do i installed compiled black

silent apex
bright glacier
#

can you wait a little bit

plain atlas
#

oh i see it above

#

and sure

bright glacier
#

I have a new set of wheels

#

just gotta push them

#

dawn, you don't have to wait, but arl shall wait :)

plain atlas
#

just gotta pull cpython

plain atlas
#

๐Ÿ˜”

bright glacier
#

because you're waiting to pull cpython lol

#

how fast is it for ya

plain atlas
#

no its pulled

bright glacier
#

๐Ÿ‘€

#

actually, I'mma just give you the file manually

silent apex
#

formatting stdlib now, let's see how it goes

bright glacier
#

what's your OS, Python version, and arch?

silent apex
#

fuck it broke

bright glacier
#

yeah that's expected

#

there's an issue on the tracker with various crashes for formatting cpython

silent apex
#

ah okie

plain atlas
bright glacier
#

do you have a preference lol?

plain atlas
#

not really, no

bright glacier
#

pypy is not supported btw

plain atlas
#

ยฏ_(ใƒ„)_/ยฏ

#

3.9.9 ig

#

or 3.10 because there's probably some random bug with 3.10 :kekw:

bright glacier
#

well here's the workflow while I unpack the zip to DM you the wheel

plain atlas
#

neat, I'll take one linux x86-64 wheel, please

#

with extra onions

bright glacier
#

... lemon_sweat

#

fuck I downloaded the zip to the wrong foler

plain atlas
#

lmao

bright glacier
#

let's see if I can upload a .whl file here with my staff perms

#

probably not

plain atlas
#

you can

bright glacier
#

oh damn

#

anyway I'mma push this new set to the index

plain atlas
#

i'll test in a moment, i'm working on my nuke discord bot

bright glacier
#

excuse me what ๐Ÿ‘€

plain atlas
#

wait-- that sounds bad, that's not what I mean

#

I've been testing slash commands and now i have a bunch of those that don't exist, so I need to clear them

bright glacier
#

d'ah

plain atlas
#

So I'm nuking my slash commands

#

okay done

#

they gone

plain atlas
#

no

#

I used 3.9 but the wheel is 3.10

#

its installed now

bright glacier
#

there

#

@dense jungle I prefer to do a release now with Batuhan's performance improvement merged so I can update the mypyc wheel index with a compiled release (instead of a development version for the time being). Batuhan said they'll need some time for additional performance wins.

#

Thoughts?

plain atlas
#

huh i got this error when formatting the stdlib

#

maximum recursion depth exceeded while calling a Python object

bright glacier
#

that's already known lol

plain atlas
#

lmfao was about to say, better not be expected

bright glacier
#

basically there's an assignment chain of 1000+ assignments

late dewBOT
#

Lib/test/test_exceptions.py line 1758

# Mutating locals() is unreliable, so we need to do it by hand```
plain atlas
#

lmfao

bright glacier
#

Yeah talk about unreasonable input

plain atlas
#

@bright glacier I ran it, do you want the good or bad news first

bright glacier
#

bad news first

plain atlas
#

i didn't run it with time

bright glacier
#

because the "did you mean" feature of NameError / AttributeError shouldn't slow it down too much, so if there's too many locals the feature is disabled

bright glacier
plain atlas
#

idk i walked away from my pc

bright glacier
#

:>

plain atlas
#

oh come on!

bright glacier
#

Also I think we should consider the fact that we crash on that function with 800 locals to be a feature.

  • Jelle

not totally unreasonable ๐Ÿ˜„

plain atlas
#

black got installed to my site packages

#

somehow

silent apex
#

wait how'd you get it to work?

#

black . in cpython/lib crashed in ~2 seconds for me

bright glacier
#

if not then it sounds like I have a mypyc bug to deal with

plain atlas
#

!remind 40M back from thing i have to do, now do other thing and other thing, but not confused with thing a or b

late dewBOT
#
You got it!

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

plain atlas
#

I'll update you when I'm done with thing cffc41bd

bright glacier
#

๐Ÿ‘€

#

hastebin it maybe?

silent apex
#

I'll get you them in text in ~20 minutes

plain atlas
plain atlas
silent apex
#

err, maybe it's cause I cloned master but am using 3.9.9 rn?

plain atlas
#

I cloned master and am using 3.10

#

but black is supposed to be able to

#

OH

#

@silent apex specific -t py310 on the cl

silent apex
#

oh frick

plain atlas
#

I didn't even look at your error lol

silent apex
#

nope still dies

little parrot
#

you need to be on 3.10

bright glacier
#

wtf is that error

#

it's literally crashing on an union

silent apex
#

I'll install 3.10 and try then

bright glacier
#

I'mma try a newer revision of mypy actually

plain atlas
bright glacier
#

there's a performance win which inlines most of the refcnt operations

silent apex
bright glacier
#

what happens if you try a pypi version of black?

#

You're not running black within cpython/lib right? because then imports would use stuff from your checkout which might not go so well

silent apex
late dewBOT
dense jungle
#

do you want to do it?

bright glacier
#

Sure, playing gartic phone with the staff here atm though =p

plain atlas
#

what did i do

bright glacier
#

what

plain atlas
#

oh nvm a simple mistake nvm nvm

dense jungle
#

I think you most likely have an empty black directory on your PYTHONPATH somewhere

#

so it interprets it as a namespace package

plain atlas
#

that's close enough to what happened, yeah

dense jungle
#

I guess not necessarily empty

bright glacier
toxic stormBOT
plain atlas
#

yeah, its black's repo lmao

bright glacier
#

I can do the release this time

dense jungle
#

thanks, sounds good!

#

also we've been running mypyc black at Quora since last week or so and everything has been smooth, I should submit a report

bright glacier
#

oh! ๐Ÿ‘€

flat krakenBOT
#

First release without regex in a loooong time. Let's hope we haven't broken anything this release as man did we have lots of experimental changes.

Checklist - did you ...

  • [x] Add a CHANGELOG entry if necessary? -> I think the changes will speak for themselves :)
  • [x] Add / update tests if necessary?
  • [x] Add new / update outdated documentation?
bright glacier
#

Sorry for the delay by the way, it turns out I underestimated how much time I had left before I was up to play with staff oops.

flat krakenBOT
bright glacier
#

@dense junglehttps://github.com/psf/black/releases/edit/untagged-9e05f026ee64102be3a9 looks good?

#

I'm totally down to remove that contributors part if you'd like

#

I saw the "auto-generate changelog" button and was curious to what it does ... then played around with its output :p

#

wait, do github releases now include this by default? cause my extra effort is useless then

#

Doesn't seem like it, probably due to me tagging them

plain atlas
#

<@&831776746206265384>

bright glacier
#

I filed an incident already but alright :)

plain atlas
#

half expected a scam link after that

#

when they didn't send, I was like, "fuck i should have dmed modmail"

mint barn
#

bruh

#

its not a scam

plain atlas
bright glacier
#

I didn't

#

but the staff team have filed an incident for the mods to take a look at

plain atlas
#

ah

dense jungle
#

looks like I missed all the moderation fun

bright glacier
#

I expected you to press the publish release button ๐Ÿ˜†

#

I'll do it

flat krakenBOT
bright glacier
#

!remind 1D update docs for stable revision

late dewBOT
#
Sure.

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

plain atlas
#

hmmm

plain atlas
#

this means that all maintainers can update the stable docs, just as they can update the tag

#

worth making, perhaps?

bright glacier
#

that seems unnecessarily complicated

#

also this shouldn't be necessary as RTD should theoretically pick up the updated stable tag but doesn't

plain atlas
#

its not, its a few lines, to use curl and a token to trigger a build

#

oh right i meant to actually make it trigger on the tag update

#

which wouldn't be complicated, either

#

not when a maintainer triggers it as that's already being trigger--

#

wait a sec brb

#

i-

plain atlas
bright glacier
#

no the webhook is being fired, it's just picking up the wrong revision somehow

plain atlas
#

you sure?

bright glacier
#

yes

plain atlas
dense jungle
bright glacier
#

how did you notice?

dense jungle
#

by refreshing

#

they weren't there when I looked half an hour ago

bright glacier
#

Yeah that's because I have to trigger the build and upload the wheels manually.

flat krakenBOT
bright glacier
flat krakenBOT
grave fox
#

Do you guys a GitHub action out to automatically run black on code in a commit or PR?

plain atlas
#

there's both an action and a pre--dang it jelle :D

grave fox
#

perfect

late dewBOT
bright glacier
#

Damn, compiled black really is faster - I just ran it against the pip project and it's probably twice as fast

#

that is stupid fast startup with compiled black ๐Ÿ‘€

#

.. and there's literally a faster startup PR for black (not blackd) so this could get faster (although it does some things I'm uneasy with)

flat krakenBOT
bright glacier
#

pre-commit.ci might not like our local black hook fwiw for autoupdating

bright glacier
#

I'm going to try to pick up psf/black#2095 and rewrite it (while addressing feedback) and hopefully drive it to completion

bright glacier
#

hmm, I don't like the existing infrastructure for running transformers - I mayy try to clean it up although I'm nervous I might break something

dense jungle
#

And maybe unary operators on non-complex expressions are still non-complex

#

2**-2 vs. 2 ** -2

plain atlas
bright glacier
#

I fucked up the commit title too

plain atlas
#

aw

bright glacier
#

Oh haha I did not realize I swore in a public channel (not that it matters but in general I try to not do that publicly)

gusty grail
#

you're grounded for 6 months lemon_cop

flat krakenBOT
#

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

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

Describe the bug

When using #fmt: skip, if there is no space between the # and f then black fails to format due to different result in the second pass.

To Reproduce

For example, take this code:

def test():
    x = 1 #fmt: skip

https://black.vercel.app/?version=main&state=_Td6WFoAAATm1rRGAgAhARYAAAB0L-Wj4ABwAFNdAD2IimZxl1N_WlbvK5V_5PM4Nceap1_OfA9LqGqzctuugz_qJKhKcm0xODvQpn1SGiQJFVPjQaZCfva5pKHycj-2VXHw1ESugA17W0JffVNXXrlGAAC1vzI706u2xQABb3Hpg-HlH7bzf...

flat krakenBOT
grave fox
#

So a question about formatting items like function definitions/calls with arguments. Say I have something like this:

def some_really_long_name(some_big_arg, another_big_arg):
  # do something

Now if black sees that the function definition line exceeds the line length I set, it'll format it like this:

def some_really_long_name(
  some_big_arg,
  another_big_arg,
):
  # do something

My question is if it's possible to force black to format all functions one way or the other, not have a mix-and-match approach to it? I would like to keep the styling the same for readability, so going with the latter option for all my function definitions and calls would be preferable over the former

errant barn
#

I'm afraid not, we'll fit it onto one line if it can!

dense jungle
errant barn
#

Although, you could use

dense jungle
#

But I feel like that's pretty ugly for one-argument functions.

grave fox
#

Oh for one argument functions I'd be keeping it on a single line
My minor issue was when I would have some heavily indented piece of code where one function call would be formatted in a single line, but a following function call right below would just exceed the line length limit and split into multiple lines, which makes everything hard to read
But hey that tip to add a comma to the last argument works like a charm, thank you!

red sedge
#

woah did django land black?

red pendant
#

failed mypy when running pre-commit run -a from the basics of trying to setup the repo for black, here's a screenshot:

#

should this be an immediate concern?

dense jungle
red pendant
dense jungle
#

that looks unrelated, totally different error

flat krakenBOT
#

When I update black I keep seeing following message:

[2021-12-07 22:35:45       driver.py:266 -          load_grammar()] Generating grammar tables from /home/alper/venv/lib/python3.8/site-packages/blib2to3/Grammar.txt
[2021-12-07 22:35:45       driver.py:269 -          load_grammar()] Writing grammar tables to /home/alper/.cache/black/21.11b1/Grammar3.8.10.final.0.pickle
[2021-12-07 22:35:45       driver.py:273 -          load_grammar()] Writing failed: [Errno 2] No such file or d...
steady plaza
#

I've made a .pre-commit-config.yaml with:

default_language_version:
    python: python3.9
repos:
-   repo: https://github.com/psf/black
    rev: 21.12b0
    hooks:
    - id: black

I run pre-commit run --all-files.
Get error in file "black\cache.py", line 13": ModuleNotFoundError: No module named '_black_version'

I've tried reinstalling everything and cleaning pre-commit. Anyone have a clue?

stuck vapor
#

I can't reproduce that @steady plaza , it works fine for me

perhaps try updating pre-commit?

flat krakenBOT
steady plaza
red pendant
#

How would I go about running a coverage test with my own test for black? I see something called .coveragerc is this something we are suppose to use?

errant barn
red pendant
#

actually, I was just about to write my own test case for black

#

it has to do with testing the # skip format

#

but i'm not sure where I would actually add that test case

errant barn
#

Oh I see

#

So adding tests in general

red pendant
#

ah i see

#

i was looking at the test_format.py on the outside of that folder

errant barn
#

Yeah it can be a bit hard to parse what's going on ๐Ÿ˜…

red pendant
#

no problem, i greatly appreciate the guidance

#

it probably saved me quite a bit of time

#

so i just added a test in data called fmtskip7

#

the outside files evaluate these different source files so I have to add the string "fmtskip7" to SIMPLE_CASES in test_format.py

errant barn
#

If you created the file, yes. But if it was already there, then not needed!

red pendant
#

actually, i'll try testing this out right now instead.

#

sorry if i'm asking a lot of questions..how would I run the specific unit test I created with coverage?

errant barn
#

Yikes that might be a bit difficult ๐Ÿ˜„ since the tests are generated on the fly. There might be a pytest syntax for that but at least I'm not familiar with it.

red pendant
#
tox -e py
errant barn
#

Isn't it enough to run overall coverage?

errant barn
#

and prints coverage info as well

red pendant
#

a user reported this bug here regarding the # fmtskip generating an error if it's put together

#

is this something we need to resolve? Becausei n documentation, we have # fmt skip which has a clear space between the hashtag and fmt

errant barn
#

Definitely, either we fix the comment and then ignore, or accept the ignore without a space. An internal failure is not an option ๐Ÿ˜„

red pendant
#

yeah i replicated the error on my machine

errant barn
#

Nicely done

red pendant
#

and added a test fmtskip7

errant barn
#

I'll respond to the issue as well

red pendant
#
a, b = 1, 2
c =    6  #fmt: skip
d = 5
#

yeah test_format.py loses coverage

#

if you're going to be responding to this issue, do you mind assisting me a bit? This is my first repository i'm trying to make contributions to, and I'd like to become more independent

errant barn
#

Sure!

red pendant
#

it doesn't seem like #fmt off has an issue

#

it actually added a space

errant barn
#

Yep, verified here too!

red pendant
#

before: #fmt off

#

yeah

errant barn
#

uhm.

#

this is awkward :D

red pendant
#

?

red pendant
#

the format is corrected for the comment

errant barn
#

I have not used them

red pendant
#

fmt off and on i believe are for blocks

errant barn
#

that much I know :D

#

Oh, they need to be in the same level of indentation and start a block, so I guess inline comments are not handled at all

#

so we're good ๐Ÿ˜…

red pendant
#

so we just need to fix the issue with #fmt skip

#
FMT_SKIP: Final = {"# fmt: skip", "# fmt:skip"}
#

it can't be as easy as just...

errant barn
#

It's probably that easy ๐Ÿ˜„ but what about #fmt: skip etc.

red pendant
#

so basically we want to check the format and correct it

errant barn
#

I think let's hear from other maintainers on the issue for now, because they might disagree with my preference

#

I'd say 1) don't fix 2) accept arbitrary spacing

red pendant
#

yeah it seems if you add any amount of spacing the internal error dissapears

errant barn
#

Oh! So my example doesn't error?

red pendant
#

but it renders the skip ineffective

#

no it does

#

but something like:

#
a=1
a=1 #     fmt: skip
a=1
errant barn
#

I see, so that's corrected to # fmt: skip and not formatted

#

then it could be possible to reformat other types as well!

red pendant
errant barn
#

Oh.

red pendant
#

yeah that's what i meant

errant barn
#

Nevermind ๐Ÿ˜„

red pendant
#

it doesn't give an internal error

#

but it doesn't do anything

errant barn
#

And the comment isn't even fixed

red pendant
#

the error specifically only happens when you have ```
#fmt: skip

#

but yeah it doesn't reformat in other cases of arbitrary space

errant barn
#

Well this is a mess huh. Best to add this to the same issue, because this is definitely related.

red pendant
#

I can make a seperate bug report and link to the old one

errant barn
#

That's fine as well!

red pendant
#

there's no way to generate a visible report from the test coverage either right?

#

like to see where certain LOC ran

errant barn
#

There is! coverage report -m

#

-m being the "missing" flag

red pendant
#

hmm

#

its missing functions

#

that my test wasnt suppose to be in

errant barn
#

I haven't actually checked it, I doubt we're at 100% anyway

#

What's the grand total?

terse jay
#

Hi guys, how do I make when a person leaves their email on my site, then the bot will send him an email, information that he bought on my site? If you can help me, I'll pay

errant barn
#

gamble: !rule 9

#

!rule 9

late dewBOT
#

9. Do not offer or ask for paid work of any kind.

errant barn
#

YES it worked

red pendant
#

prior to the run with the test that has the buggy skip, test format was at 100% coverage

terse jay
#

I'm sorry, but where do I find help

errant barn
#

Try the lobby or general channels, or the help channels if you have specific questions ๐Ÿ˜„

red pendant
#

now its at 96%

errant barn
#

that function specifically?

terse jay
#

Thanks

red pendant
#

i think what might've happened is the internal error we suffer occurs prior to running these functions

errant barn
#

You're not talking about the file test_format.py are you?

#

Maybe I've confused myself

red pendant
#

yeah im referring to the test_format.py test coverage

errant barn
#

Odd that adding a data test affects that..

red pendant
#

anyway to debug?

errant barn
#

Oooh unless, is the test failing with the internal error?

red pendant
#

^ yes

errant barn
#

Oh I see, the format tests are naturally expected to pass. So coverage isn't really valid

red pendant
errant barn
#

It's the coverage of Black source that matters

#

If the test suite itself fails, then we can't gather coverage information

#

So we'd need to first fix the issue, then make the test and finally measure coverage

red pendant
errant barn
#

Or make a test runner that expects the failure. But we'd rather fix the bug, right? ๐Ÿ˜„

red pendant
#

yes

errant barn
#

Although it's good to have failure tests as well for user errors, but that's beside the point.

red pendant
#

this isn't doing its job I believe

#
def make_comment(content: str) -> str:
    """Return a consistently formatted comment from the given `content` string.

    All comments (except for "##", "#!", "#:", '#'", "#%%") should have a single
    space between the hash sign and the content.

    If `content` didn't start with a hash sign, one is provided.
    """
errant barn
#

Could very well be

mint barn
#

i know this is a python server but can anyone help me with this java error in cmd

plain atlas
#

!ot

late dewBOT
bright glacier
#

man, I don't know how possible it is to check whether we're in a new expression with the line transformer based system

#

AFAICT all of the AST information is lost after the AST visitation logic and the visited line is compacted into a list of leaves >.<

dense jungle
bright glacier
#
a = [x**y, x**y]
``` right now with the PR code, the lack of spaces between the power operator is allowed because the whole line has more than one hugging power operator
#
line.leaves=[Leaf(NAME, 'a'), Leaf(EQUAL, '='), Leaf(LPAR, ''), Leaf(LSQB, '['), Leaf(NAME, 'x'), Leaf(DOUBLESTAR, '**'), Leaf(NAME, 'y'), Leaf(COMMA, ','), Leaf(NAME, 'x'), Leaf(DOUBLESTAR, '**'), Leaf(NAME, 'y'), Leaf(RSQB, ']'), Leaf(RPAR, '')]

and this is what I'm working with ...

#

I feel like I'm missing something obvious though.

dense jungle
bright glacier
#

It's just inconsistent with return x ** y / return x**y, a**b for example

dense jungle
#

Maybe we shouldn't space that either? The rule could simply be that we never space ** with simple LHS and RHS

bright glacier
#

Apparently ambv and a few people agreed that a single power op should not hug but honestly I don't understand whyyy exactly

dense jungle
#

might be worth just having a discussion with some of the interested people about exactly what the rule should be

bright glacier
#

Thinking about it some more (actually, a lot more) it seems to me like the easiest improvement here is to do what @paugier was suggesting all along, especially clearly in his latest comment, with the following additional twist: if ** is the only operator in the expression, then don't hug.
https://github.com/psf/black/issues/538#issuecomment-593957202

dense jungle
#

yeah, I don't really see a strong argument there for special-casing single expressions

flat krakenBOT
#

Description

Reasoning for change can be found here: https://github.com/psf/black/issues/2680
From running individual tests, it's seen that of all the formatting options, the inline option, or # fmt skip causes an internal error for black, when the comment should be reformatted like # fmt off. A proposal for this issue was made in the fmtskip_nospace branch which aims to hard code logic handling this bug within the make_comment function of comments.py.

Checklist - did you ...

...

bright glacier
#

this feels fragile but then again this entire part of the codebase is fragile :p

#

skip: skip was honestly quite undertested IMO

tired shard
#

Could I get some more reviews on my PR?

flat krakenBOT
tired shard
#

I could possibly add root to ctx.obj, it would require passing but would be less compared to root as some of the functions already take in ctx

errant barn
#

Mjeh, could be worth a try, but let's see what the others think. I'm not sure what else the context is being used for

tired shard
#

one thing can be done, make root a class variable for Report, and move find_project_root to teh main black cli function so we can pass root when we are making Report

errant barn
#

Sounds possibly good as well ๐Ÿ‘๐Ÿฟ

tired shard
#

ok @errant barn i tried doing the above change and it looks much much better, pushing the code, would make it easier to decide also :)

errant barn
errant barn
#

@tired shard psst, I think you didn't push it

flat krakenBOT
#

Describe the bug

TLDR: Black produced code that is not equivalent to the source on pass 1 when processing a multiline format string in the first line of the body of the function.

While this is a proper doctoring:

def fun_1():
    """hello from docstring"""

this isn't:

greeting = "hello"
def fun_2():
    f"""{greeting} from docstring (except not really)"""

Regardless, however, it is a valid python code, even though it might not produ...

flat krakenBOT
#

INTERNAL ERROR: Black produced code that is not equivalent to the source on pass 1.

Describe the bug

--- src
+++ dst
@@ -8252,175 +8252,175 @@
                   id=
                     'IndeedXMLRenderer',  # str
                 )  # /Name
             )  # /List
         )  # /Assign
-        FunctionDef(
-          args=
-            arguments(
-              args=
-                arg(
-                  annotation=
-                    None,  # NoneType
-...
bright glacier
#

I'm a little confused at why we're normalizing the paths to be from the root when emitting the log messages

#

Right now the code is careful to not modify the passed in SRCs as much as possible so when we do log 'em it's clear they're from what the user passed in

#

for example, the fact they're prefixed with black/ strikes me as odd given I explicitly passed in src

tired shard
tired shard
#

@errant barn pushed, i did push yest but the pre-commit failed, and then I never looked at it until now (wasn't at home)

bright glacier
#

this was surprisingly simple ๐Ÿ˜„ still got one major feature to add and a few minor ones

mint barn
#

what's the best way to make black still exit with 0 if it couldn't reformat a specific file because of a match statement, but still exit with non zero if something got reformated?

lament crow
#

Are you using latest version? Because there is basic support for 3.10 features added

mint barn
#

I have 21.12b0

lament crow
#

are you using target version 3.10?

#

as in, --target-version py310 in CLI arguments or this in pyproject.toml:

[tool.black]
target-version = ['py310']
mint barn
#

no

lament crow
#

Yeah, you need this to have 3.10 support for now as it's still experimental

flat krakenBOT
mint barn
#

hello guys , who knows how to connect MongoDB data base to a project using pythoin?

#

when ever I connect it it says err":{"name":"MongoError","message":"bad auth Authentication failed.","ok":0,"errmsg":"bad auth Authentication failed.","code":8000,"codeName":"AtlasError"}}

jagged fossil
#

hey guys, im trying to make a really basic plugin to copy paste docstrings from pdf. i havent been able to find any resources on how to make a plugin like black for pycharm. can anyone point me in the right direction?

#

gonna move this to help channel also

bright glacier
#

!remind 1D do a more proper review on psf/black#2656

late dewBOT
#
You got it!

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

flat krakenBOT
bright glacier
#

I implemented your mypy_primer feature request for diff-shades Jelle :)

#

I guess if we're using a github URL I could rewrite the URL to point to the tree at the recorded revision ๐Ÿค”

dense jungle
#

thanks this is great ๐Ÿ˜„

short forge
#

<@&831776746206265384>

glacial gate
#

!ban 898297969684660224 Racism

late dewBOT
#

:incoming_envelope: :ok_hand: applied ban to @neon oasis permanently.

flat krakenBOT
#

While handling fluent interfaces if the instruction is within parenthesis Black formats it this way:

  • Original
(spark.read.parquet(path).select(columns).filter('column is not null').filter((f.size('id_list') > 1) & (f.col('operating_system') != 'iOS')))
  • Formatted
(
    spark.read.parquet(path)
    .select(columns)
    .filter("column is not null")
    .filter((f.size("id_list") > 1) & (f.col("operating_system") != "iOS"))
)

However if the ins...

mint barn
#

hey

#

plz help me in my code

short forge
swift fossil
#

Howdy y'all. I've been using Black forever, and I feel like it'd be a good time to give back. I'm gonna go through the contributing guide and try my best at some stuff. :'] Just wanted to say hello, etc, etc.

errant barn
late dewBOT
viscid bane
#

How do I tell vscode to use the black setting that I defined in the pyproject.toml?

upbeat portal
#

idk if it's the right channel to ask, I started using Black a few weeks ago and one thing I noticed was the use of parenthesis in some cases (like backslashes)

#

I'm a bit confused about what those parenthesis are

#
# in:

if some_long_rule1 \
  and some_long_rule2:
    ...

# out:

if (
    some_long_rule1
    and some_long_rule2
):
    ...```
#

is (some_long_rule1 and some_long_rule2) a tuple with a boolean in it ?

#

(<- python beginner)

swift fossil
#

In PEP8 [https://www.python.org/dev/peps/pep-0008/#indentation] they specify this as the preferred method to multiple lines for bool masks, args, etc.

(PEP8: "The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. Long lines can be broken over multiple lines by wrapping expressions in parentheses. These should be used in preference to using a backslash for line continuation.")

So, it's not a tuple, it's just syntax which wraps around stuff for multilines and the like. A one element tuple looks like this: (1,) instead of (1).

plain atlas
#

well i forgot i asked to do this issue

#

!remind 2y actually finish that pr that makes black and isort conflict

late dewBOT
#
Aye aye, cap'n!

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

lament crow
#

2 years!?

bright glacier
#

๐Ÿ‘€ pithink

lament crow
#

you could comment on the issue to get unassigned to not discourage potential contributors :P

plain atlas
# lament crow 2 years!?

i don't check my github notifications enough, figured i'd add some leeway ยฏ_(ใƒ„)_/ยฏ

plain atlas
bright glacier
#

I get emails for GitHub notifications <.<

lament crow
#

thought you were serious-ish with those 2 years and that you're not interested in working on it any time soon :P

plain atlas
#

partially\โ„ข๏ธ

#

is magic trailing comma on by default for black?

bright glacier
#

Yes, it's why we have the --skip-trailing-comma flag

upbeat portal
#

btw I'm kinda getting better at python (still beginner though), I'm still looking for a friendly open-source project that I can start contributing

#

is this a good idea to join this project? even if my contributions will be very limited?

bright glacier
#

Being an older project with a fair amount of cleanup needed there's quite a few rough edges to be honest but overall it's still a relatively easy project to contribute if you choose your issues the right way which I can help out with :)

#

Also, the core logic behind black is very tree (i.e. node and leaf) heavy so experience in those areas will be required if you want to make changes to the actual formatting -- FWIW when I first contributed I didn't have much experience with mangling tree structures but that didn't stop me from contributing in other ways

upbeat portal
#

Well I watch some AnthonyWritesCode streams and I've done AoC21/day10, so I have some veeery basic notions about linters/parsing

#

I discovered thanks to AoC, graphs and DFS this week. Is a tree a kind of graph (or inverse)?

bright glacier
#

yeah kinda -- lemme pull up an example tree black could operate on (after parsing)

upbeat portal
bright glacier
#

!paste

late dewBOT
#

Pasting large amounts of code

If your code is too long to fit in a codeblock in discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.

bright glacier
#
with open("daylily.txt", encoding="utf-8") as f:
    blob = f.read().splitlines()

that's the blib2to3 AST for this code this

#
GitHub

Is this related to a problem? Please describe. On Black's future style doc it talks about black handling a with with multiple context managers in a few ways (Python-version-dependent). Desc...

GitHub

The documentation doesn't say anything about our PyInstaller binaries (or if it does I can't find it). Let's fix that.

GitHub

Currently, the implementation of is_type_comment() looks like this: def is_type_comment(leaf: Leaf, suffix: str = "") -> bool: """Return True if ...

#

Seems easy enough issues this

dense jungle
#

^ wow my hack fixed bugs instead of introducing bugs

#

we should have a regression test for this though, another easy issue

upbeat portal
#

you created a tag just for me (and other open-source beginners) โค๏ธ

#

very kind of you @bright glacier

bright glacier
#

I've made a "stable release" milestone fwiw: https://github.com/psf/black/milestone/1 -- I don't like using Projects as I find they take too much effort to manage and I end up forgetting about them (also the pre-existing stable project is in disorder), feel free to reorganize it Jelle

GitHub

The uncompromising Python code formatter. Contribute to psf/black development by creating an account on GitHub.

#

None of these are true blockers but they'd be nice to get in -- only formatting issues / PRs in this milestone would count as potential blockers due to the stability policy

#

Honestly should we aim to get ESP enabled by the stable release? Given there's some formatting changes I'd like to see made to ESP + that pesky performance penalty it feels optimistic that we'd be able to get it in.

#

Oh yeah, I suppose we should probably make a decision in regards to parenthesized withs by then too as those are gonna get more and more common

tired shard
#

Could I get another review on psf/black#2525 and I have mentioned the changes in psf/black#2526

late dewBOT
#

src/black/comments.py line 105

def make_comment(content: str) -> str:```
flat krakenBOT
#

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

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

Describe the bug

Python 3.10 begins to throw a deprecation warning for the distutils package, which will be removed in Python 3.12. The recommended fix is to use setuptools or to check PEP 632 for alternatives.

This isn't a workflow blocking issue, as pressing Enter or typing a command brings you to vim as normal; its just an extra step when starting Vim, and a deprecation that should be fixed for Python 3.10 (and especially >=3.12) support.

To Reproduce

On a system wi...

mint barn
#

.

upbeat portal
#

Is black conflicting with flake8 ?

upbeat portal
#

black autoformats my_list[i:i+1] into my_list[i : i + 1]

#

lol exactly the issue I had

#

I just switched to mypy but now I have another problem/question ( #help-pretzel )

plain atlas
#

!remind 2D mark that isort issue up for grabs ๐Ÿ˜”

late dewBOT
#
I'll allow it.

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

bright glacier
#

i'd've -- I saw this once on a YouTube video and I love it now.

stuck vapor
bright glacier
#

hmm I wonder if y'all'd've would be in there too ๐Ÿ‘€

#

no I'm not kidding ๐Ÿ˜† I'm genuinely curious

errant barn
#

I think we'd'ven't

bright glacier
#

'hank goodness

errant barn
#

english stack exchange here we go

#

although richard, you're a native right?

bright glacier
#

well this escalated quickly lemon_sweat

#

Uh kinda? I was born in Canada but my mother's tongue isn't English but then again I can't really speak my mother's tongue ..

#

Like I know French better than I do my family language :?

errant barn
#

oh ๐Ÿ˜… well close enough!

#

cause I've heard that there is no central authority on english language, so if it's in use, then it's correct ๐Ÿ˜„

#

especially if a (kinda) native says it

bright glacier
#

Wait, I might using "mother's tongue" incorrectly

#

I thought it was literally language your mother speaks but apparently means "native language"? Ugh I need to crack open a dictionary

errant barn
#

well I suppose it's both :D

#

leaning on "the language you speak"

bright glacier
#

Like I live in a non-English/French household but I can only speak languages of the place I live (which is English et le franรงais)

#

So technically if the bar for knowing a language is super duper low I'd count as a trilingual but practically I'd call myself 1.5 bilingual

errant barn
#

I'm not sure but my math says 1.5x2=3 ๐Ÿ˜†

#

what's your third?

bright glacier
#

well... that's awkward

#

Chinese in particular Mandarin

#

Can't write or read it all

errant barn
#

oh shoot, cool

bright glacier
#

Je peux seulement รฉcrire /lire en franรงais ou anglais

dense jungle
#

My wife is kind of like that, her family is Chinese but she can barely speak it now

errant barn
#

joo just nii, jep

bright glacier
#

I can't even read the latinized writing aka pinghi?

#

Romanization of Chinese (Chinese: ไธญๆ–‡ๆ‹‰ไธๅŒ–; pinyin: zhลngwรฉn lฤdฤซnghuร 

#

well I was pretty wrong :p

errant barn
#

now to guess what's the meaning of all those accents

bright glacier
#

It's fun knowing some French since I can now attach meaning to accents and seem more cool than I really am

dense jungle
errant barn
#

Sure :D I only know basic umlauts, and the stress รฉ on my last name

bright glacier
#

I heard there's four ones, flat, rising, falling, and some wavy one ..?

errant barn
#

No wait, I can hear my father disapproving from 300 kilometers, not a stress, but an acute accent ๐Ÿ˜…

bright glacier
#

un accent aigu ๐Ÿฅ–

#

I should probably do my french gรฉo homework now lol.

#

Every damn time I get French ads inbetween my background music, it's really something.

errant barn
#

Beautiful language though, even though I'm quite clueless to its meaning

flat krakenBOT
bright glacier
flat krakenBOT
dense jungle
#

except the error message they posted says "cannot format file.py: INTERNAL ERROR"

#

unless that's from the template?

bright glacier
#

hmm it might be

bright glacier
#

So basically the whole main post is useless garbage while the comment they added is the actual issue, sigh.

dense jungle
#

right, I think you got the actual issue out though, thanks!

bright glacier
#

oh wow we actually assert that the right ANSI codes are expected in the output >.<

#

I was not expecting that at all.

plain atlas
bright glacier
#

hmm I can't reproduce psf/black#2594

toxic stormBOT
flat krakenBOT
red sedge
bright glacier
flat krakenBOT
flat krakenBOT
bright glacier
#

man, honestly I might approve psf/black#2526 even though I don't understand the changes in regards to us printing the SRC

toxic stormBOT
bright glacier
#

yeah I know I just hate myself for going back and forth on this PR so many times

#

basically I'mma give up on fighting for my opinion here since clearly it's dumb

plain atlas
#

heads approve it, tails deny it /s

bright glacier
#

@tired shard I'm so sorry for being so flip-floppy on this verbose PR, it looks good to me except now I realize why including the root in the log messages was a good idea (for the SRCs log mind you, I still disagree it's a good idea in the other logs).

#

Basically, my opinion here is use felix's output design because it's way better than what I can come up with but let's try to avoid touching the other printed paths in the logs since people are probably used to how it works

#

but overall, if it feels dumb, then ignore my opinion, I'm as done with this PR as you are most likely and I don't want to fight it anymore

#

PS. it crashes if you format a directory that doesn't share a common base within the project root

#

This is probably my fault and I'm sorry for this too.

#

also, it seems like felix's output has the "identified X as project root" line before the "using configuration from project root" line which seems better to me

flat krakenBOT
bright glacier
#

all sources that are about to be formatted relative to the project root, meaning that if I'd run black . ../tests in one level into the project e.g. in project/src, I'd see something like about to format: project/src and about to format: project/tests
If my defeated ranty paragraphs were confusing, the TL;DR is to apply this comment to the sources line (and maybe the "reformatted X" lines too if just applying it to the SRCs line is dumb - i.e. revert my feedback).

flat krakenBOT
bright glacier
#

if someone wants to fix this I'd be happy but I'm not doing so right now.

plain atlas
slow ibex
#
# this is invalid code:
for x in f(lambda: i := 0,):
    pass

# black formats it to:
for x in f(
    lambda: i := 0,
):
    pass
plain atlas
#

remove the ,

dense jungle
#

the magic of the magic trailing comma

dense jungle
tired shard
#

yeah thanks richard, I will look into your feedback and address it soon :D

late dewBOT
#
Fat chance.

Your reminder must have a content and/or reply to a message.

tired shard
#

!remind 3d that

late dewBOT
#
Okay.

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

bright glacier
#

you can reply to a message and the bot will use the linked message as the content field if it's not provided explicitly

tired shard
#

yeah, i was the one who created a issue for that lol

bright glacier
#

and I reviewed the contributing PR :)

flat krakenBOT
#

Using black, 21.12b0 (installed with pip3) on Ubuntu 20.04, integrated with the atom-editor package.

The problem is black seems to be messing up working code, introducing duplicate definitions of well defined functions and putting bracket opens and close at random places that are throwing error.

Even if pylint was showing only warning and no error before applying black, the pylint itself is showing multiple errors after formatting with black.

I have been recommended python black r...

dense jungle
#

maybe their editor is doing something weird?

tired shard
late dewBOT
#

src/black/__init__.py lines 533 to 536

paths = '", "'.join(
    str(Path(source).absolute().relative_to(root)) for source in src
)
out(f'Sources to be formatted: "{paths}"', fg="blue")```
errant barn
tired shard
#

doesn't absolute also do that pithink

errant barn
#

You know, I thought it did, but looking at pathlib's documentation I cant see a reference to it ๐Ÿ˜…

dense jungle
#

I think there's a longstanding bug about clarifying the behavior of those two

#

Isn't one of them undocumented?

errant barn
#

Maybe this one

tired shard
#

probably, well that works :D I will push the fix

errant barn
#

The link was visited as well ๐Ÿ˜„

tired shard
#

purple lol

errant barn
#

Oh, from the discussion: Path.absolute() means exactly Path.cwd() / p

tired shard
#

felix had also probably suggested that

#

and i gave the same reasoning

#

here

tired shard
#

man this conflicts

dense jungle
#

now you have .absolute().resolve() though

tired shard
#

yeah?

errant barn
#

One option could be to only calculate the root once, maybe by caching or something.

#

Or pull the find_project_root out from find_pyproject_toml and just pass the found root there. Now it just directly calls it with the argument and it's only used there.

late dewBOT
#

src/black/files.py line 74

path_project_root = find_project_root(path_search_start)```
tired shard
tired shard
errant barn
#

Yea

#

Although I'm just flailing about, needs to be actually tested, but might work

tired shard
#

hmm, i could move find root and method to the main function and then cache them to ctx.obj[]

edit"
and richard review

#

which can then be used in get sources

errant barn
#

That could be nice, a small performance gain as well ๐Ÿ˜„

tired shard
#

not really, we only call find root once i think

tired shard
late dewBOT
#
Alright.

That reminder has been deleted successfully!

errant barn
#

Oh, at least twice now, in your PR and then when reading the TOML

#

*finding

tired shard
#

ah yes

frigid grotto
#

i see in the code comments that

All comments (except for "##", "#!", "#:", '#'", "#%%") should have a single
    space between the hash sign and the content.

but the formatter only adds a space if there isn't one, and doesn't remove extra space

#

i was wondering if all comments should only have one space or should that only be for type comments

dense jungle
flat krakenBOT
#

Description

Fixes #2097 and standardizes type comments to always have 1 space after the # and 1 space after the :

As per the issue, the functions is_type_comment() and contains_pragma_comment() have been modified to return true even with any extra spacing. Type comments without non-breaking spaces are now stripped of any extra spaces as well.

Checklist - did you ...

  • [x] Add a CHANGELOG entry if necessary?
  • [x] Add / update tests if necessary?
  • [ ] Add...
tired shard
#

This wouldn't work if it is something like type : ignore

#

probably worth using regex

frigid grotto
#

ah i thought it was required to be type:

tired shard
#

NOot sure

errant barn
#

as long as we're fixing the comments, I think #\s*type\s*:\s*whatever is fine in my opinion, but worth it to check especially from Jelle

frigid grotto
#

ok ngl when i wrote that i completely forgot regex existed

#

can change it to use it and make it a lot cleaner

tired shard
#

#\s*type\s*:\s*(.*) and then rewrite it using the group

frigid grotto
#

yup

errant barn
#

let's discuss details in the issue

flat krakenBOT
#

To Reproduce

Given input:

class ThisIsTrulyUnreasonablyExtremelyLongClassName:
    pass


def frobnicate() -> "ThisIsTrulyUnreasonablyExtremelyLongClassName | list[ThisIsTrulyUnreasonablyExtremelyLongClassName]":
    pass

Black does not split the long type hint of the function return type

Even if I explicitly attempt to split the string:

def frobnicate() -> "ThisIsTrulyUnreasonablyExtremelyLongClassName | " \
                    "list[ThisIsTrul...
dim haven
#

This turned out hard to read after some working sessions.. I just removed the tool that I wrote which formats first with black and afterwards it makes tabs of size 2, now I'm just using black hahaha

fringe coral
#

Is there a list of which Black version is good for some specific Python version? I'm getting an error with black 21.12b0 and Pyhton 3.8

Traceback (most recent call last):
  File "/opt/miniconda3/envs/<env>/bin/black", line 6, in <module>
    from black import patched_main
  File "/opt/miniconda3/envs/<env>/lib/python3.8/site-packages/black/__init__.py", line 49, in <module>
    from black.files import find_project_root, find_pyproject_toml, parse_pyproject_toml
  File "/opt/miniconda3/envs/<env>/lib/python3.8/site-packages/black/files.py", line 27, in <module>
    from black.handle_ipynb_magics import jupyter_dependencies_are_installed
  File "/opt/miniconda3/envs/<env>/lib/python3.8/site-packages/black/handle_ipynb_magics.py", line 15, in <module>
    from typing_extensions import TypeGuard
ImportError: cannot import name 'TypeGuard' from 'typing_extensions' (/opt/miniconda3/envs/<env>/lib/python3.8/site-packages/typing_extensions.py)
#

Simply by running black __init__.py on an empty init file

dense jungle
fringe coral
#

I see. So this is basically an issue with conda messing up. Thanks

dense jungle
#

yeah, we require typing-extensions 3.10.0.0 in setup.py, looks like you have an older version

flat krakenBOT
bright glacier
bright glacier
#

technically the ideal option would be to integrate blib2to3's grammar caching with black's cache mechanism but that'd be complicated as this cache attempt occurs on import

bright glacier
flat krakenBOT
flat krakenBOT
plain atlas
#

/pypi build

#

!pypi build