@@ -628,9 +628,6 @@ class PyTypesVisitor(PickleVisitor):
628
628
629
629
def visitModule (self , mod ):
630
630
self .emit ("""
631
- _Py_IDENTIFIER(_fields);
632
- _Py_IDENTIFIER(_attributes);
633
- _Py_IDENTIFIER(index);
634
631
635
632
typedef struct {
636
633
PyObject_HEAD
@@ -666,7 +663,6 @@ def visitModule(self, mod):
666
663
Py_ssize_t i, numfields = 0;
667
664
int res = -1;
668
665
PyObject *key, *value, *fields;
669
- PyObject *index = NULL;
670
666
if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) {
671
667
goto cleanup;
672
668
}
@@ -701,13 +697,10 @@ def visitModule(self, mod):
701
697
}
702
698
if (kw) {
703
699
i = 0; /* needed by PyDict_Next */
704
- if (_PyObject_LookupAttrId(fields, &PyId_index, &index) < 0) {
705
- goto cleanup;
706
- }
707
700
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);
709
702
PyObject* err = PyErr_Occurred();
710
- if (pos == NULL ) {
703
+ if (p == -1 ) {
711
704
// arbitrary keyword arguments are accepted
712
705
if (!PyErr_GivenExceptionMatches(err, PyExc_ValueError)) {
713
706
res = -1;
@@ -716,12 +709,6 @@ def visitModule(self, mod):
716
709
PyErr_Clear();
717
710
}
718
711
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
- }
725
712
if (p < PyTuple_GET_SIZE(args)) {
726
713
PyErr_Format(PyExc_TypeError,
727
714
"%.400s got multiple values for argument '%U'",
@@ -738,7 +725,6 @@ def visitModule(self, mod):
738
725
}
739
726
cleanup:
740
727
Py_XDECREF(fields);
741
- Py_XDECREF(index);
742
728
return res;
743
729
}
744
730
0 commit comments