Cyclomatic complexity is a quantitive measure of program (procedure) complexity.
You can measure it in pylint and fail functions that have complexity over maximal value.
I tried duck-ducking it but found some old answers, so here is how to enable it.
It is installed by default on recent pylint, you need to tweak pylintrc;
You need to add following plugin:
load-plugins=pylint.extensions.mccabe
Add max complexity to the Design section:
[DESIGN] max-complexity=10