Skip to content

Commit 9baa262

Browse files
committed
Python: Add getClassName for immutable literals
Used for queries where we mention the class of a literal in the alert message.
1 parent 55744b6 commit 9baa262

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowDispatch.qll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,6 +2158,23 @@ module DuckTyping {
21582158
or
21592159
f.getADecorator().(Name).getId() = "property"
21602160
}
2161+
2162+
/** Gets the name of the builtin class of the immutable literal `lit`. */
2163+
string getClassName(ImmutableLiteral lit) {
2164+
lit instanceof IntegerLiteral and result = "int"
2165+
or
2166+
lit instanceof FloatLiteral and result = "float"
2167+
or
2168+
lit instanceof ImaginaryLiteral and result = "complex"
2169+
or
2170+
lit instanceof NegativeIntegerLiteral and result = "int"
2171+
or
2172+
lit instanceof StringLiteral and result = "str"
2173+
or
2174+
lit instanceof BooleanLiteral and result = "bool"
2175+
or
2176+
lit instanceof None and result = "NoneType"
2177+
}
21612178
}
21622179

21632180
/**

0 commit comments

Comments
 (0)