0

I am new to Python, my first programming language 2 days ago. I got the error "[mccabe] Cyclomatic complexity too high: 15 (threshold 15)" and I tried to fix it. If you could explain it and give me a command to solve it, I'd appreciate it. Otherwise, I have an idea to solve this problem. I want to append a block to a block at the original command line to solve that problem. The problem is I don't know its code and does it work? (I have marked # on the link I shared). Once again I appreciate it and thank you very much.

martineau
  • 119,623
  • 25
  • 170
  • 301
  • link (repl.it): https://repl.it/@KN5/test1 – LearnPython4purposes Aug 24 '20 at 15:17
  • Coincidentally, [this answer](https://stackoverflow.com/questions/55938910/what-does-a-mccabe-cyclomatic-complexity-too-high-error-mean/55939023) of mine just got upvoted yesterday. This is a weak duplicate of that. You have too deeply nested of `if`s. If you think about how you have things set up, as you add more dialog, your code is going to get more and more deeply nested, and that isn't sustainable. You'll need to restructure your code to "flatten" it out, but doing so would require quite a major refactor, which is too broad for here. – Carcigenicate Aug 24 '20 at 15:21
  • It's not an error. – hobbs Aug 24 '20 at 15:22

1 Answers1

2

It is not an error, merely a warning. Some editors/linters checks for code complexity as complex code is hard to maintain. You just got a warning that your code seems to be too complex based on certain rules. You can safely ignore it (in the sense that your code will run normally as these checks are not done during runtime).

However, if you get such warning, I recommend to take a look on the function and think if it would make sense to rewrite the code (and potentially split it into several functions).

It is also possible to disable such warnings (depending on the linter/editor you are using). For example, look here . (I would advise against disabling the warning globally as too complex code is not a good code style)

Take a look at this answer and this article if you are interested in more details.

IPSDSILVA
  • 1,667
  • 9
  • 27
Vladimír Kunc
  • 379
  • 1
  • 4