python
type_error
ai_generated
true
TypeError: cannot unpack non-iterable int object
ID: python/typeerror-cannot-unpack-non-iterable
80%Fix Rate
86%Confidence
0Evidence
2025-02-14First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
Root Cause
A test function returns an integer but the caller tries to unpack it as a tuple or list.
generic中文
测试函数返回整数,但调用者尝试将其解包为元组或列表。
Workarounds
-
95% success Return a tuple instead of int
def get_data(): return (1, 2); a, b = get_data()
-
85% success Unpack only if iterable
result = get_data(); if hasattr(result, '__iter__'): a, b = result
Dead Ends
Common approaches that don't work:
-
Wrapping return value in a list
60% fail
If the function returns a single int, wrapping creates a list, but unpacking still expects multiple values.
-
Using *args in function definition
40% fail
Changes function signature and may break other callers.