terryyin / lizard

A simple code complexity analyser without caring about the C/C++ header files or Java imports, supports most of the popular languages.
Other
1.85k stars 250 forks source link

Wrong CCN of Python file #56

Closed ghost closed 9 years ago

ghost commented 9 years ago

Hi!

I stumbled upon a Python file at work for which lizard calculates a wrong CCN.

# code somewhat simplified
def method1(self):
    pass

class Class1(object):
    def method2(self):

        if True:
            pass
        if True:
            pass

        def method1(param):
            for x in (1,2):
                pass

        if True:
            pass

        if True:
            pass

        while True:
            if True:
                pass

            for x in (1,2):
                True

    def method3(self):
        if True:
            for x in (1,2):
                if True:
                    pass
                else:
                    pass
        if True:
            pass
        else:
            pass

    def method4(self):
        if True:
            pass

        if True:
            pass

        if True:
            if True
                pass

        if True:
            if True:
                pass

        if True:
            pass
        else:
            pass

def memoize(obj):
    obj.cache = {}

Lizard tells me that method1() ranges from line 1 to line 62 and has a CCN of 20. If I remove the last two lines (memoize()), it works as expected.

Bye, Robert

Btw: lizard is a great tool and I use it every day.

terryyin commented 9 years ago

@rschulze /Robert, thanks for the report. I will look at it within days.

terryyin commented 9 years ago

Hi @rschulze this code might be simplified a bit too much and missed the key part. I cannot reproduce the problem. Could you please supply more?

ghost commented 9 years ago

Hi @terryyin : The problem seemes to be solved after upgrading :-) Thanks for your help!