@@ -243,6 +243,12 @@ module API {
243243 */
244244 Node getAwaited ( ) { result = this .getASuccessor ( Label:: await ( ) ) }
245245
246+ /**
247+ * Gets a node representing a subscript of this node.
248+ * For example `obj[x]` is a subscript of `obj`.
249+ */
250+ Node getASubscript ( ) { result = this .getASuccessor ( Label:: subscript ( ) ) }
251+
246252 /**
247253 * Gets a string representation of the lexicographically least among all shortest access paths
248254 * from the root to this node.
@@ -570,8 +576,6 @@ module API {
570576 * API graph node for the prefix `foo`), in accordance with the usual semantics of Python.
571577 */
572578
573- private import semmle.python.internal.Awaited
574-
575579 cached
576580 newtype TApiNode =
577581 /** The root of the API graph. */
@@ -747,6 +751,14 @@ module API {
747751 lbl = Label:: return ( ) and
748752 ref = pred .getACall ( )
749753 or
754+ // Awaiting a node that is a use of `base`
755+ lbl = Label:: await ( ) and
756+ ref = pred .getAnAwaited ( )
757+ or
758+ // Subscripting a node that is a use of `base`
759+ lbl = Label:: subscript ( ) and
760+ ref = pred .getASubscript ( )
761+ or
750762 // Subclassing a node
751763 lbl = Label:: subclass ( ) and
752764 exists ( PY:: ClassExpr clsExpr , DataFlow:: Node superclass | pred .flowsTo ( superclass ) |
@@ -760,13 +772,6 @@ module API {
760772 ref .( DataFlow:: ExprNode ) .getNode ( ) .getNode ( ) = clsExpr .getADecoratorCall ( )
761773 )
762774 )
763- or
764- // awaiting
765- exists ( DataFlow:: Node awaitedValue |
766- lbl = Label:: await ( ) and
767- ref = awaited ( awaitedValue ) and
768- pred .flowsTo ( awaitedValue )
769- )
770775 )
771776 or
772777 exists ( DataFlow:: Node def , PY:: CallableExpr fn |
@@ -986,6 +991,7 @@ module API {
986991 MkLabelReturn ( ) or
987992 MkLabelSubclass ( ) or
988993 MkLabelAwait ( ) or
994+ MkLabelSubscript ( ) or
989995 MkLabelEntryPoint ( EntryPoint ep )
990996
991997 /** A label for a module. */
@@ -1061,6 +1067,11 @@ module API {
10611067 override string toString ( ) { result = "getAwaited()" }
10621068 }
10631069
1070+ /** A label that gets the subscript of a sequence/mapping. */
1071+ class LabelSubscript extends ApiLabel , MkLabelSubscript {
1072+ override string toString ( ) { result = "getASubscript()" }
1073+ }
1074+
10641075 /** A label for entry points. */
10651076 class LabelEntryPoint extends ApiLabel , MkLabelEntryPoint {
10661077 private EntryPoint entry ;
@@ -1106,6 +1117,9 @@ module API {
11061117 /** Gets the `await` edge label. */
11071118 LabelAwait await ( ) { any ( ) }
11081119
1120+ /** Gets the `subscript` edge label. */
1121+ LabelSubscript subscript ( ) { any ( ) }
1122+
11091123 /** Gets the label going from the root node to the nodes associated with the given entry point. */
11101124 LabelEntryPoint entryPoint ( EntryPoint ep ) { result = MkLabelEntryPoint ( ep ) }
11111125 }
0 commit comments