org.sonar.l10n.py.rules.python.S3403.html Maven / Gradle / Ivy
This rule raises an issue when an identity comparison operator is used to compare objects of different types.
Why is this an issue?
Operators is
and is not
check if their operands point to the same instance, thus
they will always return respectively False
and True
when they are used to compare objects of different types.
Code examples
Noncompliant code example
a = 1
b = "1"
value = a is b # Noncompliant. Always False
value = a is not b # Noncompliant. Always True
Compliant solution
a = 1
b = 1
value = a is b
value = a is not b
Resources
Documentation
- Python documentation - Identity comparisons
© 2015 - 2024 Weber Informatics LLC | Privacy Policy