from
Sylvain Thénault <sylvain.thenault at logilab dot fr>
to
Pierre Hanser <hanser at club-internet dot fr>
subject
Re: [Python-projects] branches in function: do branches in
sub-functions also count?
date
On Friday 06 May à 11:22, Pierre Hanser wrote:2005/05/09 10:01
> hello
hi
> this morning, I tried to refactor some code to lower
> the number of branches in a function. I separated
> the body of that function in sub-functions. I was
> surprised that the number of branches didn't fall.
>
> could you explain how this branch number is counted please?
Hum, the rule is quite simple: each function/method has its own branch
counter which is basically increased on new blocks. For instance:
def function(arg): # branchs = 0
a = subfunction(arg)
for i in range(10):
a += i # branchs = 1
if not a:
print 'duh?' # branchs = 2
else:
print 'ok' # branchs = 3
return a
# => function has 3 branchs
So spliting a function into subfunctions should make fall its branch
counter... If you think you've hit a bug, please post a more detailed
example.
regards
--
Sylvain Thénault LOGILAB, Paris (France).
http://www.logilab.com http://www.logilab.fr http://www.logilab.org
_______________________________________________
Python-Projects mailing list
Python-Projects@lists.logilab.org
http://lists.logilab.org/mailman/listinfo/python-projects
