diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-09-27 14:42:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-27 14:42:37 (GMT) |
commit | 3f22811fef73aec848d961593d95fa877f77ecbf (patch) | |
tree | 025ca176b2993e8d85a0961f994794c3f9801032 /Python/ast_unparse.c | |
parent | a94ee12c26aa8dd7dce01373779df8055aff765b (diff) | |
download | cpython-3f22811fef73aec848d961593d95fa877f77ecbf.zip cpython-3f22811fef73aec848d961593d95fa877f77ecbf.tar.gz cpython-3f22811fef73aec848d961593d95fa877f77ecbf.tar.bz2 |
bpo-32892: Use ast.Constant instead of specific constant AST types. (GH-9445)
Diffstat (limited to 'Python/ast_unparse.c')
-rw-r--r-- | Python/ast_unparse.c | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/Python/ast_unparse.c b/Python/ast_unparse.c index 725ce31..56ea3c4 100644 --- a/Python/ast_unparse.c +++ b/Python/ast_unparse.c @@ -567,8 +567,6 @@ append_fstring_element(_PyUnicodeWriter *writer, expr_ty e, bool is_format_spec) switch (e->kind) { case Constant_kind: return append_fstring_unicode(writer, e->v.Constant.value); - case Str_kind: - return append_fstring_unicode(writer, e->v.Str.s); case JoinedStr_kind: return append_joinedstr(writer, e, is_format_spec); case FormattedValue_kind: @@ -690,13 +688,12 @@ static int append_ast_attribute(_PyUnicodeWriter *writer, expr_ty e) { const char *period; - APPEND_EXPR(e->v.Attribute.value, PR_ATOM); + expr_ty v = e->v.Attribute.value; + APPEND_EXPR(v, PR_ATOM); /* Special case: integers require a space for attribute access to be - unambiguous. Floats and complex numbers don't but work with it, too. */ - if (e->v.Attribute.value->kind == Num_kind || - e->v.Attribute.value->kind == Constant_kind) - { + unambiguous. */ + if (v->kind == Constant_kind && PyLong_CheckExact(v->v.Constant.value)) { period = " ."; } else { @@ -841,21 +838,14 @@ append_ast_expr(_PyUnicodeWriter *writer, expr_ty e, int level) case Call_kind: return append_ast_call(writer, e); case Constant_kind: + if (e->v.Constant.value == Py_Ellipsis) { + APPEND_STR_FINISH("..."); + } return append_repr(writer, e->v.Constant.value); - case Num_kind: - return append_repr(writer, e->v.Num.n); - case Str_kind: - return append_repr(writer, e->v.Str.s); case JoinedStr_kind: return append_joinedstr(writer, e, false); case FormattedValue_kind: return append_formattedvalue(writer, e, false); - case Bytes_kind: - return append_repr(writer, e->v.Bytes.s); - case Ellipsis_kind: - APPEND_STR_FINISH("..."); - case NameConstant_kind: - return append_repr(writer, e->v.NameConstant.value); /* The following exprs can be assignment targets. */ case Attribute_kind: return append_ast_attribute(writer, e); |