Python points-to: Fix up handiling of metaclasses, new-style and type-heirarchy failure analysis.

This commit is contained in:
Mark Shannon
2019-05-10 13:02:36 +01:00
parent 93f0b8f1b7
commit 39861597e5
10 changed files with 89 additions and 11 deletions

View File

@@ -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 |

View File

@@ -0,0 +1,9 @@
import python
from ClassObject cls, string reason
where cls.getPyClass().getEnclosingModule().getName() = "test"
and cls.failedInference(reason)
select cls, reason

View File

@@ -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] |

View 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)

View File

@@ -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 |

View 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

View File

@@ -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"