Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit beebd0e

Browse files
committed
Python points-to: Be more specific when describing inheritance analysis failures.
1 parent 7244b9f commit beebd0e

2 files changed

Lines changed: 17 additions & 31 deletions

File tree

python/ql/src/semmle/python/pointsto/PointsTo.qll

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,31 +1826,38 @@ cached module Types {
18261826

18271827
/* Holds if type inference failed to compute the full class hierarchy for this class for the reason given. */
18281828
cached predicate failedInference(ClassObjectInternal cls, string reason) {
1829-
strictcount(cls.(PythonClassObjectInternal).getScope().getADecorator()) > 1 and reason = "Multiple decorators"
1829+
exists(int priority |
1830+
failedInference(cls, reason, priority) and
1831+
priority = max(int p | failedInference(cls, _, p))
1832+
)
1833+
}
1834+
1835+
/* Holds if type inference failed to compute the full class hierarchy for this class for the reason given. */
1836+
private predicate failedInference(ClassObjectInternal cls, string reason, int priority) {
1837+
strictcount(cls.(PythonClassObjectInternal).getScope().getADecorator()) > 1 and reason = "Multiple decorators" and priority = 0
18301838
or
1831-
exists(cls.(PythonClassObjectInternal).getScope().getADecorator()) and not six_add_metaclass(_, cls, _) and reason = "Decorator not understood"
1839+
exists(cls.(PythonClassObjectInternal).getScope().getADecorator()) and not six_add_metaclass(_, cls, _) and reason = "Decorator not understood" and priority = 1
18321840
or
1833-
reason = "Missing base " + missingBase(cls)
1841+
reason = "Missing base " + missingBase(cls) and priority = 6
18341842
or
1835-
not exists(ObjectInternal meta | meta = cls.getClass() and not meta = ObjectInternal::unknownClass()) and reason = "Failed to infer metaclass"
1843+
not exists(ObjectInternal meta | meta = cls.getClass() and not meta = ObjectInternal::unknownClass()) and reason = "Failed to infer metaclass" and priority = 4
18361844
or
18371845
exists(int i, ObjectInternal base1, ObjectInternal base2 |
18381846
base1 = getBase(cls, i) and
18391847
base2 = getBase(cls, i) and
18401848
base1 != base2 and
18411849
reason = "Multiple bases at position " + i
1842-
)
1850+
) and priority = 6
18431851
or
1844-
duplicateBase(cls) and reason = "Duplicate bases classes"
1852+
duplicateBase(cls) and reason = "Duplicate bases classes" and priority = 6
18451853
or
1846-
not exists(getMro(cls)) and reason = "Failed to compute MRO" and not exists(missingBase(cls)) and not duplicateBase(cls)
1854+
not exists(getMro(cls)) and reason = "Failed to compute MRO" and priority = 3
18471855
or
1848-
exists(int i | failedInference(getBase(cls, i), _) and reason = "Failed inference for base class at position " + i)
1856+
exists(int i | failedInference(getBase(cls, i), _, _) and reason = "Failed inference for base class at position " + i) and priority = 5
18491857
}
18501858

18511859
private int missingBase(ClassObjectInternal cls) {
1852-
exists(cls.(PythonClassObjectInternal).getScope().getBase(result))
1853-
and
1860+
exists(cls.(PythonClassObjectInternal).getScope().getBase(result)) and
18541861
not exists(ObjectInternal base | base = getBase(cls, result) and not base = ObjectInternal::unknownClass())
18551862
}
18561863

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,14 @@
11
| class A | Missing base 0 |
22
| class B | Failed inference for base class at position 0 |
3-
| class B | Failed to compute MRO |
43
| class C | Failed inference for base class at position 0 |
5-
| class C | Failed to compute MRO |
64
| class D | Duplicate bases classes |
75
| class E | Duplicate bases classes |
8-
| class E | Failed inference for base class at position 0 |
9-
| class E | Failed inference for base class at position 1 |
10-
| class E | Failed inference for base class at position 2 |
11-
| class E | Failed inference for base class at position 3 |
12-
| class E | Failed inference for base class at position 4 |
13-
| class E | Failed inference for base class at position 5 |
14-
| class E | Failed inference for base class at position 6 |
15-
| class E | Failed inference for base class at position 7 |
16-
| class E | Failed inference for base class at position 8 |
17-
| class E | Failed inference for base class at position 9 |
18-
| class E | Failed inference for base class at position 10 |
196
| class G | Failed inference for base class at position 0 |
20-
| class G | Failed to compute MRO |
217
| class H | Failed inference for base class at position 0 |
22-
| class H | Failed to compute MRO |
238
| class J | Missing base 0 |
249
| class L | Failed inference for base class at position 0 |
25-
| class L | Failed to compute MRO |
2610
| class M | Failed inference for base class at position 0 |
27-
| class M | Failed to compute MRO |
2811
| class N | Failed inference for base class at position 0 |
29-
| class N | Failed to compute MRO |
3012
| class R | Failed inference for base class at position 0 |
31-
| class R | Failed to compute MRO |
3213
| class S | Failed inference for base class at position 0 |
33-
| class S | Failed to compute MRO |
3414
| class T | Failed inference for base class at position 0 |
35-
| class T | Failed to compute MRO |

0 commit comments

Comments
 (0)