Git Product home page Git Product logo

Comments (6)

grantjenks avatar grantjenks commented on August 18, 2024 1

I'm 0.25 on this. Sometimes I like to see an additional set of parens for expressions in slices. Like:

            whitespace = orig_line[:(-len(line))]

from blue.

warsaw avatar warsaw commented on August 18, 2024 1

I think that's fine. Let's close this one as "won't fix".

from blue.

grantjenks avatar grantjenks commented on August 18, 2024

Having looked through a bunch of diffs in the last hour, I've actually come around to Black's formatting here. The added space doesn't hurt.

from blue.

warsaw avatar warsaw commented on August 18, 2024

I can live with it, but it goes against PEP 8, IMHO:

However, in a slice the colon acts like a binary operator, and should have equal amounts on either side (treating it as the operator with the lowest priority). In an extended slice, both colons must have the same amount of spacing applied. Exception: when a slice parameter is omitted, the space is omitted:

from blue.

MatthewScholefield avatar MatthewScholefield commented on August 18, 2024

Personally, I don't think it makes sense because this rule is inconsistent in that it causes spacing to change purely based on the type of expression (expressions are not treated uniformly).

Ie. Each of the following would be a consistent formatting rule:

  • foo[: bar_len] and foo[: len(bar)]
  • foo[:bar_len] and foo[:len(bar)].

But not how it does it right now which is:

  • foo[:bar_len] and foo[: len(bar)].

from blue.

grantjenks avatar grantjenks commented on August 18, 2024

Addressing my previous comment -- I realize now that the addition of parens is impossible given Black's constraints. Adding parens would modify the AST which Black forbids to prevent changing semantics.

@warsaw having read the PEP 8 section you quote, I don't see what part black violates here.

from blue.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.