summaryrefslogtreecommitdiff
path: root/Python/compile.c
diff options
context:
space:
mode:
authorZackery Spytz <zspytz@gmail.com>2019-08-25 03:44:09 -0600
committerSerhiy Storchaka <storchaka@gmail.com>2019-08-25 12:44:09 +0300
commitce6a070414ed1e1374d1e6212bfbff61b6d5d755 (patch)
tree55f9d0c54b98ad3c95e78a235668f6dbc314087b /Python/compile.c
parent8371799e300475c8f9f967e900816218d3500e5d (diff)
downloadcpython-git-ce6a070414ed1e1374d1e6212bfbff61b6d5d755.tar.gz
bpo-34880: Add the LOAD_ASSERTION_ERROR opcode. (GH-15073)
Fix assert statement misbehavior if AssertionError is shadowed.
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 1bf05e2913..edd8625cba 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1129,6 +1129,8 @@ stack_effect(int opcode, int oparg, int jump)
return (oparg & FVS_MASK) == FVS_HAVE_SPEC ? -1 : 0;
case LOAD_METHOD:
return 1;
+ case LOAD_ASSERTION_ERROR:
+ return 1;
default:
return PY_INVALID_STACK_EFFECT;
}
@@ -3253,16 +3255,10 @@ compiler_from_import(struct compiler *c, stmt_ty s)
static int
compiler_assert(struct compiler *c, stmt_ty s)
{
- static PyObject *assertion_error = NULL;
basicblock *end;
if (c->c_optimize)
return 1;
- if (assertion_error == NULL) {
- assertion_error = PyUnicode_InternFromString("AssertionError");
- if (assertion_error == NULL)
- return 0;
- }
if (s->v.Assert.test->kind == Tuple_kind &&
asdl_seq_LEN(s->v.Assert.test->v.Tuple.elts) > 0)
{
@@ -3277,7 +3273,7 @@ compiler_assert(struct compiler *c, stmt_ty s)
return 0;
if (!compiler_jump_if(c, s->v.Assert.test, end, 1))
return 0;
- ADDOP_O(c, LOAD_GLOBAL, assertion_error, names);
+ ADDOP(c, LOAD_ASSERTION_ERROR);
if (s->v.Assert.msg) {
VISIT(c, expr, s->v.Assert.msg);
ADDOP_I(c, CALL_FUNCTION, 1);