Skip to content

Commit 5a18b08

Browse files
committed
Python: Add comment explaining kw-only default index upgrade
1 parent a616704 commit 5a18b08

File tree

1 file changed

+5
-1
lines changed
  • python/upgrades/f635b392038a494915307f913657cd3058f9b476

1 file changed

+5
-1
lines changed

python/upgrades/f635b392038a494915307f913657cd3058f9b476/py_exprs.ql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,15 @@ where
139139
newidx = oldidx + count(callable.getInnerScope().getArg(_)) - count(args.getDefault(_))
140140
)
141141
or
142-
// expr is a default for a keyword-only parameter
142+
// expr is a default for a keyword-only parameter.
143+
// before this upgrade, we would not always attach the default value to the correct keyword-only parameter,
144+
// to fix this, we calculate the new index based on the source location of the default value (a default value
145+
// must belong to the parameter that was defined immediately before the default value).
143146
exists(Arguments_ args, CallableExprAdjusted callable |
144147
callable.getArgs() = args and
145148
args.getKwDefault(oldidx) = expr and
146149
newidx =
150+
// the last parameter to be defined before this default value
147151
max(int i |
148152
exists(Parameter_ param | param = callable.getInnerScope().getKwonlyarg(i) |
149153
param.getLocation().getStartLine() < expr.getLocation().getStartLine()

0 commit comments

Comments
 (0)