2024-09-03 12:13:36 +02:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
|
|
=== Code examples
|
|
|
|
|
|
|
|
==== Noncompliant code example
|
2021-06-02 20:44:38 +02:00
|
|
|
|
2024-09-03 12:13:36 +02:00
|
|
|
[source,python,diff-id=1,diff-type=noncompliant]
|
|
|
|
----
|
|
|
|
def foo():
|
|
|
|
a = True
|
|
|
|
if a: # Noncompliant: the condition is always true
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
return 2
|
|
|
|
----
|
2021-09-20 15:38:42 +02:00
|
|
|
|
|
|
|
|
2024-09-03 12:13:36 +02:00
|
|
|
==== Compliant solution
|
2021-09-20 15:38:42 +02:00
|
|
|
|
2024-09-03 12:13:36 +02:00
|
|
|
[source,python,diff-id=1,diff-type=compliant]
|
|
|
|
----
|
|
|
|
def foo():
|
|
|
|
a = bar()
|
|
|
|
if a:
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
return 2
|
|
|
|
----
|
2021-09-20 15:38:42 +02:00
|
|
|
|
2021-06-02 20:44:38 +02:00
|
|
|
|
2024-09-03 12:13:36 +02:00
|
|
|
== Resources
|
2023-06-22 10:38:01 +02:00
|
|
|
|
2024-09-03 12:13:36 +02:00
|
|
|
=== Documentation
|
|
|
|
|
|
|
|
* Python documentation - https://www.python.org/dev/peps/pep-0285/[PEP 285 - Adding a bool type]
|
|
|
|
* Python documentation - https://docs.python.org/3/library/stdtypes.html#truth-value-testing[Python documentation - Truth Value Testing]
|
|
|
|
|
|
|
|
include::../rule.adoc[]
|