The input method in Python 2 will read from standard input, evaluate and run the resulting string as python source code. This is similar, though in many ways worse, then using eval. On Python 2, use raw_input instead, input is safe in Python 3. Open
username = input("Wprowadź nazwę użytkownika: ")
- Exclude checks
The input method in Python 2 will read from standard input, evaluate and run the resulting string as python source code. This is similar, though in many ways worse, then using eval. On Python 2, use raw_input instead, input is safe in Python 3. Open
if step_enabled("user", args) and input(
"Czy chcesz stworzć nowego użytkownika-administratora? [y/n]"
- Exclude checks
Function install
has a Cognitive Complexity of 58 (exceeds 5 allowed). Consider refactoring. Open
def install(args):
if sys.platform == "linux" or 1 == 1:
if step_enabled("dependencies", args):
# install MongoDB and some other things if they're not installed
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Refactor this function to reduce its Cognitive Complexity from 59 to the 15 allowed. Open
def install(args):
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Correct one of the identical sub-expressions on both sides of operator "==". Open
if sys.platform == "linux" or 1 == 1:
- Read upRead up
- Exclude checks
Using the same value on either side of a binary operator is almost always a mistake. In the case of logical operators, it is either a copy/paste error and therefore a bug, or it is simply wasted code, and should be simplified. In the case of bitwise operators and most binary mathematical operators, having the same value on both sides of an operator yields predictable results, and should be simplified.
This rule ignores *
, +
, and =
.
Noncompliant Code Example
if a == a: # Noncompliant work() if a != a: # Noncompliant work() if a == b and a == b: # Noncompliant work() if a == b or a == b: # Noncompliant work() j = 5 / 5 # Noncompliant k = 5 - 5 # Noncompliant
Exceptions
The following are ignored:
- The expression
1 << 1
See
- CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
- CERT, MSC12-CPP. - Detect and remove code that has no effect
- {rule:python:S1656} - Implements a check on
=
.