Skip to content

Commit 4470bfe

Browse files
committed
Python: Get rid of getLiteralValue
This had only two uses in our libraries, so I simply inlined the predicate body in both places.
1 parent b3366d2 commit 4470bfe

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

python/ql/lib/semmle/python/Exprs.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,6 @@ abstract class ImmutableLiteral extends Expr {
337337
abstract Object getLiteralObject();
338338

339339
abstract boolean booleanValue();
340-
341-
final Value getLiteralValue() { result.(ConstantObjectInternal).getLiteral() = this }
342340
}
343341

344342
/** A numerical constant expression, such as `7` or `4.2` */

python/ql/src/Expressions/IsComparisons.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import python
44
private import LegacyPointsTo
5+
private import semmle.python.objects.ObjectInternal
56

67
/** Holds if the comparison `comp` uses `is` or `is not` (represented as `op`) to compare its `left` and `right` arguments. */
78
predicate comparison_using_is(Compare comp, ControlFlowNode left, Cmpop op, ControlFlowNode right) {
@@ -121,7 +122,7 @@ predicate invalid_portable_is_comparison(Compare comp, Cmpop op, ClassValue cls)
121122
// OK to use 'is' when comparing items from a known set of objects
122123
not exists(Expr left, Expr right, Value val |
123124
comp.compares(left, op, right) and
124-
exists(ImmutableLiteral il | il.getLiteralValue() = val)
125+
exists(ImmutableLiteral il | il = val.(ConstantObjectInternal).getLiteral())
125126
|
126127
left.pointsTo(val) and right.pointsTo(val)
127128
or

python/ql/src/Expressions/WrongNumberArgumentsForFormat.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
import python
17+
import semmle.python.objects.ObjectInternal
1718
import semmle.python.strings
1819

1920
predicate string_format(BinaryExpr operation, StringLiteral str, Value args, AstNode origin) {
@@ -31,7 +32,7 @@ int sequence_length(Value args) {
3132
not seq.getAnElt() instanceof Starred
3233
)
3334
or
34-
exists(ImmutableLiteral i | i.getLiteralValue() = args | result = 1)
35+
exists(ImmutableLiteral i | i = args.(ConstantObjectInternal).getLiteral() | result = 1)
3536
}
3637

3738
from

0 commit comments

Comments
 (0)