] > Re: [Python-projects] branches in function: do branches in sub-functions also count? (Logilab.org)

Email Re: [Python-projects] branches in function: do branches in sub-functions also count?

from
subject
Re: [Python-projects] branches in function: do branches in sub-functions also count?
date
2005/05/09 10:01
On Friday 06 May à 11:22, Pierre Hanser wrote:
> 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