mccabe
mccabe copied to clipboard
[Proposal] Allow disabling "try-except" clauses evaluation.
When using third party services libraries, or even on your own code, you may find a scenario were a function may return several different types of exceptions each of them requiring a simple but different action to be taken.
Exhaustive Exception treatment on those cases leads to a high complexity result which is right, as per the complexity calculation strategy, but an undesired result.
def foo(bar):
try:
do_whatever(bar)
except TypeA:
do_something_related_to_TypeA()
except TypeB:
do_something_related_to_TypeB()
except TypeC:
do_something_related_to_TypeC()
except TypeD:
do_something_related_to_TypeD()
except TypeE:
do_something_related_to_TypeE()
except TypeF:
do_something_related_to_TypeF()
except TypeG:
do_something_related_to_TypeG()
except TypeH:
do_something_related_to_TypeH()
except TypeI:
do_something_related_to_TypeI()
except TypeJ:
do_something_related_to_TypeJ()
python -Bm mccabe deffoobar.py
1:0: 'foo' 12
It will be interesting being able to ignore exceptions branching to properly compute the complexity of the actual function logic without the burden of the exception treatment one.
I don't think allowing folks to choose what contributes to complexity globally is really something we want to introduce. We wouldn't be even considering this on a "per-block" basis so it would be a global option and I think that's going to actively thwart the reason people bother using McCabe