-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[mccabe - too-complex] Add each match case as an edge in the graph #9667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This comment has been minimized.
This comment has been minimized.
|
1096f19
to
b1ba516
Compare
This comment has been minimized.
This comment has been minimized.
Cross posting #10542 (comment) here. IMO match in Python is basically an enhanced if statement. So checks should treat it similarly. AFAICT that was also your opinion on the ruff issue, unless I got that wrong. I.e. each match case should probably increase the complexity by one.
Astroid |
Some are asking for the possibility to configure it on the ruff side here : astral-sh/ruff#11421 (comment)
I'm thinking that they possibly want to make match case that are too complex without having to think about design too much (never saw a > 5 case match statement in pylint, probably because we use the visitor pattern). But at the same time pylint is generally very configurable so why not in this case ? What do you think @DanielNoord @jacobtylerwalls ? |
Arguably the configurability is also one its the downsides. Nevertheless good defaults go a long way. So why not. I do think though this should only apply to the |
Yeah I agree with both points. Slightly in favor of adding the option because at this point it's a little hard to rebrand pylint as an opinionated turn-key linter, even if we wanted that. And I strongly think that the default should be that each "case", count as an edge in the McCabe graph. |
I never know if the users requesting new settings have fully explored the existing ones. Can't we expect users to just adjust the max-branches setting? If we need better tooling to do that per module, we need better tooling to do that per module. |
I think their idea is to have |
I think we should keep checkers simple and easy to reason about until we can't. If you only update one setting and then find that your team can cheat by factoring code into or out of match case, that's a surprise. |
Let's vote: |
I lean towards no option. If we add one, I think it should only be for |
We decided against an option to permit to not count them. Refs pylint-dev#9667
b1ba516
to
d840cb9
Compare
too-complex
in match case, for discussion
Codecov Reportβ
All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9667 +/- ##
==========================================
- Coverage 95.90% 95.89% -0.01%
==========================================
Files 177 177
Lines 19368 19419 +51
==========================================
+ Hits 18574 18622 +48
- Misses 794 797 +3
π New features to boost your workflow:
|
This comment has been minimized.
This comment has been minimized.
We decided against an option to permit to not count them. Refs #9667
3da530b
to
7ddbd4b
Compare
I wonder if we should instead modify https://github.com/pycqa/mccabe directly so it handle match case or if we should simply drop the dependency and vendor it. It hasn't been upgraded since 2021. And it's hard to optimize performance if we don't understand what's in it (which I don't for the moment, but it's looking like adding handling for match in |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not an expert in the mccabe
code but this looks about right to me.
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Looked at the mccabe code for long enough to see that we're re-using a piece of code intended to generate dot graph, so whatever I did here it's going to be a small detail if we ever merge #10551 and want to optimize later |
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Jaap Roes <jaap.roes@gmail.com>
for more information, see https://pre-commit.ci
Type of Changes
Description
See astral-sh/ruff#11421 for initial reasoning behind this. I think we should modify the way we compute match case. But not sure if we should add a new visit method in pylint or add a
get_children
method for match case in astroid so we ends up not having to modify anything on the pylint side (and would benefit from it elsewhere too ?).