--- Python/compile.c~ +++ /Python/compile.c @@ -3407,6 +3407,24 @@ expr_constant(expr_ty e) { PyBuiltinConstant* ptr; switch (e->kind) { + case BoolOp_kind: + if (e->v.BoolOp.values != NULL && e->v.BoolOp.values->size >= 1) { + int cst = expr_constant((expr_ty)(e->v.BoolOp.values->elements[0])); + if (e->v.BoolOp.op == And && cst == 0) { + return 0; + } + else if (e->v.BoolOp.op == Or && cst == 1) { + return 1; + } + } + return -1; + case UnaryOp_kind: + if (e->v.UnaryOp.op == Not) { + int cst = expr_constant(e->v.UnaryOp.operand); + if (cst == 0 || cst == 1) + return !cst; + } + return -1; case Num_kind: return PyObject_IsTrue(e->v.Num.n); case Str_kind: