@@ -1151,9 +1151,6 @@ compiler_enter_scope(struct compiler *c, identifier name, int scope_type,
1151
1151
}
1152
1152
ADDOP_I (c , loc , RESUME , RESUME_AT_FUNC_START );
1153
1153
1154
- if (u -> u_scope_type == COMPILER_SCOPE_MODULE ) {
1155
- loc .lineno = -1 ;
1156
- }
1157
1154
return SUCCESS ;
1158
1155
}
1159
1156
@@ -1459,15 +1456,6 @@ compiler_leave_annotations_scope(struct compiler *c, location loc,
1459
1456
static int
1460
1457
compiler_body (struct compiler * c , location loc , asdl_stmt_seq * stmts )
1461
1458
{
1462
-
1463
- /* Set current line number to the line number of first statement.
1464
- This way line number for SETUP_ANNOTATIONS will always
1465
- coincide with the line number of first "real" statement in module.
1466
- If body is empty, then lineno will be set later in optimize_and_assemble. */
1467
- if (c -> u -> u_scope_type == COMPILER_SCOPE_MODULE && asdl_seq_LEN (stmts )) {
1468
- stmt_ty st = (stmt_ty )asdl_seq_GET (stmts , 0 );
1469
- loc = LOC (st );
1470
- }
1471
1459
/* If from __future__ import annotations is active,
1472
1460
* every annotated class and module should have __annotations__.
1473
1461
* Else __annotate__ is created when necessary. */
@@ -1545,31 +1533,51 @@ compiler_body(struct compiler *c, location loc, asdl_stmt_seq *stmts)
1545
1533
return SUCCESS ;
1546
1534
}
1547
1535
1536
+ static location
1537
+ start_location (asdl_stmt_seq * stmts )
1538
+ {
1539
+ if (asdl_seq_LEN (stmts ) > 0 ) {
1540
+ /* Set current line number to the line number of first statement.
1541
+ * This way line number for SETUP_ANNOTATIONS will always
1542
+ * coincide with the line number of first "real" statement in module.
1543
+ * If body is empty, then lineno will be set later in optimize_and_assemble.
1544
+ */
1545
+ stmt_ty st = (stmt_ty )asdl_seq_GET (stmts , 0 );
1546
+ return LOC (st );
1547
+ }
1548
+ return LOCATION (1 , 1 , 0 , 0 );
1549
+ }
1550
+
1548
1551
static int
1549
1552
compiler_codegen (struct compiler * c , mod_ty mod )
1550
1553
{
1551
- location loc = LOCATION ( 1 , 1 , 0 , 0 );
1554
+ assert ( c -> u -> u_scope_type == COMPILER_SCOPE_MODULE );
1552
1555
switch (mod -> kind ) {
1553
- case Module_kind :
1554
- if (compiler_body (c , loc , mod -> v .Module .body ) < 0 ) {
1556
+ case Module_kind : {
1557
+ asdl_stmt_seq * stmts = mod -> v .Module .body ;
1558
+ if (compiler_body (c , start_location (stmts ), stmts ) < 0 ) {
1555
1559
return ERROR ;
1556
1560
}
1557
1561
break ;
1558
- case Interactive_kind :
1562
+ }
1563
+ case Interactive_kind : {
1559
1564
c -> c_interactive = 1 ;
1560
- if (compiler_body (c , loc , mod -> v .Interactive .body ) < 0 ) {
1565
+ asdl_stmt_seq * stmts = mod -> v .Interactive .body ;
1566
+ if (compiler_body (c , start_location (stmts ), stmts ) < 0 ) {
1561
1567
return ERROR ;
1562
1568
}
1563
1569
break ;
1564
- case Expression_kind :
1570
+ }
1571
+ case Expression_kind : {
1565
1572
VISIT (c , expr , mod -> v .Expression .body );
1566
1573
break ;
1567
- default :
1574
+ }
1575
+ default : {
1568
1576
PyErr_Format (PyExc_SystemError ,
1569
1577
"module kind %d should not be possible" ,
1570
1578
mod -> kind );
1571
1579
return ERROR ;
1572
- }
1580
+ }}
1573
1581
return SUCCESS ;
1574
1582
}
1575
1583
0 commit comments