← Back to DAGDA | Support | Source: https://github.com/python/cpython/pull/5927/commits/4e11dd218254f53eb10521fadb6d188655529914
Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update based on PR comments.
  • Loading branch information
methane committed Mar 6, 2018
commit 4e11dd218254f53eb10521fadb6d188655529914
8 changes: 4 additions & 4 deletions Python/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ PyAST_FromNodeObject(const node *n, PyCompilerFlags *flags,
}
}
}
if (docstring_from_stmts(stmts, arena) < 0) {
if (!docstring_from_stmts(stmts, arena)) {
goto out;
}
res = Module(stmts, arena);
Expand Down Expand Up @@ -3536,12 +3536,12 @@ docstring_from_stmts(asdl_seq *stmts, PyArena *arena)
s->v.Expr.value->lineno,
s->v.Expr.value->col_offset, arena);
if (doc == NULL) {
return -1;
return 0;
}
asdl_seq_SET(stmts, 0, doc);
}
}
return 0;
return 1;
}

static asdl_seq *
Expand All @@ -3551,7 +3551,7 @@ ast_for_body(struct compiling *c, const node *n)
if (stmts == NULL) {
return NULL;
}
if (docstring_from_stmts(stmts, c->c_arena) < 0) {
if (!docstring_from_stmts(stmts, c->c_arena)) {
return NULL;
}
return stmts;
Expand Down
1 change: 0 additions & 1 deletion Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,6 @@ compiler_body(struct compiler *c, asdl_seq *stmts)
}
if (!asdl_seq_LEN(stmts))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move this to the bottom of this function?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be before asdl_seq_GET.
And this code is copied back from 3.6. (There are extra blank line, I'll remove it)

cpython/Python/compile.c

Lines 1457 to 1459 in baa4507

if (!asdl_seq_LEN(stmts))
return 1;
st = (stmt_ty)asdl_seq_GET(stmts, 0);

return 1;

st = (stmt_ty)asdl_seq_GET(stmts, 0);
/* if not -OO mode, set docstring */
if (st->kind == DocString_kind && c->c_optimize < 2) {
Expand Down
3 changes: 1 addition & 2 deletions Tools/parser/unparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ def _Expr(self, tree):
self.dispatch(tree.value)

def _DocString(self, t):
self.fill()
self.write(repr(t.s))
self.fill(repr(t.s))

def _Import(self, t):
self.fill("import ")
Expand Down