Miserlou / JonesComplexity

Per-line complexity for Flake8
29 stars 4 forks source link

f'' strings commplexity #38

Open iAnanich opened 6 years ago

iAnanich commented 6 years ago

Simple f'for {url} error code {code} with message {msg} ' string (which is aprt of multi-line string) scores 20 complexity. Full context:

spider.logger.error(
    f'for {url} error code {code} with message {msg} '
    f'and the following session info:\n'
    f'{pprint.pformat(response.meta[spider.META_SESSION_INFO])}'
)

And plugin warns only about second line.

Is it OK?

sobolevn commented 6 years ago

I will check that, thanks for reporting.

What's your solution to this problem? How do you think it should be solved?

iAnanich commented 6 years ago

I don't know it works underhood, but I think that if it's possible to track how many lines such string holds, it would be great to compare average complexity per line with a maximum. Because if an average complexity is bigger than maximum then one or more lines are too complex.

iAnanich commented 6 years ago

The problem is that tree (here) understands example above like call of spider.logger.error method with JoinedStr entirely on the next line. And this JoinedStr remembers only lineno where it starts and it's values: Str and FormattedValue which has the same lineno as JoinedStr.