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

BUG: Python expression structures and nesting level of tokens/structures #141

Closed rakhimov closed 4 years ago

rakhimov commented 8 years ago

Python reutilizes keywords for list comprehension (for, if) and ternary operator (if, else). the current implementation of the nesting structure count, which depends on the nesting level of tokens, does not differentiate between expressions or statements for these keywords and keeps counting the nesting level.

Examples:

def foo(bar):
  return [x for x in bar if x == 42]

def foo(bar):
  return 42 if bar else -42

These examples will produce NS = 2 and 1, respectively, instead of 0.

terryyin commented 7 years ago

@rakhimov I have reverse-engineered the nested structure implementation with https://github.com/terryyin/lizard/compare/e4f7ff1889ee...63ceb48a3ea7.

Thanks for your great tests. I had a wonderful journey of test-driven development. Didn't re-implement it for Python though. I think for Python it's just the level of indentations.