bpo-43892: Validate the first term of complex literal value patterns (GH-25735)

This commit is contained in:
Brandt Bucher 2021-04-29 17:19:28 -07:00 committed by GitHub
parent 87655e2cf5
commit dbe60ee09d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 595 additions and 441 deletions

View file

@ -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;