File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -2646,10 +2646,21 @@ void check_for_doc_string(compiler_t *comp, py_parse_node_t pn) {
2646
2646
2647
2647
// look for the first statement
2648
2648
if (PY_PARSE_NODE_IS_STRUCT_KIND (pn , PN_expr_stmt )) {
2649
- // fall through
2649
+ // a statement; fall through
2650
2650
} else if (PY_PARSE_NODE_IS_STRUCT_KIND (pn , PN_file_input_2 )) {
2651
- pn = ((py_parse_node_struct_t * )pn )-> nodes [0 ];
2651
+ // file input; find the first non-newline node
2652
+ py_parse_node_struct_t * pns = (py_parse_node_struct_t * )pn ;
2653
+ int num_nodes = PY_PARSE_NODE_STRUCT_NUM_NODES (pns );
2654
+ for (int i = 0 ; i < num_nodes ; i ++ ) {
2655
+ pn = pns -> nodes [i ];
2656
+ if (!(PY_PARSE_NODE_IS_LEAF (pn ) && PY_PARSE_NODE_LEAF_KIND (pn ) == PY_PARSE_NODE_TOKEN && PY_PARSE_NODE_LEAF_ARG (pn ) == PY_TOKEN_NEWLINE )) {
2657
+ // not a newline, so this is the first statement; finish search
2658
+ break ;
2659
+ }
2660
+ }
2661
+ // if we didn't find a non-newline then it's okay to fall through; pn will be a newline and so doc-string test below will fail gracefully
2652
2662
} else if (PY_PARSE_NODE_IS_STRUCT_KIND (pn , PN_suite_block_stmts )) {
2663
+ // a list of statements; get the first one
2653
2664
pn = ((py_parse_node_struct_t * )pn )-> nodes [0 ];
2654
2665
} else {
2655
2666
return ;
Original file line number Diff line number Diff line change 6
6
// # single_input is a single interactive statement;
7
7
// # file_input is a module or sequence of commands read from an input file;
8
8
// # eval_input is the input for the eval() functions.
9
- // # NB: compound_stmt in single_input is followed by extra NEWLINE! --> not in Micropython
9
+ // # NB: compound_stmt in single_input is followed by extra NEWLINE! --> not in Micro Python
10
10
// single_input: NEWLINE | simple_stmt | compound_stmt
11
11
// file_input: (NEWLINE | stmt)* ENDMARKER
12
12
// eval_input: testlist NEWLINE* ENDMARKER
You can’t perform that action at this time.
0 commit comments