@@ -42,29 +42,29 @@ private import semmle.python.internal.CachedStages
4242newtype TParameterPosition =
4343 /** Used for `self` in methods, and `cls` in classmethods. */
4444 TSelfParameterPosition ( ) or
45- TPositionalParameterPosition ( int pos ) {
46- pos = any ( Parameter p ) .getPosition ( )
45+ TPositionalParameterPosition ( int index ) {
46+ index = any ( Parameter p ) .getPosition ( )
4747 or
4848 // since synthetic parameters are made for a synthetic summary callable, based on
4949 // what Argument positions they have flow for, we need to make sure we have such
5050 // parameter positions available.
51- FlowSummaryImplSpecific:: ParsePositions:: isParsedPositionalArgumentPosition ( _, pos )
51+ FlowSummaryImplSpecific:: ParsePositions:: isParsedPositionalArgumentPosition ( _, index )
5252 } or
5353 TKeywordParameterPosition ( string name ) {
5454 name = any ( Parameter p ) .getName ( )
5555 or
5656 // see comment for TPositionalParameterPosition
5757 FlowSummaryImplSpecific:: ParsePositions:: isParsedKeywordArgumentPosition ( _, name )
5858 } or
59- TStarArgsParameterPosition ( int pos ) {
59+ TStarArgsParameterPosition ( int index ) {
6060 // since `.getPosition` does not work for `*args`, we need *args parameter positions
6161 // at index 1 larger than the largest positional parameter position (and 0 must be
6262 // included as well). This is a bit of an over-approximation.
63- pos = 0 or
64- pos = any ( Parameter p ) .getPosition ( ) + 1
63+ index = 0 or
64+ index = any ( Parameter p ) .getPosition ( ) + 1
6565 } or
66- TSynthStarArgsElementParameterPosition ( int pos ) { exists ( TStarArgsParameterPosition ( pos ) ) } or
67- TSynthLateStarArgsParameterPosition ( int pos ) { exists ( TStarArgsParameterPosition ( pos ) ) } or
66+ TSynthStarArgsElementParameterPosition ( int index ) { exists ( TStarArgsParameterPosition ( index ) ) } or
67+ TSynthLateStarArgsParameterPosition ( int index ) { exists ( TStarArgsParameterPosition ( index ) ) } or
6868 TDictSplatParameterPosition ( )
6969
7070/** A parameter position. */
@@ -128,21 +128,23 @@ class ParameterPosition extends TParameterPosition {
128128newtype TArgumentPosition =
129129 /** Used for `self` in methods, and `cls` in classmethods. */
130130 TSelfArgumentPosition ( ) or
131- TPositionalArgumentPosition ( int pos ) {
132- exists ( any ( CallNode c ) .getArg ( pos ) )
131+ TPositionalArgumentPosition ( int index ) {
132+ exists ( any ( CallNode c ) .getArg ( index ) )
133133 or
134134 // since synthetic calls within a summarized callable could use a unique argument
135135 // position, we need to ensure we make these available (these are specified as
136136 // parameters in the flow-summary spec)
137- FlowSummaryImplSpecific:: ParsePositions:: isParsedPositionalParameterPosition ( _, pos )
137+ FlowSummaryImplSpecific:: ParsePositions:: isParsedPositionalParameterPosition ( _, index )
138138 } or
139139 TKeywordArgumentPosition ( string name ) {
140140 exists ( any ( CallNode c ) .getArgByName ( name ) )
141141 or
142142 // see comment for TPositionalArgumentPosition
143143 FlowSummaryImplSpecific:: ParsePositions:: isParsedKeywordParameterPosition ( _, name )
144144 } or
145- TStarArgsArgumentPosition ( int pos ) { exists ( Call c | c .getPositionalArg ( pos ) instanceof Starred ) } or
145+ TStarArgsArgumentPosition ( int index ) {
146+ exists ( Call c | c .getPositionalArg ( index ) instanceof Starred )
147+ } or
146148 TDictSplatArgumentPosition ( )
147149
148150/** An argument position. */
@@ -329,11 +331,9 @@ abstract class DataFlowFunction extends DataFlowCallable, TFunction {
329331 |
330332 // a `*args` parameter comes after the last positional parameter. We need to take
331333 // self parameter into account, so for
332- // `def func(foo, bar, *args)` it should be index 2 (1 + max-index == 1 + 1)
333- // `class A: def func(self, foo, bar, *args)` it should be index 2 (1 + max-index - 1 == 1 + 2 - 1)
334- index =
335- 1 + max ( int positionalIndex | exists ( func .getArg ( positionalIndex ) ) | positionalIndex ) -
336- this .positionalOffset ( )
334+ // `def func(foo, bar, *args)` it should be index 2 (pos-param-count == 2)
335+ // `class A: def func(self, foo, bar, *args)` it should be index 2 (pos-param-count - 1 == 3 - 1)
336+ index = func .getPositionalParameterCount ( ) - this .positionalOffset ( )
337337 or
338338 // no positional argument
339339 not exists ( func .getArg ( _) ) and index = 0
@@ -579,8 +579,8 @@ Node clsTracker(Class classWithMethod) {
579579 * call happened in the method `func` (either a method or a classmethod).
580580 */
581581private TypeTrackingNode superCallNoArgumentTracker ( TypeTracker t , Function func ) {
582- not isStaticmethod ( func ) and
583582 t .start ( ) and
583+ not isStaticmethod ( func ) and
584584 exists ( CallCfgNode call | result = call |
585585 call = getSuperCall ( ) and
586586 not exists ( call .getArg ( _) ) and
0 commit comments