Giter Club home page Giter Club logo

flake8-picky-parentheses's People

Contributors

apakottur avatar cyyc1 avatar prychantovskyi avatar robsdedude avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

flake8-picky-parentheses's Issues

PAR101 (only operators and comments are allowed)

Hi, thanks for writing this plugin! I really like how PAR101 can check unaligned closing parenthesis.

However, I found that this plugin complains about the following code:

def func123(*arg):
    print('hello world')
    return 1


ans1 = func123(
    1, 2, 3, 4, 5
) + 100  # this is Line 8

aa = [1, 2, 3, 4, 5, 6]

ans2 = aa[
    func123(1, 2, 3, 4, 5, 6, 7, 8, 9)
] + aa[0]  # this is Line 14

The message is:

test.py:8:1: PAR101: Only operators and comments are allowed after a closing bracket on a new line
test.py:14:1: PAR101: Only operators and comments are allowed after a closing bracket on a new line

I often need to write in such style (Line 8 and Line 14). Can you give this violation a different code so that I can ignore this check?

Thank you!

Test format strings

Make sure the redundant parens check also works as expected inside format strings.

E.g., f"foo{(bar)}"

Exempt concatenated string literals for `black --preview` compatibility

black --preview enforces parentheses for concatenated string literals within comma-separated expressions:

items = [
    "item",
    "item",
    (
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt"
        " ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation"
        " ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in"
        " reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur"
        " sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id"
        " est laborum."
    ),
    "item",
]

These extra parentheses make it much easier to catch bugs where you’re missing commas in a list of strings, but flake8-picky-parentheses flags them as redundant with PAR001. Consider exempting parens around a concatenated string literal followed by a comma.

the exceptions don't seem to recognise comprehensions and complains about parens added by black

I've been using this for a while, and really like it, but I've come across a couple of problems recently:

Here is a section of a unittest:

        self.assertEqual(
            set(
                (  # noqa: PAR001
                    item.isoformat()
                    if isinstance(item, datetime.datetime)
                    else item
                )
                for item in data
            ),
            set(res),
        )

Black inserted the parens here which have the # noqa tag round them for readability, and they definitely improve the readability.

I've had a similar problem with a dict comprehension, something like

            tag = "somevalue"
            res = MyDict(
                {
                    tag: MyDict(
                        {
                            k: (  # noqa: PAR001
                                v[0]
                                if isinstance(v, list) and len(v) == 1
                                else v
                            )
                            for k, v in otherdict.items()
                        }
                    )
                }
            )

Test type annotations

Make sure the redundant parens check also works as expected inside type annotations.

Test with and without from __future__ import annotations (check if it even makes a difference for the tokenizer/ast or not).

E.g., a: (Foo) = Foo()

Preliminary evaluation suggests it's working as expected already. Adding proper unit/integration tests are still a good idea.

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.