Skip to content

Commit edc202c

Browse files
committed
bpo-29622: loosen positional argument check of AST constructor
1 parent cb41b27 commit edc202c

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

Parser/asdl_c.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -666,11 +666,10 @@ def visitModule(self, mod):
666666
}
667667
res = 0; /* if no error occurs, this stays 0 to the end */
668668
if (PyTuple_GET_SIZE(args) > 0) {
669-
if (numfields != PyTuple_GET_SIZE(args)) {
670-
PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s"
669+
if (numfields < PyTuple_GET_SIZE(args)) {
670+
PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
671671
"%zd positional argument%s",
672672
Py_TYPE(self)->tp_name,
673-
numfields == 0 ? "" : "either 0 or ",
674673
numfields, numfields == 1 ? "" : "s");
675674
res = -1;
676675
goto cleanup;

Python/Python-ast.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,11 +553,10 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
553553
}
554554
res = 0; /* if no error occurs, this stays 0 to the end */
555555
if (PyTuple_GET_SIZE(args) > 0) {
556-
if (numfields != PyTuple_GET_SIZE(args)) {
557-
PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s"
556+
if (numfields < PyTuple_GET_SIZE(args)) {
557+
PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
558558
"%zd positional argument%s",
559559
Py_TYPE(self)->tp_name,
560-
numfields == 0 ? "" : "either 0 or ",
561560
numfields, numfields == 1 ? "" : "s");
562561
res = -1;
563562
goto cleanup;

0 commit comments

Comments
 (0)