@@ -95,7 +95,7 @@ var AnnotationRules = On(Any).Self(
9595 On (Not (HasInternalType (pyast .Module ))).Error (errors .New ("root must be Module" )),
9696 On (HasInternalType (pyast .Module )).Roles (File ).Descendants (
9797 // Binary Expressions
98- On (HasInternalType (pyast .BinOp )).Roles (BinaryExpression ).Children (
98+ On (HasInternalType (pyast .BinOp )).Roles (BinaryExpression , Expression ).Children (
9999 On (HasInternalRole ("op" )).Roles (BinaryExpressionOp ),
100100 On (HasInternalRole ("left" )).Roles (BinaryExpressionLeft ),
101101 On (HasInternalRole ("right" )).Roles (BinaryExpressionRight ),
@@ -143,23 +143,23 @@ var AnnotationRules = On(Any).Self(
143143 On (HasInternalType (pyast .UAdd )).Roles (OpPositive ),
144144 On (HasInternalType (pyast .USub )).Roles (OpNegative ),
145145
146- On (HasInternalType (pyast .StringLiteral )).Roles (StringLiteral ),
147- On (HasInternalType (pyast .ByteLiteral )).Roles (ByteStringLiteral ),
148- On (HasInternalType (pyast .NumLiteral )).Roles (NumberLiteral ),
149- On (HasInternalType (pyast .Str )).Roles (StringLiteral ),
150- On (HasInternalType (pyast .BoolLiteral )).Roles (BooleanLiteral ),
151- On (HasInternalType (pyast .JoinedStr )).Roles (StringLiteral ).Children (
146+ On (HasInternalType (pyast .StringLiteral )).Roles (StringLiteral , Expression ),
147+ On (HasInternalType (pyast .ByteLiteral )).Roles (ByteStringLiteral , Expression ),
148+ On (HasInternalType (pyast .NumLiteral )).Roles (NumberLiteral , Expression ),
149+ On (HasInternalType (pyast .Str )).Roles (StringLiteral , Expression ),
150+ On (HasInternalType (pyast .BoolLiteral )).Roles (BooleanLiteral , Expression ),
151+ On (HasInternalType (pyast .JoinedStr )).Roles (StringLiteral , Expression ).Children (
152152 // FIXME: should be StringInterpolatedExpression or something like that
153153 On (HasInternalType (pyast .FormattedValue )).Roles (Expression ),
154154 ),
155- On (HasInternalType (pyast .NoneLiteral )).Roles (NullLiteral ),
156- On (HasInternalType (pyast .Set )).Roles (SetLiteral ),
157- On (HasInternalType (pyast .List )).Roles (ListLiteral ),
158- On (HasInternalType (pyast .Dict )).Roles (MapLiteral ).Children (
155+ On (HasInternalType (pyast .NoneLiteral )).Roles (NullLiteral , Expression ),
156+ On (HasInternalType (pyast .Set )).Roles (SetLiteral , Expression ),
157+ On (HasInternalType (pyast .List )).Roles (ListLiteral , Expression ),
158+ On (HasInternalType (pyast .Dict )).Roles (MapLiteral , Expression ).Children (
159159 On (HasInternalRole ("keys" )).Roles (MapKey ),
160160 On (HasInternalRole ("values" )).Roles (MapValue ),
161161 ),
162- On (HasInternalType (pyast .Tuple )).Roles (TupleLiteral ),
162+ On (HasInternalType (pyast .Tuple )).Roles (TupleLiteral , Expression ),
163163
164164 // FIXME: decorators
165165 // FIXME: the FunctionDeclarationReceiver is not set for methods; it should be taken from the parent
@@ -186,7 +186,7 @@ var AnnotationRules = On(Any).Self(
186186 ),
187187 ),
188188
189- On (HasInternalType (pyast .Call )).Roles (Call ).Children (
189+ On (HasInternalType (pyast .Call )).Roles (Call , Expression ).Children (
190190 On (HasInternalRole ("args" )).Roles (CallPositionalArgument ),
191191 On (HasInternalRole ("keywords" )).Roles (CallNamedArgument ).Children (
192192 On (HasInternalRole ("value" )).Roles (CallNamedArgumentValue ),
@@ -203,21 +203,21 @@ var AnnotationRules = On(Any).Self(
203203 // targets[] => AssignmentVariable
204204 // value => AssignmentValue
205205 //
206- On (HasInternalType (pyast .Assign )).Roles (Assignment ).Children (
206+ On (HasInternalType (pyast .Assign )).Roles (Assignment , Statement ).Children (
207207 On (HasInternalRole ("targets" )).Roles (AssignmentVariable ),
208208 On (HasInternalRole ("value" )).Roles (AssignmentValue ),
209209 ),
210210
211- On (HasInternalType (pyast .AugAssign )).Roles (AugmentedAssignment ).Children (
211+ On (HasInternalType (pyast .AugAssign )).Roles (AugmentedAssignment , Statement ).Children (
212212 On (HasInternalRole ("op" )).Roles (AugmentedAssignmentOperator ),
213213 On (HasInternalRole ("target" )).Roles (AugmentedAssignmentVariable ),
214214 On (HasInternalRole ("value" )).Roles (AugmentedAssignmentValue ),
215215 ),
216216
217217 On (HasInternalType (pyast .Expression )).Roles (Expression ),
218218 On (HasInternalType (pyast .Expr )).Roles (Expression ),
219- On (HasInternalType (pyast .Name )).Roles (SimpleIdentifier ),
220- On (HasInternalType (pyast .Attribute )).Roles (QualifiedIdentifier ),
219+ On (HasInternalType (pyast .Name )).Roles (SimpleIdentifier , Expression ),
220+ On (HasInternalType (pyast .Attribute )).Roles (QualifiedIdentifier , Expression ),
221221
222222 // Comments and non significative whitespace
223223 On (HasInternalType (pyast .SameLineNoops )).Roles (Comment ),
@@ -229,24 +229,24 @@ var AnnotationRules = On(Any).Self(
229229 ),
230230
231231 // TODO: check what Constant nodes are generated in the python AST and improve this
232- On (HasInternalType (pyast .Constant )).Roles (SimpleIdentifier ),
233- On (HasInternalType (pyast .Try )).Roles (Try ).Children (
232+ On (HasInternalType (pyast .Constant )).Roles (SimpleIdentifier , Expression ),
233+ On (HasInternalType (pyast .Try )).Roles (Try , Statement ).Children (
234234 On (HasInternalRole ("body" )).Roles (TryBody ),
235235 On (HasInternalRole ("finalbody" )).Roles (TryFinally ),
236236 On (HasInternalRole ("handlers" )).Roles (TryCatch ),
237237 On (HasInternalRole ("orelse" )).Roles (IfElse ),
238238 ),
239- On (HasInternalType (pyast .TryExcept )).Roles (TryCatch ), // py2
240- On (HasInternalType (pyast .ExceptHandler )).Roles (TryCatch ), // py3
241- On (HasInternalType (pyast .TryFinally )).Roles (TryFinally ),
242- On (HasInternalType (pyast .Raise )).Roles (Throw ),
239+ On (HasInternalType (pyast .TryExcept )).Roles (TryCatch , Statement ), // py2
240+ On (HasInternalType (pyast .ExceptHandler )).Roles (TryCatch , Statement ), // py3
241+ On (HasInternalType (pyast .TryFinally )).Roles (TryFinally , Statement ),
242+ On (HasInternalType (pyast .Raise )).Roles (Throw , Statement ),
243243 // FIXME: review, add path for the body and items childs
244244 // FIXME: withitem on Python to RAII on a resource and can aditionally create and alias on it,
245245 // both of which currently doesn't have representation in the UAST
246- On (HasInternalType (pyast .With )).Roles (BlockScope ),
247- On (HasInternalType (pyast .Return )).Roles (Return ),
248- On (HasInternalType (pyast .Break )).Roles (Break ),
249- On (HasInternalType (pyast .Continue )).Roles (Continue ),
246+ On (HasInternalType (pyast .With )).Roles (BlockScope , Statement ),
247+ On (HasInternalType (pyast .Return )).Roles (Return , Statement ),
248+ On (HasInternalType (pyast .Break )).Roles (Break , Statement ),
249+ On (HasInternalType (pyast .Continue )).Roles (Continue , Statement ),
250250 // FIXME: IfCondition bodies in Python take the form:
251251 // 1 < a < 10
252252 // - left (internalRole): 1 (first element)
@@ -260,60 +260,58 @@ var AnnotationRules = On(Any).Self(
260260 // and SDK feature to mix lists (also needed for default and keyword arguments and
261261 // boolean operators).
262262 // "If that sounds awkward is because it is" (their words)
263- On (HasInternalType (pyast .If )).Roles (If ).Children (
263+ On (HasInternalType (pyast .If )).Roles (If , Statement ).Children (
264264 On (HasInternalType ("If.body" )).Roles (IfBody ),
265265 On (HasInternalRole ("test" )).Roles (IfCondition ),
266266 On (HasInternalType ("If.orelse" )).Roles (IfElse ),
267- On (HasInternalType (pyast .Compare )).Roles (BinaryExpression ).Children (
267+ On (HasInternalType (pyast .Compare )).Roles (BinaryExpression , Expression ).Children (
268268 On (HasInternalType ("Compare.ops" )).Roles (BinaryExpressionOp ),
269269 On (HasInternalType ("Compare.comparators" )).Roles (BinaryExpressionRight ),
270270 On (HasInternalRole ("left" )).Roles (BinaryExpressionLeft ),
271271 ),
272272 ),
273- On (HasInternalType (pyast .IfExp )).Roles (If , Expression ).Children (
273+ On (HasInternalType (pyast .IfExp )).Roles (If , Expression , Statement ).Children (
274274 // These are used on ifexpressions (a = 1 if x else 2)
275275 On (HasInternalRole ("body" )).Roles (IfBody ),
276276 On (HasInternalRole ("test" )).Roles (IfCondition ),
277277 On (HasInternalRole ("orelse" )).Roles (IfElse ),
278278 ),
279- // One liner if, like a normal If but it will be inside an Assign (like the ternary if in C)
280- On (HasInternalType (pyast .IfExp )).Roles (If ),
281- On (HasInternalType (pyast .Import )).Roles (ImportDeclaration ),
282- On (HasInternalType (pyast .ImportFrom )).Roles (ImportDeclaration ),
279+ On (HasInternalType (pyast .Import )).Roles (ImportDeclaration , Statement ),
280+ On (HasInternalType (pyast .ImportFrom )).Roles (ImportDeclaration , Statement ),
283281 On (HasInternalType (pyast .Alias )).Roles (ImportAlias , SimpleIdentifier ),
284- On (HasInternalType (pyast .ClassDef )).Roles (TypeDeclaration , SimpleIdentifier ).Children (
282+ On (HasInternalType (pyast .ClassDef )).Roles (TypeDeclaration , SimpleIdentifier , Statement ).Children (
285283 On (HasInternalType ("ClassDef.body" )).Roles (TypeDeclarationBody ),
286284 On (HasInternalType ("ClassDef.bases" )).Roles (TypeDeclarationBases ),
287285 ),
288286
289- On (HasInternalType (pyast .For )).Roles (ForEach ).Children (
287+ On (HasInternalType (pyast .For )).Roles (ForEach , Statement ).Children (
290288 On (HasInternalType ("For.body" )).Roles (ForBody ),
291289 On (HasInternalRole ("iter" )).Roles (ForExpression ),
292290 On (HasInternalRole ("target" )).Roles (ForUpdate ),
293291 On (HasInternalType ("For.orelse" )).Roles (IfElse ),
294292 ),
295- On (HasInternalType (pyast .While )).Roles (While ).Children (
293+ On (HasInternalType (pyast .While )).Roles (While , Statement ).Children (
296294 On (HasInternalType ("While.body" )).Roles (WhileBody ),
297295 On (HasInternalRole ("test" )).Roles (WhileCondition ),
298296 On (HasInternalType ("While.orelse" )).Roles (IfElse ),
299297 ),
300- On (HasInternalType (pyast .Pass )).Roles (Noop ),
301- On (HasInternalType (pyast .Num )).Roles (NumberLiteral ),
298+ On (HasInternalType (pyast .Pass )).Roles (Noop , Statement ),
299+ On (HasInternalType (pyast .Num )).Roles (NumberLiteral , Expression ),
302300 // FIXME: this is the annotated assignment (a: annotation = 3) not exactly Assignment
303301 // it also lacks AssignmentValue and AssignmentVariable (see how to add them)
304- On (HasInternalType (pyast .AnnAssign )).Roles (Assignment ),
305- On (HasInternalType (pyast .Assert )).Roles (Assert ),
302+ On (HasInternalType (pyast .AnnAssign )).Roles (Assignment , Statement ),
303+ On (HasInternalType (pyast .Assert )).Roles (Assert , Statement ),
306304
307305 // These are AST nodes in Python2 but we convert them to functions in the UAST like
308306 // they are in Python3
309- On (HasInternalType (pyast .Exec )).Roles (Call ).Children (
307+ On (HasInternalType (pyast .Exec )).Roles (Call , Expression ).Children (
310308 On (HasInternalRole ("body" )).Roles (CallPositionalArgument ),
311309 On (HasInternalRole ("globals" )).Roles (CallPositionalArgument ),
312310 On (HasInternalRole ("locals" )).Roles (CallPositionalArgument ),
313311 ),
314312 // Repr already comes as a Call \o/
315313 // Print as a function too.
316- On (HasInternalType (pyast .Print )).Roles (Call , CallCallee , SimpleIdentifier ).Children (
314+ On (HasInternalType (pyast .Print )).Roles (Call , CallCallee , SimpleIdentifier , Expression ).Children (
317315 On (HasInternalRole ("dest" )).Roles (CallPositionalArgument ),
318316 On (HasInternalRole ("nl" )).Roles (CallPositionalArgument ),
319317 On (HasInternalRole ("values" )).Roles (CallPositionalArgument ).Children (
@@ -336,8 +334,8 @@ var AnnotationRules = On(Any).Self(
336334 // List/Map/Set comprehensions. We map the "for x in y" to ForEach roles and the
337335 // "if something" to If* roles. FIXME: missing the top comprehension roles in the UAST, change
338336 // once they've been merged
339- On (HasInternalType (pyast .Comprehension )).Roles (ForEach ).Children (
340- On (HasInternalRole ("iter" )).Roles (ForUpdate ),
337+ On (HasInternalType (pyast .Comprehension )).Roles (ForEach , Expression ).Children (
338+ On (HasInternalRole ("iter" )).Roles (ForUpdate , Statement ),
341339 On (HasInternalRole ("target" )).Roles (ForExpression ),
342340 // FIXME: see the comment on IfCondition above
343341 On (HasInternalType (pyast .Compare )).Roles (IfCondition , BinaryExpression ).Children (
0 commit comments