
When an include is not surrounded by empty lines, its content is inlined on the same line as the adjacent content. That can lead to broken tags and other display issues. This PR fixes all such includes and introduces a validation step that forbids introducing the same problem again.
59 lines
1.4 KiB
Plaintext
59 lines
1.4 KiB
Plaintext
== Why is this an issue?
|
|
|
|
In some cases a comparison with operators ``++==++``, or ``++!=++`` will always return True or always return False. When this happens, the comparison and all its dependent code can simply be removed. This includes:
|
|
|
|
* comparing unrelated builtin types such as string and integer.
|
|
* comparing class instances which do not implement ``++__eq__++`` or ``++__ne__++`` to an object of a different type (builtin or from an unrelated class which also doesn't implement ``++__eq__++`` or ``++__ne__++``).
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,python]
|
|
----
|
|
foo = 1 == "1" # Noncompliant. Always False.
|
|
|
|
foo = 1 != "1" # Noncompliant. Always True.
|
|
|
|
class A:
|
|
pass
|
|
|
|
myvar = A() == 1 # Noncompliant. Always False.
|
|
myvar = A() != 1 # Noncompliant. Always True.
|
|
----
|
|
|
|
=== Compliant solution
|
|
|
|
[source,python]
|
|
----
|
|
foo = 1 == int("1")
|
|
|
|
foo = str(1) != "1"
|
|
|
|
class Eq:
|
|
def __eq__(self, other):
|
|
return True
|
|
|
|
myvar = Eq() == 1
|
|
myvar = 1 == Eq()
|
|
myvar = Eq() != 1 # Ok. "__ne__" calls "__eq__" by default
|
|
myvar = 1 != Eq()
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
* Remove this equality check between incompatible types X and Y; it will always return True/False
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::../comments-and-links.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|