@@ -273,7 +273,7 @@ public PNode visit(AndSSTNode node) {
273
273
274
274
@ Override
275
275
public PNode visit (AnnAssignmentSSTNode node ) {
276
- PNode assignmentNode = createAssignment (node , true );
276
+ PNode assignmentNode = createAssignment (node );
277
277
if (!scopeEnvironment .isInFunctionScope () && node .type != null && node .lhs .length == 1 && node .lhs [0 ] instanceof VarLookupSSTNode ) {
278
278
// annotations in a function we ignore at all. Even there are not evalueated, whether
279
279
// the type is wrong
@@ -301,25 +301,16 @@ public PNode visit(AssertSSTNode node) {
301
301
302
302
@ Override
303
303
public PNode visit (AssignmentSSTNode node ) {
304
- return createAssignment (node , false );
304
+ return createAssignment (node );
305
305
}
306
306
307
- public StatementNode createAssignment (AssignmentSSTNode node , boolean checkAnnotationPermitted ) {
307
+ private StatementNode createAssignment (AssignmentSSTNode node ) {
308
308
ExpressionNode [] lhs = new ExpressionNode [node .lhs .length ];
309
309
int numYields = getCurrentNumberOfYields ();
310
310
for (int i = 0 ; i < node .lhs .length ; i ++) {
311
311
SSTNode sstLhs = node .lhs [i ];
312
312
checkCannotAssignTo (sstLhs );
313
313
lhs [i ] = (ExpressionNode ) sstLhs .accept (this );
314
- if (checkAnnotationPermitted ) {
315
- if (lhs [i ] instanceof TupleLiteralNode ) {
316
- throw errors .raiseInvalidSyntax (source , createSourceSection (sstLhs .getStartOffset (), sstLhs .getEndOffset ()), ErrorMessages .ONLY_SINGLE_TARGET_CAN_BE_ANNOTATED , "tuple" );
317
- } else if (lhs [i ] instanceof ListLiteralNode ) {
318
- throw errors .raiseInvalidSyntax (source , createSourceSection (sstLhs .getStartOffset (), sstLhs .getEndOffset ()), ErrorMessages .ONLY_SINGLE_TARGET_CAN_BE_ANNOTATED , "list" );
319
- } else if (!(lhs [i ] instanceof ReadNode )) {
320
- throw errors .raiseInvalidSyntax (source , createSourceSection (sstLhs .getStartOffset (), sstLhs .getEndOffset ()), ErrorMessages .ILLEGAL_TARGET_FOR_ANNOTATION );
321
- }
322
- }
323
314
}
324
315
ExpressionNode rhs = (ExpressionNode ) node .rhs .accept (this );
325
316
@@ -361,7 +352,7 @@ private void checkCannotAssignTo(SSTNode lhs) throws RuntimeException {
361
352
if (lhs instanceof ForComprehensionSSTNode ) {
362
353
PythonBuiltinClassType resultType = ((ForComprehensionSSTNode ) lhs ).resultType ;
363
354
if (resultType == PythonBuiltinClassType .PGenerator ) {
364
- throw errors .raiseInvalidSyntax (source , createSourceSection (lhs .startOffset , lhs .endOffset ), "cannot assign to generator expression" );
355
+ throw errors .raiseInvalidSyntax (source , createSourceSection (lhs .startOffset , lhs .endOffset ), ErrorMessages . CANNOT_ASSIGN_TO , " generator expression" );
365
356
}
366
357
String calleeName ;
367
358
switch (resultType ) {
@@ -378,12 +369,12 @@ private void checkCannotAssignTo(SSTNode lhs) throws RuntimeException {
378
369
calleeName = null ;
379
370
}
380
371
if (calleeName == null ) {
381
- throw errors .raiseInvalidSyntax (source , createSourceSection (lhs .startOffset , lhs .endOffset ), "cannot assign to comprehension" );
372
+ throw errors .raiseInvalidSyntax (source , createSourceSection (lhs .startOffset , lhs .endOffset ), ErrorMessages . CANNOT_ASSIGN_TO , " comprehension" );
382
373
} else {
383
- throw errors .raiseInvalidSyntax (source , createSourceSection (lhs .startOffset , lhs .endOffset ), "cannot assign to %s comprehension" , calleeName );
374
+ throw errors .raiseInvalidSyntax (source , createSourceSection (lhs .startOffset , lhs .endOffset ), ErrorMessages . CANNOT_ASSIGN_TO_COMPREHENSION , calleeName );
384
375
}
385
376
} else if (lhs instanceof CallSSTNode ) {
386
- throw errors .raiseInvalidSyntax (source , createSourceSection (lhs .startOffset , lhs .endOffset ), "cannot assign to function call" );
377
+ throw errors .raiseInvalidSyntax (source , createSourceSection (lhs .startOffset , lhs .endOffset ), ErrorMessages . CANNOT_ASSIGN_TO , " function call" );
387
378
} else if (lhs instanceof CollectionSSTNode ) {
388
379
for (SSTNode n : ((CollectionSSTNode ) lhs ).getValues ()) {
389
380
checkCannotAssignTo (n );
0 commit comments