@@ -64,27 +64,18 @@ class Arguments_ extends @py_arguments {
64
64
}
65
65
66
66
class Function_ extends @py_Function {
67
- /** Gets the name of this function. */
68
- string getName ( ) { py_strs ( result , this , 0 ) }
69
-
70
67
/** Gets the positional parameter list of this function. */
71
68
ParameterList getArgs ( ) { py_parameter_lists ( result , this ) }
72
69
73
70
/** Gets the nth positional parameter of this function. */
74
71
Parameter_ getArg ( int index ) { result = this .getArgs ( ) .getItem ( index ) }
75
72
76
- /** Gets the tuple (*) parameter of this function. */
77
- Expr_ getVararg ( ) { py_exprs ( result , _, this , 2 ) }
78
-
79
73
/** Gets the keyword-only parameter list of this function. */
80
74
ExprList_ getKwonlyargs ( ) { py_expr_lists ( result , this , 3 ) }
81
75
82
76
/** Gets the nth keyword-only parameter of this function. */
83
77
Expr_ getKwonlyarg ( int index ) { result = this .getKwonlyargs ( ) .getItem ( index ) }
84
78
85
- /** Gets the dictionary (**) parameter of this function. */
86
- Expr_ getKwarg ( ) { py_exprs ( result , _, this , 4 ) }
87
-
88
79
string toString ( ) { result = "Function" }
89
80
}
90
81
@@ -125,32 +116,42 @@ class FunctionExpr_ extends @py_FunctionExpr, CallableExprAdjusted, Expr_ {
125
116
override string toString ( ) { result = "FunctionExpr" }
126
117
}
127
118
128
- from Expr_ id , int kind , ExprParent_ parent , int oldidx , int newidx
119
+
120
+ /*
121
+ * This upgrade changes the *layout* of the default values for parameters, by
122
+ * making `Argument.getKwDefault(i)` return the default value for keyword-only parameter `i`
123
+ * (instead of the i'th default for a keyword-only parameter). `Argument.getDefault` is
124
+ * changed in the same manner to keep consistency.
125
+ */
126
+ from Expr_ expr , int kind , ExprParent_ parent , int oldidx , int newidx
129
127
where
130
- py_exprs ( id , kind , parent , oldidx ) and
128
+ py_exprs ( expr , kind , parent , oldidx ) and
131
129
(
132
- not exists ( Arguments_ args | args .getDefault ( oldidx ) = id ) and
133
- not exists ( Arguments_ args | args .getKwDefault ( oldidx ) = id ) and
130
+ // expr is not a parameter default
131
+ not exists ( Arguments_ args | args .getDefault ( oldidx ) = expr ) and
132
+ not exists ( Arguments_ args | args .getKwDefault ( oldidx ) = expr ) and
134
133
newidx = oldidx
135
134
or
135
+ // expr is a default for a normal parameter
136
136
exists ( Arguments_ args , CallableExprAdjusted callable |
137
137
callable .getArgs ( ) = args and
138
- args .getDefault ( oldidx ) = id and
138
+ args .getDefault ( oldidx ) = expr and
139
139
newidx = oldidx + count ( callable .getInnerScope ( ) .getArg ( _) ) - count ( args .getDefault ( _) )
140
140
)
141
141
or
142
+ // expr is a default for a keyword-only parameter
142
143
exists ( Arguments_ args , CallableExprAdjusted callable |
143
144
callable .getArgs ( ) = args and
144
- args .getKwDefault ( oldidx ) = id and
145
+ args .getKwDefault ( oldidx ) = expr and
145
146
newidx =
146
147
max ( int i |
147
148
exists ( Parameter_ param | param = callable .getInnerScope ( ) .getKwonlyarg ( i ) |
148
- param .getLocation ( ) .getStartLine ( ) < id .getLocation ( ) .getStartLine ( )
149
+ param .getLocation ( ) .getStartLine ( ) < expr .getLocation ( ) .getStartLine ( )
149
150
or
150
- param .getLocation ( ) .getStartLine ( ) = id .getLocation ( ) .getStartLine ( ) and
151
- param .getLocation ( ) .getStartColumn ( ) < id .getLocation ( ) .getStartColumn ( )
151
+ param .getLocation ( ) .getStartLine ( ) = expr .getLocation ( ) .getStartLine ( ) and
152
+ param .getLocation ( ) .getStartColumn ( ) < expr .getLocation ( ) .getStartColumn ( )
152
153
)
153
154
)
154
155
)
155
156
)
156
- select id , kind , parent , newidx
157
+ select expr , kind , parent , newidx
0 commit comments