bpo-43892: Validate the first term of complex literal value patterns (GH-25735)
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 @@
_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;