Remove total order check from equals not equals (doesn't make sense there; total order doesn't define eq or ne methods at all)

This commit is contained in:
Joe Farebrother
2025-07-11 15:12:59 +01:00
parent 083d258585
commit 843a6c8012
3 changed files with 9 additions and 17 deletions

View File

@@ -1,12 +0,0 @@
/** Helper definitions for reasoning about comparison methods. */
import python
import semmle.python.ApiGraphs
/** Holds if `cls` has the `functools.total_ordering` decorator. */
predicate totalOrdering(Class cls) {
API::moduleImport("functools")
.getMember("total_ordering")
.asSource()
.flowsTo(DataFlow::exprNode(cls.getADecorator()))
}

View File

@@ -12,7 +12,6 @@
*/
import python
import Comparisons
import semmle.python.dataflow.new.internal.DataFlowDispatch
import Classes.Equality
@@ -33,8 +32,6 @@ predicate missingEquality(Class cls, Function defined, string missing) {
}
from Class cls, Function defined, string missing
where
not totalOrdering(cls) and
missingEquality(cls, defined, missing)
where missingEquality(cls, defined, missing)
select cls, "This class implements $@, but does not implement " + missing + ".", defined,
defined.getName()

View File

@@ -14,7 +14,14 @@
import python
import semmle.python.dataflow.new.internal.DataFlowDispatch
import semmle.python.ApiGraphs
import Comparisons
/** Holds if `cls` has the `functools.total_ordering` decorator. */
predicate totalOrdering(Class cls) {
API::moduleImport("functools")
.getMember("total_ordering")
.asSource()
.flowsTo(DataFlow::exprNode(cls.getADecorator()))
}
predicate definesStrictOrdering(Class cls, Function meth) {
meth = cls.getMethod("__lt__")