Skip to content

Commit 010d5fb

Browse files
committed
Python: Fix indexes of keyword-only defaults in upgrade script
Works like a charm ;)
1 parent a15833d commit 010d5fb

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

python/upgrades/f635b392038a494915307f913657cd3058f9b476/py_exprs.ql

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
1+
class Location extends @location {
2+
/** Gets the start line of this location */
3+
int getStartLine() {
4+
locations_default(this, _, result, _, _, _) or
5+
locations_ast(this, _, result, _, _, _)
6+
}
7+
8+
/** Gets the start column of this location */
9+
int getStartColumn() {
10+
locations_default(this, _, _, result, _, _) or
11+
locations_ast(this, _, _, result, _, _)
12+
}
13+
14+
string toString() { result = "<some file>" + ":" + this.getStartLine().toString() }
15+
}
16+
117
class Expr_ extends @py_expr {
218
string toString() { result = "Expr" }
19+
20+
Location getLocation() { py_locations(result, this) }
321
}
422

523
class ExprParent_ extends @py_expr_parent {
@@ -15,6 +33,8 @@ class ExprList_ extends @py_expr_list {
1533

1634
class Parameter_ extends @py_parameter {
1735
string toString() { result = "Parameter" }
36+
37+
Location getLocation() { result = this.(Expr_).getLocation() }
1838
}
1939

2040
class ParameterList extends @py_parameter_list {
@@ -68,8 +88,8 @@ class Function_ extends @py_Function {
6888
string toString() { result = "Function" }
6989
}
7090

71-
72-
/** This class servers the same purpose as CallableExpr. CallableExpr is defined in Function.qll
91+
/**
92+
* This class servers the same purpose as CallableExpr. CallableExpr is defined in Function.qll
7393
* To ease the burden of number of classes that needs to be implemented here, I make the class
7494
* hierarchy slightly different (that's why it's called Adjusted)
7595
*/
@@ -85,7 +105,6 @@ abstract class CallableExprAdjusted extends Expr_ {
85105
abstract Function_ getInnerScope();
86106
}
87107

88-
89108
class Lambda_ extends @py_Lambda, CallableExprAdjusted, Expr_ {
90109
/** Gets the arguments of this lambda expression. */
91110
override Arguments_ getArgs() { py_arguments(result, this) }
@@ -119,5 +138,19 @@ where
119138
args.getDefault(oldidx) = id and
120139
newidx = oldidx + count(callable.getInnerScope().getArg(_)) - count(args.getDefault(_))
121140
)
141+
or
142+
exists(Arguments_ args, CallableExprAdjusted callable |
143+
callable.getArgs() = args and
144+
args.getKwDefault(oldidx) = id and
145+
newidx =
146+
max(int i |
147+
exists(Parameter_ param | param = callable.getInnerScope().getKwonlyarg(i) |
148+
param.getLocation().getStartLine() < id.getLocation().getStartLine()
149+
or
150+
param.getLocation().getStartLine() = id.getLocation().getStartLine() and
151+
param.getLocation().getStartColumn() < id.getLocation().getStartColumn()
152+
)
153+
)
154+
)
122155
)
123156
select id, kind, parent, newidx
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
description: Support defaults for keyword-only parameters
2-
compatibility: partial
2+
compatibility: full
33
py_exprs.rel: run py_exprs.qlo

0 commit comments

Comments
 (0)