Skip to content

Commit 10cd875

Browse files
committed
Look for common iterable types, not iterator types
1 parent 2dfa47c commit 10cd875

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

Python/specialize.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3119,8 +3119,41 @@ _Py_Specialize_ContainsOp(_PyStackRef value_st, _Py_CODEUNIT *instr)
31193119
void
31203120
_Py_GatherStats_GetIter(_PyStackRef iterable)
31213121
{
3122-
PyObject *obj = PyStackRef_AsPyObjectBorrow(iterable);
3123-
int kind = _PySpecialization_ClassifyIterator(obj);
3122+
PyTypeObject *tp = PyStackRef_TYPE(iterable);
3123+
int kind = SPEC_FAIL_OTHER;
3124+
if (tp == &PyTuple_Type) {
3125+
kind = SPEC_FAIL_ITER_TUPLE;
3126+
}
3127+
else if (tp == &PyList_Type) {
3128+
kind = SPEC_FAIL_ITER_LIST;
3129+
}
3130+
else if (tp == &PyDict_Type) {
3131+
kind = SPEC_FAIL_ITER_DICT_KEYS;
3132+
}
3133+
else if (tp == &PySet_Type) {
3134+
kind = SPEC_FAIL_ITER_SET;
3135+
}
3136+
else if (tp == &PyBytes_Type) {
3137+
kind = SPEC_FAIL_ITER_BYTES;
3138+
}
3139+
else if (tp == &PyEnum_Type) {
3140+
kind = SPEC_FAIL_ITER_ENUMERATE;
3141+
}
3142+
else if (tp == &PyUnicode_Type) {
3143+
kind = SPEC_FAIL_ITER_STRING;
3144+
}
3145+
else if (tp == &PyGen_Type) {
3146+
kind = SPEC_FAIL_ITER_GENERATOR;
3147+
}
3148+
else if (tp == &PyCoro_Type) {
3149+
kind = SPEC_FAIL_ITER_COROUTINE;
3150+
}
3151+
else if (tp == &PyAsyncGen_Type) {
3152+
kind = SPEC_FAIL_ITER_ASYNC_GENERATOR;
3153+
}
3154+
else if (tp == &_PyAsyncGenASend_Type) {
3155+
kind = SPEC_FAIL_ITER_ASYNC_GENERATOR_SEND;
3156+
}
31243157
SPECIALIZATION_FAIL(GET_ITER, kind);
31253158
}
31263159
#endif

0 commit comments

Comments
 (0)