Skip to content

Commit 04c0475

Browse files
authored
Merge pull request github#16483 from yoff/python/MaD-instance-follow-subclass
Python: The MaD token `Instance` now follows subclasses
2 parents d76182b + 52717f8 commit 04c0475

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

python/ql/lib/semmle/python/ApiGraphs.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ module API {
226226
*/
227227
Node getASubclass() { result = this.getASuccessor(Label::subclass()) }
228228

229+
/**
230+
* Gets a node representing an instance of the class (or a transitive subclass of the class) represented by this node.
231+
*/
232+
Node getAnInstance() { result = this.getASubclass*().getReturn() }
233+
229234
/**
230235
* Gets a node representing the result from awaiting this node.
231236
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ API::Node getExtraSuccessorFromNode(API::Node node, AccessPathTokenBase token) {
5353
result = node.getMember(token.getAnArgument())
5454
or
5555
token.getName() = "Instance" and
56-
result = node.getReturn() // In Python `Instance` is just an alias for `ReturnValue`
56+
result = node.getAnInstance()
5757
or
5858
token.getName() = "Awaited" and
5959
result = node.getAwaited()

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ isSource
7878
| test.py:39:11:39:20 | ControlFlowNode for Await | test-source |
7979
| test.py:41:8:41:27 | ControlFlowNode for Attribute() | test-source |
8080
| test.py:46:7:46:16 | ControlFlowNode for SubClass() | test-source |
81+
| test.py:51:8:51:18 | ControlFlowNode for Sub2Class() | test-source |
8182
| test.py:53:7:53:16 | ControlFlowNode for Attribute() | test-source |
8283
| test.py:60:13:60:16 | ControlFlowNode for self | test-source |
8384
| test.py:60:24:60:28 | ControlFlowNode for named | test-source |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class SubClass (CommonTokens.Super):
4848
class Sub2Class (CommonTokens.Class):
4949
pass
5050

51-
sub2 = Sub2Class() # TODO: Currently not recognized as an instance of CommonTokens.Class
51+
sub2 = Sub2Class()
5252

5353
val = inst.foo()
5454

0 commit comments

Comments
 (0)