mirror of
https://github.com/github/codeql.git
synced 2026-05-05 05:35:13 +02:00
Python points-to: Fix up handiling of metaclasses, new-style and type-heirarchy failure analysis.
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
| test.py:26:1:26:17 | class C5 | Failed to infer metaclass |
|
||||
| test.py:30:1:30:17 | class C6 | Decorator not understood |
|
||||
| test.py:30:1:30:17 | class C6 | Failed to infer metaclass |
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
import python
|
||||
|
||||
from ClassObject cls, string reason
|
||||
|
||||
where cls.getPyClass().getEnclosingModule().getName() = "test"
|
||||
and cls.failedInference(reason)
|
||||
|
||||
select cls, reason
|
||||
@@ -0,0 +1,7 @@
|
||||
| class C1 | [C1, object] |
|
||||
| class C2 | [C2, object] |
|
||||
| class C3 | [C3, object] |
|
||||
| class C4 | [C4, C2, object] |
|
||||
| class Meta1 | [Meta1, type, object] |
|
||||
| class Meta2 | [Meta2, type, object] |
|
||||
| class NewStyleEvenForPython2 | [NewStyleEvenForPython2, object] |
|
||||
18
python/ql/test/library-tests/PointsTo/metaclass/Mro.ql
Normal file
18
python/ql/test/library-tests/PointsTo/metaclass/Mro.ql
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
import python
|
||||
|
||||
private import semmle.python.objects.ObjectInternal
|
||||
private import semmle.python.pointsto.PointsTo
|
||||
|
||||
/** Make unknown type visible */
|
||||
class UnknownType extends UnknownClassInternal {
|
||||
|
||||
override string toString() { result = "*UNKNOWN TYPE" }
|
||||
|
||||
override string getName() { result = "UNKNOWN" }
|
||||
|
||||
}
|
||||
|
||||
from PythonClassObjectInternal cls
|
||||
where cls.getScope().getEnclosingModule().getName() = "test" and not Types::failedInference(cls, _)
|
||||
select cls.toString(), Types::getMro(cls)
|
||||
@@ -0,0 +1,9 @@
|
||||
| test.py:3:1:3:18 | class Meta1 | new |
|
||||
| test.py:6:1:6:18 | class Meta2 | new |
|
||||
| test.py:10:1:10:17 | class C1 | new |
|
||||
| test.py:14:1:14:17 | class C2 | new |
|
||||
| test.py:18:1:18:17 | class C3 | new |
|
||||
| test.py:22:1:22:21 | class C4 | new |
|
||||
| test.py:26:1:26:17 | class C5 | new |
|
||||
| test.py:30:1:30:17 | class C6 | new |
|
||||
| test.py:35:1:35:29 | class NewStyleEvenForPython2 | new |
|
||||
13
python/ql/test/library-tests/PointsTo/metaclass/Style.ql
Normal file
13
python/ql/test/library-tests/PointsTo/metaclass/Style.ql
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
|
||||
import python
|
||||
|
||||
|
||||
from ClassObject cls, string style
|
||||
where cls.getPyClass().getEnclosingModule().getName() = "test"
|
||||
and (
|
||||
cls.isNewStyle() and style = "new"
|
||||
or
|
||||
cls.isOldStyle() and style = "old"
|
||||
)
|
||||
select cls, style
|
||||
@@ -1,5 +1,15 @@
|
||||
|
||||
import python
|
||||
private import semmle.python.objects.ObjectInternal
|
||||
|
||||
/** Make unknown type visible */
|
||||
class UnknownType extends UnknownClassInternal {
|
||||
|
||||
override string toString() { result = "*UNKNOWN TYPE" }
|
||||
|
||||
override string getName() { result = "UNKNOWN" }
|
||||
|
||||
}
|
||||
|
||||
from ClassObject cls
|
||||
where cls.getPyClass().getEnclosingModule().getName() = "test"
|
||||
|
||||
Reference in New Issue
Block a user