mirror of
https://github.com/github/codeql.git
synced 2026-04-28 10:15:14 +02:00
Python: Autoformat all .ql files.
This commit is contained in:
@@ -15,7 +15,9 @@ import semmle.python.SelfAttribute
|
||||
import Equality
|
||||
|
||||
predicate class_stores_to_attribute(ClassObject cls, SelfAttributeStore store, string name) {
|
||||
exists(FunctionObject f | f = cls.declaredAttribute(_) and store.getScope() = f.getFunction() and store.getName() = name) and
|
||||
exists(FunctionObject f |
|
||||
f = cls.declaredAttribute(_) and store.getScope() = f.getFunction() and store.getName() = name
|
||||
) and
|
||||
/* Exclude classes used as metaclasses */
|
||||
not cls.getASuperType() = theTypeType()
|
||||
}
|
||||
@@ -30,23 +32,26 @@ predicate should_override_eq(ClassObject cls, Object base_eq) {
|
||||
)
|
||||
}
|
||||
|
||||
/** Does the non-overridden __eq__ method access the attribute,
|
||||
/**
|
||||
* Does the non-overridden __eq__ method access the attribute,
|
||||
* which implies that the __eq__ method does not need to be overridden.
|
||||
*/
|
||||
predicate superclassEqExpectsAttribute(ClassObject cls, PyFunctionObject base_eq, string attrname) {
|
||||
not cls.declaresAttribute("__eq__") and
|
||||
exists(ClassObject sup | sup = cls.getABaseType() and sup.declaredAttribute("__eq__") = base_eq |
|
||||
exists(SelfAttributeRead store |
|
||||
store.getName() = attrname |
|
||||
exists(SelfAttributeRead store | store.getName() = attrname |
|
||||
store.getScope() = base_eq.getFunction()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
from ClassObject cls, SelfAttributeStore store, Object base_eq
|
||||
where class_stores_to_attribute(cls, store, _) and should_override_eq(cls, base_eq) and
|
||||
/* Don't report overridden unittest.TestCase. -- TestCase overrides __eq__, but subclasses do not really need to. */
|
||||
not cls.getASuperType().getName() = "TestCase" and
|
||||
not superclassEqExpectsAttribute(cls, base_eq, store.getName())
|
||||
|
||||
select cls, "The class '" + cls.getName() + "' does not override $@, but adds the new attribute $@.", base_eq, "'__eq__'", store, store.getName()
|
||||
where
|
||||
class_stores_to_attribute(cls, store, _) and
|
||||
should_override_eq(cls, base_eq) and
|
||||
/* Don't report overridden unittest.TestCase. -- TestCase overrides __eq__, but subclasses do not really need to. */
|
||||
not cls.getASuperType().getName() = "TestCase" and
|
||||
not superclassEqExpectsAttribute(cls, base_eq, store.getName())
|
||||
select cls,
|
||||
"The class '" + cls.getName() + "' does not override $@, but adds the new attribute $@.", base_eq,
|
||||
"'__eq__'", store, store.getName()
|
||||
|
||||
Reference in New Issue
Block a user