mirror of
https://github.com/github/codeql.git
synced 2026-04-26 09:15:12 +02:00
Python: Autoformat everything using qlformat.
Will need subsequent PRs fixing up test failures (due to deprecated methods moving around), but other than that everything should be straight-forward.
This commit is contained in:
@@ -15,21 +15,21 @@ import semmle.python.SelfAttribute
|
||||
import Equality
|
||||
|
||||
predicate class_stores_to_attribute(ClassValue cls, SelfAttributeStore store, string name) {
|
||||
exists(FunctionValue f |
|
||||
f = cls.declaredAttribute(_) and store.getScope() = f.getScope() and store.getName() = name
|
||||
) and
|
||||
/* Exclude classes used as metaclasses */
|
||||
not cls.getASuperType() = ClassValue::type()
|
||||
exists(FunctionValue f |
|
||||
f = cls.declaredAttribute(_) and store.getScope() = f.getScope() and store.getName() = name
|
||||
) and
|
||||
/* Exclude classes used as metaclasses */
|
||||
not cls.getASuperType() = ClassValue::type()
|
||||
}
|
||||
|
||||
predicate should_override_eq(ClassValue cls, Value base_eq) {
|
||||
not cls.declaresAttribute("__eq__") and
|
||||
exists(ClassValue sup | sup = cls.getABaseType() and sup.declaredAttribute("__eq__") = base_eq |
|
||||
not exists(GenericEqMethod eq | eq.getScope() = sup.getScope()) and
|
||||
not exists(IdentityEqMethod eq | eq.getScope() = sup.getScope()) and
|
||||
not base_eq.(FunctionValue).getScope() instanceof IdentityEqMethod and
|
||||
not base_eq = ClassValue::object().declaredAttribute("__eq__")
|
||||
)
|
||||
not cls.declaresAttribute("__eq__") and
|
||||
exists(ClassValue sup | sup = cls.getABaseType() and sup.declaredAttribute("__eq__") = base_eq |
|
||||
not exists(GenericEqMethod eq | eq.getScope() = sup.getScope()) and
|
||||
not exists(IdentityEqMethod eq | eq.getScope() = sup.getScope()) and
|
||||
not base_eq.(FunctionValue).getScope() instanceof IdentityEqMethod and
|
||||
not base_eq = ClassValue::object().declaredAttribute("__eq__")
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,21 +37,21 @@ predicate should_override_eq(ClassValue cls, Value base_eq) {
|
||||
* which implies that the __eq__ method does not need to be overridden.
|
||||
*/
|
||||
predicate superclassEqExpectsAttribute(ClassValue cls, FunctionValue base_eq, string attrname) {
|
||||
not cls.declaresAttribute("__eq__") and
|
||||
exists(ClassValue sup | sup = cls.getABaseType() and sup.declaredAttribute("__eq__") = base_eq |
|
||||
exists(SelfAttributeRead store | store.getName() = attrname |
|
||||
store.getScope() = base_eq.getScope()
|
||||
)
|
||||
not cls.declaresAttribute("__eq__") and
|
||||
exists(ClassValue sup | sup = cls.getABaseType() and sup.declaredAttribute("__eq__") = base_eq |
|
||||
exists(SelfAttributeRead store | store.getName() = attrname |
|
||||
store.getScope() = base_eq.getScope()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
from ClassValue cls, SelfAttributeStore store, Value 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())
|
||||
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()
|
||||
"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