mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
bpo-32892: Use ast.Constant instead of specific constant AST types. (GH-9445)
This commit is contained in:
parent
a94ee12c26
commit
3f22811fef
20 changed files with 337 additions and 678 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue