diff options
author | Brandt Bucher <brandt@python.org> | 2021-04-30 00:19:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-30 00:19:28 (GMT) |
commit | dbe60ee09dc5a624cfb78dff61ecf050a5b3f105 (patch) | |
tree | cb0850e50916b666879770be4fb42b473db357e8 /Parser/pegen.c | |
parent | 87655e2cf58c543914ea05ebe5a0377441da1ef2 (diff) | |
download | cpython-dbe60ee09dc5a624cfb78dff61ecf050a5b3f105.zip cpython-dbe60ee09dc5a624cfb78dff61ecf050a5b3f105.tar.gz cpython-dbe60ee09dc5a624cfb78dff61ecf050a5b3f105.tar.bz2 |
bpo-43892: Validate the first term of complex literal value patterns (GH-25735)
Diffstat (limited to 'Parser/pegen.c')
-rw-r--r-- | Parser/pegen.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Parser/pegen.c b/Parser/pegen.c index 4d6e69e..e32b271 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -2352,7 +2352,17 @@ expr_ty _PyPegen_ensure_imaginary(Parser *p, expr_ty exp) { if (exp->kind != Constant_kind || !PyComplex_CheckExact(exp->v.Constant.value)) { - RAISE_SYNTAX_ERROR_KNOWN_LOCATION(exp, "Imaginary number required in complex literal"); + RAISE_SYNTAX_ERROR_KNOWN_LOCATION(exp, "imaginary number required in complex literal"); + return NULL; + } + return exp; +} + +expr_ty +_PyPegen_ensure_real(Parser *p, expr_ty exp) +{ + if (exp->kind != Constant_kind || PyComplex_CheckExact(exp->v.Constant.value)) { + RAISE_SYNTAX_ERROR_KNOWN_LOCATION(exp, "real number required in complex literal"); return NULL; } return exp; |