robsdedude / flake8-picky-parentheses Goto Github PK
View Code? Open in Web Editor NEWflake8 plugin to check for redundant parentheses
Home Page: https://pypi.org/project/flake8-picky-parentheses/
License: Apache License 2.0
flake8 plugin to check for redundant parentheses
Home Page: https://pypi.org/project/flake8-picky-parentheses/
License: Apache License 2.0
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!
Make sure the redundant parens check also works as expected inside format strings.
E.g., f"foo{(bar)}"
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.
As far as I can tell from the change log, that should only be adding handling for the new except*
syntax https://peps.python.org/pep-0654/
So we know when new versions of dependencies (currently only major versions of flake8) are available.
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()
}
)
}
)
To reproduce, run:
pip install flake8-picky-parentheses
pip install -U flake8
pip check
Returns:
flake8-picky-parentheses 0.5.1 has requirement flake8~=3.7, but you have flake8 6.1.0.
I think that:
flake8-picky-parentheses/pyproject.toml
Line 10 in b35bb66
should actually be:
"flake8>=3.7",
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.