diff -r 27e5437f442c Lib/test/test_ast.py --- a/Lib/test/test_ast.py Tue Jan 26 00:40:57 2016 +0100 +++ b/Lib/test/test_ast.py Tue Jan 26 01:55:38 2016 +0100 @@ -1017,15 +1017,9 @@ class ConstantTests(unittest.TestCase): code = '\n'.join(map(repr, consts)) code += '\n...' - code_consts = [const for const in consts - if (not isinstance(const, (str, int, float, complex)) - or isinstance(const, bool))] - code_consts.append(Ellipsis) - # the compiler adds a final "LOAD_CONST None" - code_consts.append(None) - tree = ast.parse(code) - self.assertEqual(self.get_load_const(tree), code_consts) + self.assertEqual(self.get_load_const(tree), + [(1, 2, 3), None]) # Replace expression nodes with constants for expr_node, const in zip(tree.body, consts): @@ -1034,7 +1028,8 @@ class ConstantTests(unittest.TestCase): ast.copy_location(new_node, expr_node.value) expr_node.value = new_node - self.assertEqual(self.get_load_const(tree), code_consts) + self.assertEqual(self.get_load_const(tree), + [None]) def test_literal_eval(self): tree = ast.parse("1 + 2") diff -r 27e5437f442c Python/compile.c --- a/Python/compile.c Tue Jan 26 00:40:57 2016 +0100 +++ b/Python/compile.c Tue Jan 26 01:55:38 2016 +0100 @@ -2616,20 +2616,19 @@ compiler_visit_stmt_expr(struct compiler return 1; } - if (value->kind == Str_kind || value->kind == Num_kind) { - /* ignore strings and numbers */ + switch (value->kind) + { + case Str_kind: + case Bytes_kind: + case Num_kind: + case NameConstant_kind: + case Ellipsis_kind: + case Constant_kind: + /* ignore constants */ return 1; - } - - if (value->kind == Constant_kind) { - PyObject *cst = value->v.Constant.value; - if (PyUnicode_CheckExact(cst) - || PyLong_CheckExact(cst) - || PyFloat_CheckExact(cst) - || PyComplex_CheckExact(cst)) { - /* ignore strings and numbers */ - return 1; - } + + default: + break; } VISIT(c, expr, value);