Python: Get rid of getLiteralValue

This had only two uses in our libraries, so I simply inlined the
predicate body in both places.
This commit is contained in:
Taus
2025-10-30 11:50:07 +00:00
parent fef08afff9
commit b434ce460e
3 changed files with 4 additions and 4 deletions

View File

@@ -337,8 +337,6 @@ abstract class ImmutableLiteral extends Expr {
abstract Object getLiteralObject();
abstract boolean booleanValue();
final Value getLiteralValue() { result.(ConstantObjectInternal).getLiteral() = this }
}
/** A numerical constant expression, such as `7` or `4.2` */

View File

@@ -2,6 +2,7 @@
import python
private import LegacyPointsTo
private import semmle.python.objects.ObjectInternal
/** Holds if the comparison `comp` uses `is` or `is not` (represented as `op`) to compare its `left` and `right` arguments. */
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)
// OK to use 'is' when comparing items from a known set of objects
not exists(Expr left, Expr right, Value val |
comp.compares(left, op, right) and
exists(ImmutableLiteral il | il.getLiteralValue() = val)
exists(ImmutableLiteral il | il = val.(ConstantObjectInternal).getLiteral())
|
left.pointsTo(val) and right.pointsTo(val)
or

View File

@@ -14,6 +14,7 @@
*/
import python
import semmle.python.objects.ObjectInternal
import semmle.python.strings
predicate string_format(BinaryExpr operation, StringLiteral str, Value args, AstNode origin) {
@@ -31,7 +32,7 @@ int sequence_length(Value args) {
not seq.getAnElt() instanceof Starred
)
or
exists(ImmutableLiteral i | i.getLiteralValue() = args | result = 1)
exists(ImmutableLiteral i | i = args.(ConstantObjectInternal).getLiteral() | result = 1)
}
from