mirror of
https://github.com/github/codeql.git
synced 2026-05-02 20:25:13 +02:00
Python points-to: Fix up metaclass determination for Python 2.
This commit is contained in:
@@ -426,6 +426,11 @@ module ObjectInternal {
|
||||
result = TBuiltinClassObject(Builtin::special("super"))
|
||||
}
|
||||
|
||||
/** The old-style class type (Python 2 only) */
|
||||
ObjectInternal classType() {
|
||||
result = TBuiltinClassObject(Builtin::special("ClassType"))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** Helper for boolean predicates returning both `true` and `false` */
|
||||
|
||||
@@ -1692,9 +1692,9 @@ cached module Types {
|
||||
}
|
||||
|
||||
cached ClassObjectInternal getMetaClass(PythonClassObjectInternal cls) {
|
||||
result = declaredMetaClass(cls)
|
||||
or
|
||||
hasDeclaredMetaclass(cls) = false and result = getInheritedMetaclass(cls)
|
||||
result = declaredMetaClass(cls)
|
||||
or
|
||||
hasDeclaredMetaclass(cls) = false and result = getInheritedMetaclass(cls)
|
||||
}
|
||||
|
||||
private ClassObjectInternal declaredMetaClass(PythonClassObjectInternal cls) {
|
||||
@@ -1799,7 +1799,9 @@ cached module Types {
|
||||
c = cls.(PythonClassObjectInternal).getScope() and
|
||||
n = count(c.getABase())
|
||||
|
|
||||
result = ObjectInternal::builtin("type")
|
||||
result = ObjectInternal::type() and major_version() = 3
|
||||
or
|
||||
result = ObjectInternal::classType() and major_version() = 2
|
||||
)
|
||||
or
|
||||
exists(ClassObjectInternal meta1, ClassObjectInternal meta2 |
|
||||
@@ -1811,6 +1813,8 @@ cached module Types {
|
||||
or
|
||||
improperSuperType(meta2) = meta1 and result = meta2
|
||||
or
|
||||
meta2 = ObjectInternal::classType() and result = meta1
|
||||
or
|
||||
/* Make sure we have a metaclass, even if base is unknown */
|
||||
meta1 = ObjectInternal::unknownClass() and result = ObjectInternal::builtin("type")
|
||||
or
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
|
||||
import python
|
||||
import semmle.python.pointsto.MRO
|
||||
import semmle.python.pointsto.PointsTo
|
||||
import semmle.python.objects.ObjectInternal
|
||||
|
||||
ClassList mro(ClassObject cls) {
|
||||
if cls.isNewStyle() then
|
||||
result = new_style_mro(cls)
|
||||
ClassList mro(ClassObjectInternal cls) {
|
||||
if Types::isNewStyle(cls) then
|
||||
result = Mro::newStyleMro(cls)
|
||||
else
|
||||
result = old_style_mro(cls)
|
||||
result = Mro::oldStyleMro(cls)
|
||||
}
|
||||
|
||||
from ClassObject cls
|
||||
from ClassObjectInternal cls
|
||||
where not cls.isBuiltin()
|
||||
|
||||
select cls.toString(), mro(cls)
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
/**
|
||||
* @name class_attr
|
||||
* @kind test
|
||||
* @problem.severity warning
|
||||
*/
|
||||
|
||||
|
||||
import python
|
||||
|
||||
|
||||
Reference in New Issue
Block a user