#black-formatter

1 messages Β· Page 25 of 1

flat krakenBOT
#

Describe the bug

When a Jupyter cell is a cell magic, despite the doc, sometimes the whole content is parsed and can throw an indentation error (even though it should be ignored). For example, the %%writefile magic should be able to contain arbitrary text regardless of indentation.

To Reproduce

For example, create a notebook notebook.ipynb containing the below code cell:

``...

flat krakenBOT
plain atlas
#

uhm

#

stable docs build is very out of date

bright glacier
#

rightttt

plain atlas
#

since it currently needs to be triggered manually

bright glacier
#

readthedocs still borks when we update the stable tag

plain atlas
#

there's an endpoint, someone just needs to write a script for it

bright glacier
bright glacier
plain atlas
#

ah, so someone could still write a script for it πŸ˜›

bright glacier
#

I'm not in a happy mood fwiw

#

(unrelated to this, don't worry - just want to caution if I am a little short)

plain atlas
bright glacier
#

D'oh that's unfortunate :(

plain atlas
#

huh

#

are comments on issues not relayed here

#

darn

#

Pipenv has updated a bunch of unrelated packages unfortuantely when updating the lock
lol

#

why yes, of course it would

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];
      ...
plain atlas
#

huh that is somewhat annoying since its a comment in the pr

bright glacier
#
import random

n = random.randint(1, 10)

match n%2:
    case 0:
        print("even")
    case 1:
        print("odd")

this is valid code?

plain atlas
#

!e ```py
import random

n = random.randint(1, 10)

match n%2:
case 0:
print("even")
case 1:
print("odd")

late dewBOT
#

@plain atlas :white_check_mark: Your eval job has completed with return code 0.

even
plain atlas
#

yes

#

figured it would be something like that lmao

plain atlas
#

lol neat

#

that was nice and fast

bright glacier
#

I wonder if they're going to post a comment or not :p

plain atlas
#

srsly tho I respect when ppl close like that

bright glacier
#

Yeah, just unusual to close without a comment

plain atlas
#

true

#

but like, rather than argue about it lmao

bright glacier
#

Eh, we don't get too much arguing in the tracker

plain atlas
#

they commented

plain atlas
dense jungle
#

except for the tabs people πŸ˜„

plain atlas
#

I've seen too many github issues with argues

#

ofc most of the github issues I look at are ones from searches for issues or ones ppl mention to me that I should take a look so my set is very skewed

silent apex
#

it's the best one I've seen

plain atlas
#

or funny issues like that which ppl mention around me smh ^

silent apex
#

They're like, "hey, you say you're listening to the community, so just give us tabs"
black: we also say:

Black is a PEP 8 compliant opinionated formatter with its own style.
(I mean, I know it says "Tabs should be used solely to remain consistent with code that is already indented with tabs," but still, black's point is to be consistent)

plain atlas
#

No, not rejected. Give me one good reason why you won't add tab support. Don't say "no eww tabs are gross and everyone who uses black automatically has to hate tabs"

The response was this lol

Our general principle is to avoid options that affect formatting, so that Black-formatted style is always consistent. We have given in and added a few formatting options, but we're unlikely to add more.

Jelle never mentioned tabs or anything lmfao

bright glacier
#

It's honestly these sort of things that make me consider quitting the project (or OSS in general) - not so the much arguments (I knew what I was signing up for, for the most part) but more the constant decisions on whether to uphold the project's ethos or give into user demands is rather tiring -- hence why I let others do it for me (thanks @dense jungle!)

plain atlas
#

uphold the project's ethos
I have a solution for you, never have them in the first place /s
we don't need ethics where we're going!

dense jungle
#

I love making decisions, it's great

bright glacier
#

I'm both conflict-averse and indecisive.. it's not a good duo trust me.

plain atlas
#

hey same

plain atlas
dense jungle
#

I'm pretty conflict averse too, if I have a mild conflict at work I tend to feel bad all day

silent apex
#

Saaame. But I'm usually fine since when I get an idea in my head for a project of mine (eg. yeeting truthiness as a concept), I will not let it go.

bright glacier
plain atlas
#

when I get an idea in my head for a project of mine....I will not let it go
Yeah uh

#

yeah mhm that's defintely what I do

#

no feature creep or anything yep mhm

#

when I get an idea for something while working on something I'll add it. I try to write all of my stuff future proofed for stuff I'm thinking of adding even if I never intend to add it.

#

I added yaml configuration support because I was like, why not???

#

and we are offtopic

#

Thankfully, there's one thing I never need to think about when writing my code, and that's the formatting. Black takes care of that for me, leaving me to focus on what matters.

bright glacier
#

and now diff-shades has native zip file support (for read operations only though)

plain atlas
silent apex
#

^^^ I absolutely hate thinking about consistent formatting in my code. I hate having to go back and divide up stuff into multiple lines or whatever, and black makes it so easy, so thank you

#

y'all deserve some more love 🀍

plain atlas
#

Well, spacing and stuff need to be done yourself, nothing good can come out of something choosing line grouping automatically

silent apex
#

well I mean like when I have function arguments spanning 200 characters

plain atlas
#

true

#

btw thoughts on psf/black#2623

toxic stormBOT
dense jungle
#

the longer it goes without anybody reproing it, the more I'm convinced the OP was confused

plain atlas
#

(i commented on it, my thoughts are there)

dense jungle
plain atlas
#

I feel like this happened in a ci workflow

#

or something

#

perhaps pip install black --no-deps was used (idfk why)

dense jungle
#

I'm sure there's many ways to mess up python package installation

plain atlas
#

yeah

flat krakenBOT
#

Description

See https://github.com/psf/black/issues/2627 , a non-Python cell magic such as %%writeline can legitimately contain "incorrect" indentation, however this causes tokenize-rt to return an error. To avoid this, validate_cell should early detect cell magics (just like it detects TransformerManager transformations).

Test added too, in the shape of a "badly indented" %%writefile within test_non_python_magics.

Checklist - did you ...

  • [X] Add a CH...
flat krakenBOT
#

Thanks @danielsparing for this PR!

I'm not a black maintainer, but I did make the Jupyter PR, so am leaving a couple of comments:

1 - does this mean that lines

https://github.com/psf/black/blob/9a73bb86db59de1e12426fec81dcdb7f3bb9be7b/src/black/handle_ipynb_magics.py#L233-L234

can be removed?

  1. Perhaps this should be done the other way round? I.e. rather than checking if the magic name is in a blocklist, and skipping the cell if that's the case, black should check if the m...
mint barn
#

how can i make black ignore lists and tuples

errant barn
#

You can't, because it's not an option we're willing to give users! We like it consistent πŸ‘πŸΏ

mint barn
#

that sucks

#

welp back to not using black πŸšΆβ€β™‚οΈ

plain atlas
mint barn
#

keeps messing with my large lists and tuples

plain atlas
#

there's one option that may be affect your diff

mint barn
#

makes them look like ass

plain atlas
#

iirc its --skip-magic-trailing-comma

mint barn
errant barn
#

if you want to collapse small lists that is

#

collapses small lists to one line again

#

and function declarations, calls, tuples etc.

plain atlas
# mint barn what does that do

its what it doesn't do πŸ˜›
tldr if something has a trailing comma black will expand it no matter the length
this flag turns off that check

#

also hi felix i haven't talked to you in a while

mint barn
#

this looks good, why can't black make my lists look like this and instead it makes one large shit that adds a ton of lines for nothing

plain atlas
#

because that's not an option that black provides

mint barn
#

πŸ˜”

errant barn
plain atlas
#

also IMO that only looks good because of the lengths of every param being the same

errant barn
mint barn
#

ig.. but still looks a lot better than what black does to it imo

errant barn
#

but if you're not writing a matrix of values, I'd argue it is formatted poorly

errant barn
#

i.e. a 2-d list

plain atlas
mint barn
#

oh

mint barn
plain atlas
mint barn
#

i use it to check if at least one of the user's role matches one of the id from that tuple

plain atlas
#

but that should probably be in a datafile anyways πŸ˜›

errant barn
#

then I'd say you're doing it wrong πŸ˜„ hear me out: if you want to remove something from the list, do you fix up the lines to be the same length every time?

plain atlas
#

why do i have so many this emojis lmao

mint barn
#

and in fact yeah that's what i do πŸ˜‚

errant barn
#

:D oh no

errant barn
#

oh no

plain atlas
#

oh no

#

πŸ˜”

#

a user is adopting black, but at what cost...

#

at what cost.....

errant barn
#

that's the secret configuration option :D

#

the "I want to use black but then again I don't"

mint barn
#

it worked :D

errant barn
#

fair enough, but please don't πŸ˜†

plain atlas
lament crow
#

or yapf

plain atlas
#

say, since 21.11b0 is messed up, could someone yank it from pypi?

#

it shouldn't cause any problems, since ppl can still use it

#

but it tells clients not to, if they can

flat krakenBOT
flat krakenBOT
plain atlas
# toxic storm

lmfao wowwwww there's been a bug with @toxic storm for so long here

tired shard
#

GitHub link?

plain atlas
#

yeah

glacial drum
#

it seems fine to me

tired shard
#

GitHub hyperlink is to pydis org

plain atlas
glacial drum
#

Ahh, more of an oversight really. The feature only ever used to work for pydis github mentions

plain atlas
#

yeah

glacial drum
#

when we extended it to other repos, we didn't update that link

plain atlas
#

eh, close enough

#

its an fstring which adds it

glacial drum
#

Should be fairly easy to change that url to the org mentioned

plain atlas
#

tbh i'd just remove it

#

its slightly more complex than that

bright glacier
#

I can reproduce the regex issue @dense jungle

#

seems like if you build your own version of regex via setup.py install it breaks something

dense jungle
bright glacier
#

actually even building your own wheel breaks it somehow ...

dense jungle
#

not for me on macos

plain atlas
bright glacier
#

how is this relevant?

plain atlas
#

theory: it builds correctly when the version matches the current date

#

for some weird internal reason

bright glacier
#

it's setuptools, I doubt it'd be that broken

plain atlas
#

!pip regex

late dewBOT
dense jungle
#

yeah and their setup.py isn't doing anything crazy either

late dewBOT
#

setup.py line 8

SRC_BASE = 'regex_%i' % MAJOR```
dense jungle
#

it uses different directories for Python 2 and 3

bright glacier
#

the very old string C-style interpolation :)

dense jungle
#

but both define Pattern I checked

#

wait @plain atlas you seriously hadn't seen % interpolation before?

plain atlas
#

yes lol

dense jungle
#

wow I'm oold

plain atlas
#

lol

bright glacier
#

What's weird is that Pattern exists even in the locally built version of regex 2021.4.4 but it's just that it's only in regex.regex.Pattern

#

wait a second

#

does the PyPI wheel contain different code than the source distribution ..

dense jungle
#

I wouldn't put it past them

plain atlas
#

hey totally random thing

#

found this very useful commit

#

its the change from 2021.4.4 to 2021.7.1

dense jungle
#

good find, but I think we're only using Pattern not Match

bright glacier
#
❯ diff regex-2021.4.4/regex_3/regex.py regex/regex.py -u --color
--- regex-2021.4.4/regex_3/regex.py    2021-11-19 12:21:46.303850129 -0500
+++ regex/regex.py    2021-04-04 17:00:14.000000000 -0400
@@ -723,6 +723,9 @@
 Match = type(_pat.match(''))
 del _pat
 
+# Make Pattern public for typing annotations.
+__all__.append("Pattern")
+
 # We'll define an alias for the 'compile' function so that the repr of a
 # pattern object is eval-able.
 Regex = compile
plain atlas
bright glacier
#

regex-2021.4.4/ is the tar.gz and regex/ is the wheel

dense jungle
#

well that explains it

bright glacier
#

Yup.

plain atlas
#

wait i don't get it

#

oh got it now nvm

#

the wheel includes those two lines but the source doesn't.....

dense jungle
#

could have sworn I tried with --no-binary yesterday but I guess I didn't

bright glacier
#

So regex's 2021.4.4 release contains multiple artifacts, right? The wheels contain the __all__ code needed to make Pattern public but the .tar.gz doesn't. Which btw is a big no-no in the world of packaging

plain atlas
#

yeah

#

i wonder if that's a bug in their workflows

dense jungle
#

they might just be doing it manually

bright glacier
#

I bet it was manually uploaded and someone messed up

plain atlas
#

and if its still a diff with the most recent code

plain atlas
#

or was, at that commit

dense jungle
#

so is the 2021.7 version good on both the sdist and the wheel? the bug report claimed that we need 2021.11

bright glacier
#

I'm checking right now

dense jungle
#

thanks!

bright glacier
#
❯ diff regex-2021.7.1/regex_3/regex.py regex/regex.py -u --color
plain atlas
bright glacier
#

seems like it

plain atlas
#

nope

#

.....

dense jungle
plain atlas
#

nope nope nope nope it is so bad

#

lol i think i am overreacting slightly but there is a fatal bug in that workflow

#

it runs tests but builds and pushes to pypi no matter if they pass or fail

plain atlas
dense jungle
plain atlas
#

oh, it builds them in the tests which it doesn't care about

late dewBOT
#

.github/workflows/main.yml lines 26 to 29

- name: Run test
  run: |
    python setup.py install
    python -m unittest -v regex.test_regex```
bright glacier
#

Why are they still using setup.py install.

plain atlas
#

idk

#

i'm submitting a fix for the not requiring tests right now

dense jungle
#

it's an old package. people don't tend to change things until they break

#

and setup.py install still works. kind of

bright glacier
#

Yeah, although I'd've expected them to do some cleanup since it seems like they just moved to GitHub and (GitHub Actions)

#

I assumed it was a new workflow

plain atlas
#

mrabarnett/mrab-regex#435

toxic stormBOT
plain atlas
#

mrabarnett/mrab-regex#445 okay I think I'll stop shaking in a few minutes whew

toxic stormBOT
late dewBOT
#

.github/workflows/main.yml lines 79 to 83

- name: Build source distribution & wheels
  run: |
    python setup.py sdist --formats=gztar
    python -m pip install -U cibuildwheel
    python -m cibuildwheel --output-dir wheelhouse```
dense jungle
#

good point

bright glacier
#

I thought cibuildwheel handles the Musl emulation for ya

plain atlas
#

i'll be back in a little bit, I'm still shaking from the tests....

dense jungle
#

also @bright glacier which wheel did you check? I wonder whether all wheels actually have the right code

plain atlas
#

idk why that stressed me out so much....

bright glacier
#

regex-2021.7.1-cp38-cp38-manylinux2014_x86_64.whl and regex-2021.4.4-cp38-cp38-manylinux2014_x86_64.whl

bright glacier
#

@dense jungle all wheels + the sdist from 2021.7.1 seem to be correct

#

I downloaded every single distribution for regex 2021.7.1 and checked the sdist manually and the wheels with this script:

import zipfile
from pathlib import Path

import rich

console = rich.get_console()

THIS_DIR = Path(__file__).parent

wheels = THIS_DIR.rglob("*.whl")
for whl in wheels:
    with zipfile.ZipFile(whl) as zfile:
        with zfile.open("regex/regex.py") as f:
            src = f.read().decode("utf-8")
            if '__all__.append("Pattern")' in src:
                console.print(f"{whl.name}: [bold green]all good")
            else:
                console.print(f"{whl.name}: [bold red]oh no ...")
plain atlas
#

the question is, is it worth bumping the min dep up again?

bright glacier
#

I do wonder how they get the sdist tho.. are they on a platform without a wheel or are they using --no-binary?

plain atlas
#

honestly uh

#

i can't continue to participate in this lol

bright glacier
#

ohhh they're on ARM

dense jungle
plain atlas
dense jungle
#

I might spend some time tonight trying to just get rid of the regex dep

#

would make life a lot easier

#

I don't really want to make another release just bumping the regex version

bright glacier
dense jungle
#

phew

bright glacier
#

Unfornately regex 2021.4.4 doesn't have a wheel for apple arm or linux musl so the sdist is more popular than ideal. OTOH it's a rather old regex at this point.

#

Man did that issue take forever to reproduce πŸ˜…

#

Should we at least yank 21.11b0 as it's virtually identical to the less broken 21.11b1?

dense jungle
#

sure

#

done

bright glacier
#

You're so fast πŸ‘€

flat krakenBOT
#

Description

In Python 3.10 the exception generated by creating a process pool on a Python build that doesn't support this is now NotImplementedError.

Here is the stack trace I received on Python 3.10 on Termux / Android 11:

  File "/data/data/com.termux/files/home/my-project/.venv/lib/python3.10/site-packages/black/__init__.py", line 624, in reformat_many
    executor = ProcessPoolExecutor(max_workers=worker_count)
  File "/data/data/com.termux/files/usr/lib/python3.10/c...
gaunt pecan
#

how do I make black not format a folder

flat krakenBOT
neon loom
gaunt pecan
abstract halo
#

any simple bank application projects?

errant barn
abstract halo
#

ahh okay, my bad, sorry :)

errant barn
#

all good mate, you can use Black in your application ;^)

heavy heron
#

That's an interesting problem, can I not use Black with Pipenv due to how Black specify versions?

plain atlas
#

you can, yes

heavy heron
#

Or at least not give it * as the version lock

plain atlas
#

but you have to allow pre-release versions

#

psf/black#517

toxic stormBOT
plain atlas
#

lol that's a funny number given what its about

plain atlas
#

lol oof

This will happen soon, you're right. We'll be releasing one last (planned) beta, and then an RC of a stable release.

Right. Surely before Christmas, likely not in November though.

#

three years later

errant barn
#

Never set deadlines.

plain atlas
#

well, that depends

red sedge
#

It is before Christmas though

errant barn
#

tru

#

before the Christmas of His second coming

plain atlas
cold citrus
#

Hello

red sedge
#

Hehe

plain atlas
# plain atlas <:this:470903994118832130>

First of all I want to make it clear that I'm not announcing a stable release or a date or really any concrete plans. We've been burned too many times by suggesting dates and the whatnot. What I do want to do is bring more transparency and let y'all know what the project has been up to since the last major update (which yikes is from 10 months ago!).
that first part is very wise

cold citrus
#

TΓΌrk yok mu ya

heavy heron
#

Hey @cold citrus, could you please speak english?

errant barn
#

:D

plain atlas
#

(4)

heavy heron
#

!rule 4

late dewBOT
#

4. Use English to the best of your ability. Be polite if someone speaks English imperfectly.

errant barn
#

Just because "respect staff and their commands?" πŸ˜„

heavy heron
#

I blame CTRL + K for being super ineffective

plain atlas
#

also akarys: y'all need to use black.

heavy heron
#

I guess rule 3 works for anything

#

I am using black!

red sedge
#

Commands seems a bit strong

cold citrus
#

Hey @Rabia, could you please speak english?evet akar

errant barn
#

Let the arbitrary power trips begin

plain atlas
#

actually its worded as > Respect staff members and listen to their instructions.

cold citrus
#

Yes akarys

heavy heron
#

excellent

red sedge
cold citrus
#

No graingert

bright glacier
plain atlas
#

lol

bright glacier
plain atlas
#

is that an extend or an overwrite of the already existing-- nvm

#

darned ninja edits

heavy heron
#
@dataclasses.dataclass
class AddressPacket:
    """Class representing a single interaction from the client to the server."""

    action: str  # "get", "set" or "delete"
    key: str
    value: Optional[str]


@dataclasses.dataclass
class ReturnPacket:
    """
    Class representing a value or ack from the server to the client.
    """

    status: str  # "ok", "error" or "not_found"
    value: Optional[str]```Black is happy to leave two different docstring styles. Is it because you consider the docstring as a logical piece of information and removing newlines could have side effects?
bright glacier
#

or

[tool.black]
extend-exclude = '''
/some_folder/
'''
plain atlas
#

Black is happy to leave two different docstring styles. Is it because you consider the docstring as a logical piece of information and removing newlines could have side effects?
not sure if that's part of flake8

#

pep8*

bright glacier
heavy heron
#

it is

bright glacier
#

TBF sphinx treats those two examples differently

heavy heron
#

alright, I see

#

does Black also sort imports?

plain atlas
heavy heron
#

I guess I can check it right now

plain atlas
#

!pip isort

late dewBOT
plain atlas
#

black doesn't touch sorting of imports

bright glacier
#

with --profile black obviously πŸ˜‰

heavy heron
#

I know isort does that

plain atlas
#

tldr if it did that would be half of the issue tracker

#

...maybe two-thirds

#

interestingly i don't think isort is pep8 compat

#

@heavy heron its actually in pep 257

#

and surprisingly

#
def complex(real=0.0, imag=0.0):
    """Form a complex number.

    Keyword arguments:
    real -- the real part (default 0.0)
    imag -- the imaginary part (default 0.0)
    """
    if imag == 0.0 and real == 0.0:
        return complex_zero
    ...
flat krakenBOT
#

I'm using Python 3.8.9 with conda environment and resulted in this problem

Traceback (most recent call last):
  File "/Users/mac/opt/anaconda3/bin/black", line 5, in 
    from black import patched_main
  File "/Users/mac/opt/anaconda3/lib/python3.8/site-packages/black/__init__.py", line 46, in 
    from black.concurrency import cancel, shutdown, maybe_install_uvloop
  File "/Users/mac/opt/anaconda3/lib/python3.8/site-packages/black/concurrency.py", line 6, in 
    from black.outpu...
flat krakenBOT
#

Describe the bug
black cannot format a file
To Reproduce

db_name = 'foo'
tb_name = 'foo'
trigger_info = {'foo':'bar'}
partition_check = (
        "use %s;show table extended like %s_%s partition (trigger_name = '%s',file_name='%s');"
        % (db_name, tb_name, trigger_info["TriggerName"], trigger_info["TriggerName"],trigger_info["ResultFileName"])
)

And run it with these arguments:

$ black file.py 

The resulting error is:

error: cannot form...

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];
      ...
plain atlas
#

? unread

delicate marsh
plain atlas
#

ah

flat krakenBOT
#

Hello and thanks for this library and the reactivity to support python 3.10 new syntaxes.

Describe the bug

While running with the latest version (gotten from git),basic match on a single pattern is correctly supported <3
But it seems that it does not support multiple match value.

I tried on a simple example after observing it on my real code:

To Reproduce

a = 11
b = 12

match a, b:
    case _, 5:
        print("a5")
    case 11, 12:
        prin...
red sedge
#

What are the limits of the black match parser?

#

Is it just because match is a soft keyword?

dense jungle
red sedge
dense jungle
red sedge
#

Because it's not a PEG parser it can't ever get them all - but which types can it not do?

#

At least I thought it couldn't

plain atlas
dense jungle
#

it's only a keyword in certain positions

red sedge
#

Yeah match = re.match(r"...") and if match: all work

dense jungle
#

this is also true for case; it was true for async and await for a few versions too

red sedge
#

But async and await aren't as soft as match?

dense jungle
#

they are full keywords now

#

I think in 3.5-3.8 or so they were soft

red sedge
#

async def was a hard keyword that promotes await into a hard keyword

plain atlas
red sedge
#

Nah 3.6 has them hard

#

I think

plain atlas
#

I thought it was 3.5.3

dense jungle
#

definitely not a change for a point release πŸ™‚

plain atlas
#

why was 3.5.3 so major anyhow?

red sedge
#

Sorry 3.7 made them hard

dense jungle
red sedge
#
Python 3.6.15 (default, Sep 10 2021, 00:26:58) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> await = 2
>>> 
KeyboardInterrupt
>>> 
$ python3.7
Python 3.7.12 (default, Sep 10 2021, 00:20:04) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> await = 2
  File "<stdin>", line 1
    await = 2
          ^
SyntaxError: invalid syntax
>>> 
plain atlas
#

ah, because I know there was a while when many libraries supported, 3.5.3 and up but not 3.5.2

plain atlas
red sedge
#

ok but I'm sure someone said match could not be done without a PEG parser

#

same for parenthesized with

plain atlas
#

what does peg stand for?

red sedge
#

In computer science, a parsing expression grammar (PEG), is a type of analytic formal grammar, i.e. it describes a formal language in terms of a set of rules for recognizing strings in the language. The formalism was introduced by Bryan Ford in 2004 and is closely related to the family of top-down parsing languages introduced in the early 1970s....

dense jungle
#

I dunno, it's a parsing technique

red sedge
#

The current Python grammar is an LL(1)-based grammar. A grammar can be said to be LL(1) if it can be parsed by an LL(1) parser, which in turn is defined as a top-down parser that parses the input from left to right, performing leftmost derivation of the sentence, with just one token of lookahead.

plain atlas
#

interesting

red sedge
#

But a PEG parser has infinite look ahead

#

Which means you can parse multiple alternatives of match and use the subsequent context to find out if it was a match block or just the Name match

plain atlas
#

given that there's the ast module, why can't black just use that to remake the code? (apologies if this is oversimplified, there's probably a clear reason why)

sour jay
#

Didn't Guido have to do a lot of work to get these soft keywords to work in the LL(1) parser?

uncut patio
#

@plain atlaswell, ast doesn't include comments

plain atlas
#

oh

#

that's okay, we never needed comments anyways /s

sour jay
#

Doesn't that module somewhat require running the code?

plain atlas
#

no, not that I know of, but I know black parses the ast anyways

#

that's what the safe mode does, which is on by default

cold citrus
#

Hello

plain atlas
#

hi

#

hello felix

cold citrus
#

hello arl

dense jungle
# plain atlas given that there's the ast module, why can't black just use that to remake the c...

you got some good answers today but in more detail: the AST is a representation of all the parts of the code that affect how it's run, but it throws away a lot of details that black may want to preserve. off the top of my head those include: comments, whitespace (we preserve newlines between blocks of code, for example), the trailing comma (for the magic trailing comma feature), raw vs. normal strings, string quote style (e.g. triple quotes, which we preserve), hex vs. normal ints, parentheses

#

we do also parse the AST, but that's only as an additional safety check to make sure our formatting changes don't change the AST (except for a few limited exceptions)

flat krakenBOT
plain atlas
#

never heard of them

red sedge
#

Seems like this should be a list of sponsors now

bright glacier
#

Haha, yea we get paid nothing for this work for the most part :p

ornate patio
#

not sure if this is the right channel to ask questions about black, but here goes

I have a block of commented code similar to this:

# fmt: off
# x = 3
# if x == 5:
    # print("hello")
    # print("goodbye")
# fmt: on
#

and when I run black I get this:

# fmt: off
# x = 3
# if x == 5:
# print("hello")
# print("goodbye")
# fmt: on
#

is that expected? I would think the fmt tags should leave it indented as is?

plain atlas
#

huh the fmt indicators don't apply to the comments

plain atlas
#

if there isn't one already

#

wait no

#

what's your black version

#

black --version

ornate patio
#

black, version 21.9b0

bright glacier
#

Pretty sure this is a known bug

ornate patio
#

i get the same behaviour with black, version 19.10b0

ornate patio
bright glacier
plain atlas
#

and commenting out the whitespace

ornate patio
#

yeah that works

plain atlas
#

(it also plays better with ide comment implementations)

ornate patio
#

so the actual use case is some internal tool that's using comments as tags

#

but yeah the indent inside the comment instead of outside is a good intermediate solution

bright glacier
#

This is total guesswork (from what I barely remember about the fmt: on/off implementation) but the AST leaf containing # fmt: on wouldn't be ignored, everything else contained is though. This is a problem as comments and whitespace is stored in the AST as prefix attributes on AST nodes and leaves, so since this is attached to the non-ignored # fmt: on leaf, the indentation normalization logic edits it.

plain atlas
#

questionable design choice

ornate patio
bright glacier
#

And fmt: on is its own leaf instead of being part of the prefix because that's literally how the fmt: on/off implementation works.

plain atlas
ornate patio
plain atlas
#

that's.... interesting and I have many questions

ornate patio
#

yeah honestly not a fan

plain atlas
#

yet I want to hear none of the answers

bright glacier
#

psf/black#1245 -- this one?

toxic stormBOT
plain atlas
bright glacier
# toxic storm

I almost fixed this issue matter of fact but there was one edge case I couldn't work around

plain atlas
#

could use an enum for deployment location, and then if the lines of code.

#

my consulting rate is $18/h I'll send you a bill /s

bright glacier
#

!rule 9

red sedge
#

Are you doing anything special for Friday?

dense jungle
#

Could a workaround be to start your line with # print instead of # print?

bright glacier
ornate patio
red sedge
dense jungle
#

ah black friday πŸ˜„

bright glacier
#

d'oh

errant barn
#

:D

#

we'll ship PRs with discounted review quality

dense jungle
#

@plain atlas might reduce their consulting rate

plain atlas
#

lmfao

plain atlas
#

jk all of my reviews are of Superior Quality

bright glacier
#

!eval

a = 11
b = 12

match a, b:
    case _, 5:
        print("a5")
    case 11, 12:
        print("default")
    case _:
        print("badass")
late dewBOT
#

@bright glacier :white_check_mark: Your eval job has completed with return code 0.

default
bright glacier
#

Alright this is valid code

plain atlas
#

I believe you were missing a space after eval and the first ``` I am behind

bright glacier
#

Yeah I was but I've thought it'd ignore that

plain atlas
#

nope, dpy doesn't care

bright glacier
#

ah, isidentical fixed this similar case:

value = (1, 2)

match value:
    case x, y:
        pass
plain atlas
#

what is isidentical? a lib?

bright glacier
#

a core dev

plain atlas
#

...

#

that makes more sense

bright glacier
#

anyway I fixed this issue with this sketchy patch:

diff --git a/src/blib2to3/Grammar.txt b/src/blib2to3/Grammar.txt
index c2a6254..92bd22c 100644
--- a/src/blib2to3/Grammar.txt
+++ b/src/blib2to3/Grammar.txt
@@ -238,7 +238,7 @@ yield_arg: 'from' test | testlist_star_expr
 # to reformat them.
 
 match_stmt: "match" subject_expr ':' NEWLINE INDENT case_block+ DEDENT
-subject_expr: namedexpr_test
+subject_expr: namedexpr_test [(',' namedexpr_test)*]
 
 # cases
 case_block: "case" patterns [guard] ':' suite

will test later -- this is probably dumb but I don't have time right now

plain atlas
#

why would we need a method that is basically is

bright glacier
#

?

plain atlas
#

isidentical

bright glacier
#

that was a bad joke imo

errant barn
#

you must be joking :D

plain atlas
#

thought you were first meaning isidentical(a, b) which is the same as a is b

plain atlas
bright glacier
#

@muted haven it's this person

errant barn
bright glacier
plain atlas
#

yeee I got that now lol

rain flower
#

Hi, just wondering if you all have any easy open issues? Would like to get familiar with the codebase πŸ˜„

mint barn
#

@obsidian sapphire@junior crystal@mint barn This channel isn't for running bot commands, that's what #bot-commands is for. This channel is for the discussion of an autoformatting tool called "black"

junior crystal
#

Oh woops sorry about that!

obsidian sapphire
#

Srry

muted haven
leaden dove
#

How can I ask black to format with single quotes

errant barn
#

-S skips the normalisation, but I don't think there's an option for switching the quote style

errant barn
glad pebble
#

How can i use Black (not racist) in android command line ?

errant barn
#

Can you use Python?

#

(I have no experience with android CMD)

plain atlas
#

and then black just makes them standard

#

ironically using a formatter has made my code format without a formatter very very shit

errant barn
#

I feel ya πŸ˜„ linters on the other hand.. they bullied me into writing code that I'd be surprised if it were modified by black, disregarding the quotes

plain atlas
#

I use both

#

my code has no chance of passing my linter before i run black

tacit skiff
#

challenge: make a algorithm program with \n

red sedge
# leaden dove How can I ask black to format with single quotes

there's this https://github.com/pre-commit/pre-commit-hooks/blob/38b88246ccc552bffaaf54259d064beeee434539/README.md#double-quote-string-fixer which you can run after black -S to change your high quality double quoted strings to use the incorrect/inferior/wrong quote style

GitHub

Some out-of-the-box hooks for pre-commit. Contribute to pre-commit/pre-commit-hooks development by creating an account on GitHub.

flat krakenBOT
plain atlas
#

@bright glacier an edge case above would have broken your next-pr-number script ^ πŸ˜›

plain atlas
#

huh that comment thing

bright glacier
plain atlas
#

i mean, you can't solve it

#

but the two above were within seconds of each other

#

race condition where someone makes a pr after the command is run, so the number now already exists.

bright glacier
#

Well yeah I thought that was obvious

#

I could add a (silly) disclaimer but I don't have room for it really

plain atlas
#

true

dense jungle
#

Maybe we should do a new release with the match fix and bump regex to make the ARM people happy

#

I won't have time for it today though

bright glacier
#

oh gosh I just realized diff-shades is eating 5x the size of the analysis file in RAM while loading it

#

when it's cached as a pickle there's no extra copies, but without caching it's real bad

#

I think I just saw a peak of 1GB of RAM usage (with a json file, not a zip as like with the previous comment) πŸ‘€

#

This file is ~100MB, genuinely what the heck

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];
      ...
stuck vapor
#

Sorry for the somewhat scant descriptions in the above, bit short on time, need to start by day job in a few minutes πŸ˜†

muted haven
#

E.g:

def something():
    match something:
        case t:
            pass

    match arg:
        case t:
            print(t)
        case z := u:
            print(a)

shows the line 2, but the actual error happen on the line 9 (and the match block it is bound to is in line 6).

errant barn
#

How would you feel about restricting the conversation in psf/black#517 to maintainers so that we can avoid the noise and just provide updates to the people that are following the issue?

toxic stormBOT
errant barn
#

I'm getting irrationally frustrated πŸ˜„

flat krakenBOT
dense jungle
errant barn
# dense jungle done

πŸ‘ŒπŸΏ surprisingly enough I don't have the privilege to comment either, but I trust you do and that's enough πŸ˜„

flat krakenBOT
#

This removes all but one usage of the regex dependency. Tricky bits included:

  • A bug in test_black.py where we were incorrectly using a character range. Fix also submitted separately in #2643.
  • tokenize.py was the original use case for regex (#1047). The important bit is that we rely on \w to match anything valid in an identifier, and re fails to match a few characters as part of identifiers. My solution is to instead match all characters except those we know to mean something e...
plain atlas
#

...than black, the OG of Python formatters
Has black really been around that long?

#

(location of snippet not super relevant)

dense jungle
plain atlas
#

lol a fork of black gave that in their readme

bright glacier
late dewBOT
#
No problem.

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

plain atlas
#

hey that migration to coveralls, I found an easy official way to do it for gha without causing everything to fail if coveralls is down

late dewBOT
bright glacier
#

@dense jungle , what's the difference between your regex reduction PR and the regex pattern bugfix PR? It seems like the former contains the latter.

bright glacier
#

it feels good to have so much tooling for black now

#

like I'm reviewing Jelle's PR and checking impact and performance is relatively easy :)

dense jungle
bright glacier
#

I'm going to approve your regex reduction PR -- what controversy are you expecting?

dense jungle
#

I mean the tokenize thing is kind of hacky and might break in some way I didn't think of πŸ™‚

bright glacier
#

yeah hopefully not

#

it didn't break anything on the 2 020 758 lines of code diff-shades ran over so that's encouraging but I suspect the potential bugs will surface in invalid code the most

#

certainly worth some more thought I suppose

dense jungle
#

it makes this work: ```(black) jelle@mbpt-root black % black --fast -c "xΒΏ = 3"
xΒΏ = 3

#

though I am not sure that will have any practical effect

bright glacier
#

yeah especially as our match support is very liberal already

bright glacier
#

It seems like the noregex PR is a bit faster than main somehow. It's probably noise but at least it doesn't make things slower AFAICT.

flat krakenBOT
jolly oriole
#

So with keyword arguments whenever I format my code,
Black adds spaces around the = when the argument is annotated but when there's no annotation black doesn't add a space around it.
Is this a feature or a flaw?

dense jungle
jolly oriole
#

Ohh, just wanted to confirm thanks.

red sedge
#

are parenthesized with handled at all in the formatter?

#

eg, I'd expect this :

import contextlib
import collections.abc


@contextlib.contextmanager
def foo() -> collections.abc.Generator[None, None, None]:
    yield None


@contextlib.contextmanager
def bar() -> collections.abc.Generator[None, None, None]:
    yield None


with (
    foo() as eggs,
    bar() as ham,
):
    pass
#

to remove the parentheses in the with statement:

with foo() as eggs, bar() as ham:
    pass
#

oh wait magic comma

#

ah it does this though:

with (foo() as eggs, bar() as ham):
    pass
#

those parenthesis are now redundant

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];
      ...
dense jungle
flat krakenBOT
plain atlas
#

now that I know that isidentical exists I will never forget

#

this is what I first thought richard was referring to...

def isidentical(a: Any, b: Any) -> bool:
  return a is b
errant barn
#

isidenticalexists is another level entirely

plain atlas
#

lol

plain atlas
#

...

#

i've legit never seen that order of webhooks

#

its always pull closed, x new commit(s)

flat krakenBOT
flat krakenBOT
flat krakenBOT
flat krakenBOT
slow ibex
#

black formats this

#

into this

plain atlas
#

!magic-trailing-comma

#

smh we need a tag for that

plain atlas
slow ibex
#

yea, i know

#

but formatting this is weird

#

tuples are not expanded

plain atlas
#

true

#

this is a set

#

yknow, I would check open and closed issues and make and issue if there isn't one already

slow ibex
#

set also shouldnt be expanded

plain atlas
#

ye

#

I think list is okay

#

well actually

slow ibex
#

tuples are not expanding because magic comma isnt magic, it is important part ((x) is not (x,))

plain atlas
#

!e print(type({'d'}))

late dewBOT
#

@plain atlas :white_check_mark: Your eval job has completed with return code 0.

<class 'set'>
plain atlas
#

so that's probably why sets don't expand, its not necessary there

slow ibex
#

oh

#

really

#

sorry sad

plain atlas
#

unless there a structure which can load into a set which does cause it, wouldn't be surprised

slow ibex
#

I will clean the messages

plain atlas
#

don't bother, please ^^

#

it'll make me look like I'm talking to myself

slow ibex
#

ok πŸ˜„

mint barn
#
+ python3 -m black main.ipynb
Skipping .ipynb files as Jupyter dependencies are not installed.
You can fix this by running ``pip install black[jupyter]``

$ cat requirements.txt | grep black
black
black[jupyter]

$ pip3 list | grep black
black             21.11b1  
```Was wondering why my `black[jupyter]` in my `requirements.txt` doesn't seem to install correctly. Installing with `pip install -r requirements.txt` vs `pip3 ...` makes no difference. Running `pip install black[jupyter]` manually does fix it though, but I'd like to avoid doing that.
plain atlas
#

jupyter is a install_extras

#

it doesn't actually install a package named black[juypter]

#

it installs.....

mint barn
#

Is there a way to specify to install it in the requirements.txt file?

plain atlas
#

black[juypter] should work

#

i uh

#

i can't tell you what it installs right now

mint barn
#

lmao it's true

plain atlas
#

okay aside from me spelling it wrong, its actually jupyter

#

anyway, it should actually install it even in your requirements.txt file

tribal thistle
#

Fuzzy matching on pip install when

plain atlas
#

eys

#

we ned that

#

it would save me from myself

#

@mint barn anyways, it should be working....

#

what is your pip version?

#

(pip -V)

mint barn
#

20.0.2 it's standard ubuntu 20.04 lts

#

mispell

plain atlas
#

#selfshame

bright glacier
#

jupyter

plain atlas
#

github is down nice

#

lolwat

mint barn
#

ah okay, it doesnt work if you have black and then black[jupyter]
sorry thanks for the help

flat krakenBOT
#

On current main:

In [16]: s='importA\n0;0^0#'

In [17]: mode=black.Mode(line_length=0)

In [18]: t=black.format_str(s, mode=mode)

In [19]: black.assert_stable(s, t, mode)
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
 in 
----> 1 black.assert_stable(s, t, mode)

~/py/black/src/black/__init__.py in assert_stable(src, dst, mode)
   1322             diff(dst, newdst, "fir...
dense jungle
#

the fuzzer found a real bug πŸ˜„

bright glacier
#

you pay attention to it?

#

I wish I had that determination to make use of it

dense jungle
#

well this was on my sketchy tokenizer change so I was worried it was real

dense jungle
#

I'm trying to think of ways to replace the recursive regex at https://github.com/psf/black/blob/main/src/black/trans.py#L985 so we can stop having regex as a dependency but so far all I can think of is manually writing a recursive descent parser (probably slow) and using libcst (which probably won't improve dependency hell)

late dewBOT
#

src/black/trans.py line 985

RE_FEXPR: Final = r"""```
tired shard
#

If the user cache DIR is not writable by the user wouldn't black fail?

slow ibex
#

accept only certain nesting depth, other code leave as is

#

deep nested f-strings are rare

elder tusk
flat krakenBOT
bright glacier
flat krakenBOT
sullen pendant
#

Any beginner friendly open source projects web based??

bright glacier
#

I spent some time and I now have a non-regex f-string scanner implementation that passes the test suite just fine. It's pretty sketchy but at least it should be possible to create something decent without regex.

#

If I can clean it up a bit more then I might submit it for potential inclusion

flat krakenBOT
dense jungle
#

you can make another PR and then we can actually get rid of regex πŸ˜„

plain atlas
elder tusk
flat krakenBOT
#

Just opening a draft for discussion! I'll need to double check some of the escaping stuff, but our life is made easier by the fact that backslashes aren't allowed in f-string expressions.

Here are some tests this passes. I omitted the "f" and leading / closing quotes because they shouldn't matter. Curious what a good place for these dedicated unit tests would be:

assert list(iter_fexpr_spans("""{var}""")) == [(0, 5)]
assert list(iter_fexpr_spans("""text {var} text""")) == [(5, 10)]
...
flat krakenBOT
#

All the time I'm seeing black get stuck, and it requires a manual restart.

Here is an example of what we see on the pipeline console:

`$ tox -e black

black create: /tmp/pachyderm/echelon-curators/.tox/black
black installdeps: black
black installed: black==21.11b1,click==8.0.3,mypy-extensions==0.4.3,pathspec==0.9.0,platformdirs==2.4.0,regex==2021.11.10,tomli==1.2.2,typing-extensions==4.0.0
black run-test-pre: PYTHONHASHSEED='1617221419'
black run-test: commands[0] | black --chec...

flat krakenBOT
#

Make the startup of black faster when formatting a single file by importing less modules and skipping loading of .gitignore.

With this patch the time to format one file went from a baseline of:
(min /max time from doing many runs on my machine)
0.29s -> 0.47s to 0.17s -> 0.32s

-- Note that this includes the time to format too, not just the startup time. Also, this depends a lot on the target machine (slower machines will probably have more to gain)... in my machine I...

flat krakenBOT
dense jungle
#

it occurred to me that a natural extension to your suggested change though would be to format the expression bits of f-strings

elder tusk
#

hmm, okay, i think that's still fine, since the PR won't crash on invalid f-strings; it just might not yield anything. and then at the end we'll still get a crash in --safe or whatever

#

yeah, formatting expression bits would be nice

bright glacier
#
❯ python scanner.py "{'{'}"
VALID INPUT

0 [] {
1 [0] '
2 [0] {
3 [0, 2] '
4 [0, 2] }
pop due to even
0.1
0.07 ("{'}", 2, 5)
FAIL
``` although fwiw my goal was to first match the regex's behaviour ... and it turns out the regex fails on this one too. The first line (one after the pop due to even log line) is my scanner implementation and the other is the regex one.
#

I wasn't happy with my implementation hence the "if I can clean it up" bit, I really didn't like the hacky asserts of the potential expression. I didn't think about checking strings with other styles of quotes though, nice catch!

#

Wait a second, does the transformer implementation expect open ranges or half open ranges? the implementation is fine, don't worry I got confused

flat krakenBOT
#

Description

The recent 2021.4 release of pyinstaller-hooks-contrib now contains a
built-in hook for platformdirs. Manually specifying the hidden import
arg should no longer be needed.

The latest release of pyinstaller-hooks-contrib is installed when installing
PyInstaller, so reverting #2466 is all that is needed.

Checklist - did you ...

  • [x] Add a CHANGELOG entry if necessary?
  • [x] Add / update tests if necessary?
  • [x] Add new / update outdated documentation?

I...

plain atlas
#

lmao black

#
- WEBHOOK = ''''''''''''''''''''''''''''''''''''''''''''''''
+ WEBHOOK = """""" """""" """""" """""" """""" """""" """""" """"""
```*this exists because i zoned out with my finger on `'`, then thought to run it through black*
dense jungle
plain atlas
#

lol

#

because safe is on, i kind of had to make it parsable

flat krakenBOT
bright glacier
#

FYI I am going to start community testing of the mypyc wheels soon. Please merge any major PRs soon so I don't have to constantly rebuild to keep the data up to date.

#

I'll try to review the lazy imports PR soon.

bright glacier
#

gosh dammit our tox setup is not compatible with my needs to test under cibuildwheel as part of the compiled wheel build ..

flat krakenBOT
neon loom
bright glacier
#

AFAIK no

#

The mypyc bit is not too painful but setting up a workflow to build and test across the various platforms that is painful

plain atlas
#

I sense an imbalance in the github actions force

hidden junco
#

how to i make my own help channel

#

for my Q

plain atlas
hidden junco
#

k thx

plain atlas
#

no problem!

plain atlas
neon loom
#

Then once we have that we can add other platforms. I'm down to help.

#

Maybe step 0 is documenting the manual process (sorry if you have)

plain atlas
neon loom
#

Then I'm willing to take a stab at a action from scratch to do it

neon loom
plain atlas
#

😳

#

yeah uh i'm not obsessed with ci at all

#

I could stop at any time!

neon loom
#

e.g. I can push to my ansible repo and if i don't need the change everywhere right away, I do it on 1 host to test, push and then it will automatically apply a few hours later

plain atlas
#

wow

neon loom
#

Love shit like that

plain atlas
#

rn i just have a lint/test workflow, nothing more complex than that yet

bright glacier
#

I got it all automated and working but I can't use tox as part of the testing step which is incredibly annoying

neon loom
#

tox is incredibly annoying - so this is good πŸ˜„

#

(tox is fine, it's good python has a psuedo standard)

plain atlas
#

i heard nox is nicer, and I think I'll be writing a config thing like nox uses for a project of my own too

neon loom
#

nox sorted died as I got into doing a lot of CI so I never started using it

plain atlas
#

!pip nox

late dewBOT
bright glacier
#

I prefer nox but honestly I don't even know what to do with pipenv

neon loom
#

Yeah, I never found pipenv to be a game changer like others did

#

Pretty much everything it did I needed I feel I could do with pip

plain atlas
#

honestly i feel like dropping pipenv.lock from the repo would solve a lot of problems

late dewBOT
#

.github/workflows/build.yaml lines 73 to 77

# So these are the environments we are targeting:
# - CPython 3.6 and higher (no PyPy)
# - 64-bit only
# - ARCH: amd64, x86_64, universal2, and arm64
# - OSes: Linux (no musl), Windows, and MacOS```
bright glacier
#

cibuildwheel makes it a lot less painful fwiw

#

there's also no support for ARM windows because who the heck is using that?

plain atlas
neon loom
#

Do we have to keep 3.6 in the new year for mypyc?

#

I just see 3.6 mentioned there

bright glacier
#

There's no good reason to keep 3.6 except for that it doesn't really cost us to keep it

plain atlas
bright glacier
#

except pip-compile doesn't have a proper resolver πŸ₯²

plain atlas
#

poetry does KEKW

bright glacier
#

You do realize we are scarred by pipenv, right?

plain atlas
#

slightly

#

I do tend to see a lot of pipenv sucks but no moves to get away from it here lol

neon loom
plain atlas
#

ah yeah, nosetest

neon loom
#

*team

plain atlas
plain atlas
neon loom
#

The pipenv support deprecation would need to be communicated and see how much noise we get. I could start an issue and see what uproar we get from people who need it

#

Could open an issue and see - but i don't think people pay enough attention

plain atlas
#

wouldn't pipenv deprecation only mess with contributors?

bright glacier
#

oh yeah because people do actually use Pipfile (not PIpfile.lock)

neon loom
#

Ya

plain atlas
#

I do think a minor step in the direction would be to remove pipfile.lock from the repo

silent apex
#

Why? Isn't a lockfile one of the greatest benefits of pipenv?

plain atlas
#

since.... it ensures the contributors and developers all have the same dependencies, whereas in a real-world use, the dependencies are all different

plain atlas
bright glacier
#

so anyway the main things I need to do from a mypyc perspective is 1) actually get the community to test my wheels, 2) integrate a build step into CI, and 3) document, document, and document

plain atlas
#

from an exploration of issues on the pipenv repo: ( pypa/pipenv#954 pypa/pipenv#598 )
The standard is to commit it for applications, for libraries, less so

Given that black is typically used as a third party tool in workflows and environments, in this case I would consider black a library: its not the only thing being installed to an environment.

This means that the contributor libraries are pinned to a very different verision than what could be installed.

In addition, take the recent versioning problem with regex. This should have been caught and found before release, by testing with the lowest supported versions of dependencies. With the pipfile.lock, all of the dependencies are the same for every contributor, and during the development cycle all dependencies are the same.

When installed from pypi, pip or the installation tool uses its own dependency resolver that matches the provided requirements--which may or may not necessarily match the versions in pipfile.lock

Given all of this information, I am a believer that pipfile.lock should not actually be commited to version control for black.
I also believe that the lowest supported dependencies should be used for testing, but that's a different argument

plain atlas
#

@neon loom@silent apex@bright glacier ^

bright glacier
#

why do people always think black is a library? like I get your argument but we don't even have an official API

#

from a packaging standpoint, sure we may package it like a library but that means less way than a fullblown library

plain atlas
#

for purposes of the above, it is IMO, but i agree it is not, yet

bright glacier
#

It'd be nice if pip had an upgrade strategy to install the oldest supported deps but unfortunately that feature is still in the planning phase

plain atlas
#

I could write one (partially)
I don't think it would work on the deps of the deps from how I'd do it lol

bright glacier
#

I mean if I had to make a solution up I'd use minideps

plain atlas
#

is that a package?

bright glacier
#

mindeps?

bright glacier
plain atlas
#

aw

bright glacier
#

not everything is packaged

#

including diff-shades.

plain atlas
#

I mean a thing on pypi

#

or wait

#

all of those are packaged...right?

bright glacier
#

what do you mean?

plain atlas
#

everything on pypi is packaged, right?

bright glacier
#

yeah?

plain atlas
#

cool just needed that clarification

#

so what is min[i]deps?

bright glacier
#

I don't know

#

it's a subtool of a larger tool by FFY00 that spits out a list of pinned requirements that are the oldest possible

#

not sure it uses a resolver and it doesn't support packages with spotty wheel coverage but it'd be a good start

plain atlas
#

I mean, its not a hard tool to write, depending on if it supports sub-deps or not

bright glacier
#

are you sure? because conflicts are bound to happen

plain atlas
#

if it supports sub-deps it would be harder

#

so like this is black's current dep tree

bright glacier
#

Yeah. Anyway I am getting incredibly annoyed (because of me being an irresponsible person) and tired so I need to go or I'm going to snap.

plain atlas
#

(pasted for those who want it)```py
black 21.11b1 The uncompromising code formatter.
β”œβ”€β”€ click >=7.1.2
β”‚ └── colorama *
β”œβ”€β”€ mypy-extensions >=0.4.3
β”œβ”€β”€ pathspec >=0.9.0,<1
β”œβ”€β”€ platformdirs >=2
β”œβ”€β”€ regex >=2021.4.4
β”œβ”€β”€ tomli >=0.2.6,<2.0.0
β”œβ”€β”€ typing-extensions >=3.10.0.0
└── typing-extensions !=3.10.0.1

bright glacier
plain atlas
#

ah right i don't have them installed in this environment 😬

bright glacier
#

there's the colorama, python2, and uvloop extras but they each only add one more dep

plain atlas
#

the jupyter (oh look i spelled it correctly) and d deps add a lot tho.....

bright glacier
#

yes, I'm going now.

plain atlas
#

yeah

#

gn, sleep well richard

bright glacier
#

I will not but oh well

slow ibex
#

is black compiled with mypyc?

tribal thistle
#

Not currently. Richard is trialing that, but that will still go through a bit of a public testing period

flat krakenBOT
#

Describe the bug

Attempt to format invalid match expression results in misleading parse error message.

To Reproduce

MRE:

x = 1

match x:
    case 3 | 4:
        print("3 or 4")
    case _:
        print("Not 3 or 4")

match x, x + 1:
    case 3, 4:
        print("3 and 4")

Format command:

black --target-version py310 example.py

The resulting error is:

error: cannot format example.py: Cannot parse: 3:6: match x:
O...
flat krakenBOT
mint barn
#

Hi - the stable tag on github still points to 21.11b0 which has been yanked on pypi - should it be updated to point to 21.11b1?

muted haven
#

This is a bit weird,

#

only happens when used with match or case πŸ€” probably some keyword shenanigans

late dewBOT
#

src/black/linegen.py lines 140 to 141

if child.type == token.NAME and child.value in keywords:  # type: ignore
    yield from self.line()```
flat krakenBOT
celest grail
bright glacier
# celest grail

is that a function definition? in that case you don't need the quote to define a parameter named file

celest grail
bright glacier
#

Well I more meant you don't need to quote file

plain atlas
dense jungle
plain atlas
#

yeah, although.... I'm tempted enough at this point to write a workflow for it

#

the gist is if stable tag edited, send api request to rebuild

bright glacier
late dewBOT
#
No problem.

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

lament crow
slow ibex
#
pip uninstall black && pip cache purge && pip install black -U --extra-index-url https://ichard26.github.io/black-mypyc-index/simple/ && black --version
```what am i doing wrong?
bright glacier
#

huh

bright glacier
slow ibex
bright glacier
#

right - I forgot that 3.10 isn't supported on windows

slow ibex
#

yes, im on 3.10

bright glacier
#

I think I can get 3.10 working for windows but the last time I tried the C compiler got very mad at me 😦

#

IIRC a dependency bump should fix it

#

I should definitely add better instructions though

slow ibex
#

black works correctly on 3.10
and im using mypyc for my project, it is also working correctly

bright glacier
#

The last time I tried I'd get compiler errors on mypyc's C shared library w/ mypy==0.910 on Windows Python 3.10

#

Alright I'm rebuilding the wheels this time with 3.10 enabled for Windows - hopefully this passes 🀞

#

Estimated time remaining is roughly 40 minutes (for both CI and me updating the index).

slow ibex
#

why it is so long? i think, mypyc can build it in about one minute

bright glacier
#

really?

#

to be fair I am using an interpreted copy of mypyc as their release schedule is really bad and I need some of the bugfixes available only in the master branch but it still takes a while

late dewBOT
bright glacier
#

dawn you aren't on Windows using CPython 3.10 right?

slow ibex
#

win10/64 + cpy3.10/64

#

yes

bright glacier
#

I was asking dawn the moderator not you denball πŸ˜„

slow ibex
#

sry πŸ˜„
english is not my native language

bright glacier
#

Can you try again @slow ibex ? I just pushed the 3.10 wheel for windows

slow ibex
bright glacier
#

that's good

slow ibex
#

and it is working!

#

thank you

bright glacier
#

Don't forget to fill out that issue form once you feel ready so I can keep track but thank you!

silent apex
#

or WSL

#

I don't mind installing any version

bright glacier
#

It doesn't matter anynow, I recently added 3.10 support - just please don't be using an ARM cpu or a 32-bit OS :p

silent apex
#

Nope, just a regular old intel 64-bit thing

bright glacier
#

I could theoretically support 32-bit but that would double the workload on CI and testing requirements for relatively little gain IMO given 64-bit OSes are wayy more popular.

dense jungle
#

at Quora we ran 32-bit Python until just a few years ago and it was a major pain because it got really hard to build packages. I don't want to go back to that

#

it did decrease memory usage though

bright glacier
#

did you have to build pytorch or tensorflow on 32-bit? I sure hope not

dense jungle
#

no fortunately not

#
GitHub

This removes all but one usage of the regex dependency. Tricky bits included:

A bug in test_black.py where we were incorrectly using a character range. Fix also submitted separately in #2643.
toke...

GitHub

Fixes #2648.
Haven't figured out how to test this yet.

bright glacier
#

I won't have time to check mypyc compatibility but I doubt they'd cause issues. I say go for it if the PRs are good themselves.

#

I am still a bit nervous about the hacky tokenizer change but I guess we can learn whether it's too hacky the hard way

flat krakenBOT
plain atlas
elder tusk
flat krakenBOT
dense jungle
#

we no longer need regex πŸ˜„

#

I can prepare a PR later today to nix it

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];
      ...
bright glacier
#

jeez our timing haha

muted haven
#

How does black's grammar selection work? For example if you return 3 grammars (as [3.9, 3.8, 3.10]) and if it successfully gets parsed with 3.9 grammar, would it try the 3.8 or 3.10?

dense jungle
muted haven
#

Cool! The reason I am asking is that, 3.10 grammar might be probably much slower than the others since we do a lot of pre-calculation on every match/case token (even if the code uses any of these as regular names without pattern matching).

dense jungle
#

So if we always return the 3.10 grammar first, we'd use it to parse most code

muted haven
#

So if we put this into the first row, parsing regular code will become slower if they use re.match() etc

bright glacier
#

The order comes from how black.parsing.get_grammers's return statements are layed out

muted haven
#

just a FYI about the consideration on enabling this by default.

dense jungle
#

interesting, do you know how big the slowdown would be?

muted haven
#

it depends on the program's size

#

we copy() the whole parser stack on each match occurence

#

and that really takes a lot of time

plain atlas
bright glacier
#

That's probably not happening imo.

muted haven
#

I think it should be possible to optimize this a lot (by just copying the last top-level statement, instead of the whole stack) but I still didn't get around looking at it

dense jungle
bright glacier
#

We do actually use one grammar file but we have to keep multiple different instances of it with various features enabled / disabled at the runtime level.

muted haven
# muted haven Cool! The reason I am asking is that, `3.10` grammar might be probably much slow...

Another optimization idea would be specializing the current code for match/case. I initially tried to aim the whole backtracking problem, it got landed black as is. But I think it might also just make sense to implement a hacky solution for match/case where we just check the next few tokens (at best we can locate it in 1 token) manually without the proxy/recorder infrastructure. That would nearly close the speed gap.

#

But I think it is easier for now to have 3.10 at the last, if you plan to enable it by default at this time.

mental current
#

Hi

#

I have a task in my work.. we have a application mobil built with react native and flask as backend... Currently the application mobile is authenticating with Aws cognito service from backend. But my team determinated that this implementation is wrong. They want use AWS lambda like microservice that it can authenticate the user with diferentes providers of authentication such auth0 or cognito. They want have this flexibility when will be necessary. Finally the team too want social login. I have investigated other service such AWS ALB and AWS Api gateway these are others alternatives. I want read us about your opinions. how would you solve this problem? what are your tips?

bright glacier
#

This seems like the wrong channel to ask in :) #web-development seems like a better fit IMO.

flat krakenBOT
elder tusk
#

we'd probably get fewer lost strangers if the "open-source projects" section in discord went below "topical chat/help"

bright glacier
#

I CCed ambv since he's the main person who knows the magic trailing comma implementation (and the many many pitfalls involved) well

#

as evident he's quite busy 😦

errant barn
#

I find it humorous that fixing that problem mostly involves deleting a bunch of lines πŸ˜„

bright glacier
#

@dense jungle what do you think of merging psf/black#2472?

toxic stormBOT
bright glacier
dense jungle
bright glacier
#

Sounds good!

#

oh lol this PR is gonna break primer as it causes pyanalyze to be reformatted

#

wait that's a quora project :p

dense jungle
#

the project, not the formatting change it needs to make

bright glacier
#

Oh haha

plain atlas
#

@bright glacier how did you make this comment??

#

I tried to make a drop down for a comment with colorized formatting within and i couldn't do it

bright glacier
#

<details>

```

```

</details>

#

the blank lines are important

plain atlas
#

ahhhhhhh

#

that's why

#

...

#

thanks....

bright glacier
#

if you want to name the dropdown you can use the <summary> inline tag

plain atlas
#
<details>
<summary>
thanks ichard
</summary>

\`\`\`py
import python
\`\`\`

</details>
#

i legit tried for 15 minutes once to get the markdown parsing within the block

#

turns out i just needed a new line

bright glacier
plain atlas
#

yummy commits

dense jungle
#

why run local tests when you have CI

plain atlas
#

both are good

bright glacier
#

it's faster imo

plain atlas
#

IMHO a commit should always always always be atomic

bright glacier
#

I don't like context switching between my terminal and the web.

plain atlas
#

i want a project that runs with every single commit

dense jungle
plain atlas
#

it may not do everything that it should, but it should run

bright glacier
#

Other than mypyc what should we focus on next? I'm currently trying to deal with the PR backlog pushing 'em forward with diff-shades insight. I suppose I could pick up my goal of moving off pipenv to something friendlier.

plain atlas
#

I suppose I could pick up my goal of moving off pipenv to something friendlier.
pleasepleasepleaseplease

bright glacier
dense jungle
#

Yeah we need to make a call on those PRs that change formatting

#

I think we should move forward with the math people who want x**y to be unspaced

bright glacier
#

It's roughly 10 ten times as disruptive as that spacing consistency PR I just merged in terms of diff size. I linked the diff-shades report on it -- note it's not perfect as I didn't update my base data after I merged that blank line PR.

dense jungle
bright glacier
plain atlas
#

ternaries?

dense jungle
dense jungle
plain atlas
dense jungle
#

this is the only ternary operator in many languages so it's often just called "the ternary operator"

bright glacier