Skip to content

Commit 0d4414c

Browse files
committed
Use PySequence_Index
1 parent 9cb5679 commit 0d4414c

File tree

2 files changed

+4
-32
lines changed

2 files changed

+4
-32
lines changed

Parser/asdl_c.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -628,9 +628,6 @@ class PyTypesVisitor(PickleVisitor):
628628

629629
def visitModule(self, mod):
630630
self.emit("""
631-
_Py_IDENTIFIER(_fields);
632-
_Py_IDENTIFIER(_attributes);
633-
_Py_IDENTIFIER(index);
634631
635632
typedef struct {
636633
PyObject_HEAD
@@ -666,7 +663,6 @@ def visitModule(self, mod):
666663
Py_ssize_t i, numfields = 0;
667664
int res = -1;
668665
PyObject *key, *value, *fields;
669-
PyObject *index = NULL;
670666
if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) {
671667
goto cleanup;
672668
}
@@ -701,13 +697,10 @@ def visitModule(self, mod):
701697
}
702698
if (kw) {
703699
i = 0; /* needed by PyDict_Next */
704-
if (_PyObject_LookupAttrId(fields, &PyId_index, &index) < 0) {
705-
goto cleanup;
706-
}
707700
while (PyDict_Next(kw, &i, &key, &value)) {
708-
PyObject* pos = _PyObject_FastCallDict(index, &key, 1, NULL);
701+
Py_ssize_t p = PySequence_Index(fields, key);
709702
PyObject* err = PyErr_Occurred();
710-
if (pos == NULL) {
703+
if (p == -1) {
711704
// arbitrary keyword arguments are accepted
712705
if (!PyErr_GivenExceptionMatches(err, PyExc_ValueError)) {
713706
res = -1;
@@ -716,12 +709,6 @@ def visitModule(self, mod):
716709
PyErr_Clear();
717710
}
718711
else {
719-
Py_ssize_t p = PyNumber_AsSsize_t(pos, NULL);
720-
Py_DECREF(pos);
721-
if (p == -1 && PyErr_Occurred()) {
722-
res = -1;
723-
goto cleanup;
724-
}
725712
if (p < PyTuple_GET_SIZE(args)) {
726713
PyErr_Format(PyExc_TypeError,
727714
"%.400s got multiple values for argument '%U'",
@@ -738,7 +725,6 @@ def visitModule(self, mod):
738725
}
739726
cleanup:
740727
Py_XDECREF(fields);
741-
Py_XDECREF(index);
742728
return res;
743729
}
744730

Python/Python-ast.c

Lines changed: 2 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)