-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
bpo-29622: make AST constructor accepts less than enough number of positional arguments #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -551,29 +551,27 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw) | |
if (numfields == -1) | ||
goto cleanup; | ||
} | ||
|
||
res = 0; /* if no error occurs, this stays 0 to the end */ | ||
if (PyTuple_GET_SIZE(args) > 0) { | ||
if (numfields != PyTuple_GET_SIZE(args)) { | ||
PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s" | ||
"%zd positional argument%s", | ||
Py_TYPE(self)->tp_name, | ||
numfields == 0 ? "" : "either 0 or ", | ||
numfields, numfields == 1 ? "" : "s"); | ||
if (numfields < PyTuple_GET_SIZE(args)) { | ||
PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " | ||
"%zd positional argument%s", | ||
Py_TYPE(self)->tp_name, | ||
numfields, numfields == 1 ? "" : "s"); | ||
res = -1; | ||
goto cleanup; | ||
} | ||
for (i = 0; i < PyTuple_GET_SIZE(args); i++) { | ||
/* cannot be reached when fields is NULL */ | ||
PyObject *name = PySequence_GetItem(fields, i); | ||
if (!name) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. out of curiosity what's the prefered python style There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't care about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I saw. It was a genuine question like if you are coding something new, what's the prefered style in the CPython codebase? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://www.python.org/dev/peps/pep-0007/ |
||
res = -1; | ||
goto cleanup; | ||
} | ||
for (i = 0; i < PyTuple_GET_SIZE(args); i++) { | ||
/* cannot be reached when fields is NULL */ | ||
PyObject *name = PySequence_GetItem(fields, i); | ||
if (!name) { | ||
res = -1; | ||
goto cleanup; | ||
} | ||
res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); | ||
Py_DECREF(name); | ||
if (res < 0) | ||
goto cleanup; | ||
} | ||
res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); | ||
Py_DECREF(name); | ||
if (res < 0) | ||
goto cleanup; | ||
} | ||
if (kw) { | ||
i = 0; /* needed by PyDict_Next */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep these and change to assertNotRaises ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, too late, that was merged while I was reviewing :-)