Skip to content

Commit 178acc8

Browse files
committed
Adds main modifications.
1 parent 5269fb7 commit 178acc8

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

python/ql/src/Expressions/ExpectedMappingForFormatString.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import python
1414
import semmle.python.strings
1515

16-
from Expr e, ClassObject t
16+
from Expr e, ClassValue t
1717
where exists(BinaryExpr b | b.getOp() instanceof Mod and format_string(b.getLeft()) and e = b.getRight() and
18-
mapping_format(b.getLeft()) and e.refersTo(_, t, _) and not t.isMapping())
19-
select e, "Right hand side of a % operator must be a mapping, not class $@.", t, t.getName()
18+
mapping_format(b.getLeft()) and e.pointsTo(_, t, _) and not t.isMapping())
19+
select e, "Right hand side of a % operator must be a mapping, not class $@.", t, t.getName()

python/ql/src/semmle/python/objects/ObjectAPI.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,16 @@ class ClassValue extends Value {
402402
or
403403
this.hasAttribute("__getitem__")
404404
}
405+
406+
/** Holds if this class is a mapping.
407+
*
408+
* This is an attempt to translate ClassObject::isMapping()
409+
*/
410+
predicate isMapping() {
411+
exists(this.attr("__getitem__"))
412+
and
413+
not this instanceof SequenceValue
414+
}
405415

406416
/** Holds if this class is a descriptor. */
407417
predicate isDescriptorType() {

0 commit comments

Comments
 (0)