← Back to Error Library
TypeErrorPythonMay 2026

'NoneType' object is not iterable

Error Message

terminal
TypeError: 'NoneType' object is not iterable
  File "main.py", line 22, in process_results
    for item in fetch_data():

Root Cause

fetch_data() returned None because an early return statement had no value. Python bare return is equivalent to return None.

Fix

solution
# Before (broken) — bare return returns None
def fetch_data():
    if condition:
        return  # implicitly None!

for item in fetch_data():  # crashes

# After (fixed) — always return an iterable
def fetch_data():
    if condition:
        return []  # explicit empty list

for item in (fetch_data() or []):  # safe fallback

Takeaway

In Python, a bare return or a missing return statement evaluates to None. Always return an empty iterable ([], {}, ()) when the caller will iterate over the result.

PythonFunctionsIteration