@@ -42,29 +42,29 @@ private import semmle.python.internal.CachedStages
42
42
newtype TParameterPosition =
43
43
/** Used for `self` in methods, and `cls` in classmethods. */
44
44
TSelfParameterPosition ( ) or
45
- TPositionalParameterPosition ( int pos ) {
46
- pos = any ( Parameter p ) .getPosition ( )
45
+ TPositionalParameterPosition ( int index ) {
46
+ index = any ( Parameter p ) .getPosition ( )
47
47
or
48
48
// since synthetic parameters are made for a synthetic summary callable, based on
49
49
// what Argument positions they have flow for, we need to make sure we have such
50
50
// parameter positions available.
51
- FlowSummaryImplSpecific:: ParsePositions:: isParsedPositionalArgumentPosition ( _, pos )
51
+ FlowSummaryImplSpecific:: ParsePositions:: isParsedPositionalArgumentPosition ( _, index )
52
52
} or
53
53
TKeywordParameterPosition ( string name ) {
54
54
name = any ( Parameter p ) .getName ( )
55
55
or
56
56
// see comment for TPositionalParameterPosition
57
57
FlowSummaryImplSpecific:: ParsePositions:: isParsedKeywordArgumentPosition ( _, name )
58
58
} or
59
- TStarArgsParameterPosition ( int pos ) {
59
+ TStarArgsParameterPosition ( int index ) {
60
60
// since `.getPosition` does not work for `*args`, we need *args parameter positions
61
61
// at index 1 larger than the largest positional parameter position (and 0 must be
62
62
// 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
65
65
} 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
68
68
TDictSplatParameterPosition ( )
69
69
70
70
/** A parameter position. */
@@ -128,21 +128,23 @@ class ParameterPosition extends TParameterPosition {
128
128
newtype TArgumentPosition =
129
129
/** Used for `self` in methods, and `cls` in classmethods. */
130
130
TSelfArgumentPosition ( ) or
131
- TPositionalArgumentPosition ( int pos ) {
132
- exists ( any ( CallNode c ) .getArg ( pos ) )
131
+ TPositionalArgumentPosition ( int index ) {
132
+ exists ( any ( CallNode c ) .getArg ( index ) )
133
133
or
134
134
// since synthetic calls within a summarized callable could use a unique argument
135
135
// position, we need to ensure we make these available (these are specified as
136
136
// parameters in the flow-summary spec)
137
- FlowSummaryImplSpecific:: ParsePositions:: isParsedPositionalParameterPosition ( _, pos )
137
+ FlowSummaryImplSpecific:: ParsePositions:: isParsedPositionalParameterPosition ( _, index )
138
138
} or
139
139
TKeywordArgumentPosition ( string name ) {
140
140
exists ( any ( CallNode c ) .getArgByName ( name ) )
141
141
or
142
142
// see comment for TPositionalArgumentPosition
143
143
FlowSummaryImplSpecific:: ParsePositions:: isParsedKeywordParameterPosition ( _, name )
144
144
} 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
146
148
TDictSplatArgumentPosition ( )
147
149
148
150
/** An argument position. */
@@ -329,11 +331,9 @@ abstract class DataFlowFunction extends DataFlowCallable, TFunction {
329
331
|
330
332
// a `*args` parameter comes after the last positional parameter. We need to take
331
333
// 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 ( )
337
337
or
338
338
// no positional argument
339
339
not exists ( func .getArg ( _) ) and index = 0
@@ -579,8 +579,8 @@ Node clsTracker(Class classWithMethod) {
579
579
* call happened in the method `func` (either a method or a classmethod).
580
580
*/
581
581
private TypeTrackingNode superCallNoArgumentTracker ( TypeTracker t , Function func ) {
582
- not isStaticmethod ( func ) and
583
582
t .start ( ) and
583
+ not isStaticmethod ( func ) and
584
584
exists ( CallCfgNode call | result = call |
585
585
call = getSuperCall ( ) and
586
586
not exists ( call .getArg ( _) ) and
0 commit comments