Skip to content

Commit 5414bd2

Browse files
authored
Merge pull request #21134 from yoff/python/support-ListElement-in-MaD
Python support `ListElement` in MaD
2 parents fbcb65a + fa92645 commit 5414bd2

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: feature
3+
---
4+
* It is now possible to refer to list elements in the Python models-as-data language, via the `ListElement` path.

python/ql/lib/semmle/python/frameworks/data/internal/ApiGraphModelsSpecific.qll

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,13 @@ API::Node getExtraSuccessorFromNode(API::Node node, AccessPathTokenBase token) {
142142
// `DataFlow::DictionaryElementContent` just from seeing a subscript read, so we would
143143
// need to add that. (also need to handle things like `DictionaryElementAny` which
144144
// doesn't have any value for .getAnArgument())
145-
(
146-
token.getName() = "DictionaryElement" and
147-
result = node.getSubscript(token.getAnArgument())
148-
or
149-
token.getName() = "DictionaryElementAny" and
150-
result = node.getASubscript() and
151-
not exists(token.getAnArgument())
152-
// TODO: ListElement/SetElement/TupleElement
153-
)
145+
token.getName() = "DictionaryElement" and
146+
result = node.getSubscript(token.getAnArgument())
147+
or
148+
token.getName() in ["DictionaryElementAny", "ListElement"] and
149+
result = node.getASubscript() and
150+
not exists(token.getAnArgument())
151+
// TODO: SetElement/TupleElement
154152
// Some features don't have MaD tokens yet, they would need to be added to API-graphs first.
155153
// - decorators ("DecoratedClass", "DecoratedMember", "DecoratedParameter")
156154
}
@@ -261,7 +259,7 @@ predicate isExtraValidTokenNameInIdentifyingAccessPath(string name) {
261259
name =
262260
[
263261
"Member", "Instance", "Awaited", "Call", "Method", "Subclass", "DictionaryElement",
264-
"DictionaryElementAny"
262+
"DictionaryElementAny", "ListElement"
265263
]
266264
}
267265

@@ -270,7 +268,7 @@ predicate isExtraValidTokenNameInIdentifyingAccessPath(string name) {
270268
* in an identifying access path.
271269
*/
272270
predicate isExtraValidNoArgumentTokenInIdentifyingAccessPath(string name) {
273-
name = ["Instance", "Awaited", "Call", "Subclass", "DictionaryElementAny"]
271+
name = ["Instance", "Awaited", "Call", "Subclass", "DictionaryElementAny", "ListElement"]
274272
}
275273

276274
/**

python/ql/test/library-tests/frameworks/data/test.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ isSource
108108
| test.py:119:20:119:30 | ControlFlowNode for getSource() | test-source |
109109
| test.py:124:1:124:33 | ControlFlowNode for Attribute() | test-source |
110110
| test.py:126:11:126:43 | ControlFlowNode for Attribute() | test-source |
111+
| test.py:129:11:129:39 | ControlFlowNode for Attribute() | test-source |
111112
syntaxErrors
112113
| Member[foo |
113114
| Member[foo] .Member[bar] |

python/ql/test/library-tests/frameworks/data/test.ext.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extensions:
2727
- ["testlib", "Member[source_dict].DictionaryElement[key].Member[func].ReturnValue", "test-source"]
2828
- ["testlib", "Member[source_dict_any].DictionaryElementAny.Member[func].ReturnValue", "test-source"]
2929
# TODO: Add support for list/tuples
30-
# - ["testlib", "Member[source_list].ListElement.Member[func].ReturnValue", "test-source"]
30+
- ["testlib", "Member[source_list].ListElement.Member[func].ReturnValue", "test-source"]
3131
# - ["testlib", "Member[source_tuple].TupleElement[0].Member[func].ReturnValue", "test-source"]
3232

3333
- addsTo:

0 commit comments

Comments
 (0)