the wedge
python bugs ai writes (and how to catch them).
updated 2026-05-11 · 7 entries
every bug below is one your ai coding assistant will ship to you. most of them, more than once. each entry names the bug, shows where it shows up, and links to a runnable chapter on the fix when one exists.
send a bug to @TFisPython. the best ones land here, anonymized.
#01 · claude code, cursor, copilot
filters falsy values out of a list, deletes valid zeros
why:asked to filter `None` from `[0, 1, None, 2]`, the ai writes `[x for x in xs if x]` and silently drops `0`. shipped a `user_id` outage at one company.
fix:use `if x is not None` for nullable checks. never use truthiness for nullable id checks.
#02 · all ai coders
shared mutable default argument
why:writes `def add(item, items=[]):` and the same list gets reused across every call. classic python footgun, ai writes it weekly.
fix:use `items: list | None = None` and create the list inside the function.
#03 · claude code, cursor
`==` where `is` was meant
why:writes `if items == None:` six times in one file. `__eq__` can lie. `is` cannot.
fix:use `is None` always. it's not a style choice.
#04 · claude code, cursor
`sorted(..., key=...)` with no `reverse=True`
why:ask for the top 3 best sellers, get the 3 worst. `sorted()` is ascending by default and the ai never asks.
fix:always pass `reverse=True` when you want largest-first, or use `heapq.nlargest`.
#05 · claude code
claims a function is a generator, returns a list
why:asks for a streaming generator, gets a function that builds the full list in memory and returns it. memory blows up at scale.
fix:look for `yield`. no yield, not a generator.
chapter coming
#06 · cursor, copilot
modifies a dict while iterating over it
why:`for k in d:` then `del d[k]` raises `RuntimeError: dictionary changed size during iteration`. ai writes it confidently anyway.
fix:iterate over `list(d.keys())` if you need to mutate while looping. or build a new dict.
#07 · all ai coders
`except Exception:` swallowing everything
why:writes `try: ... except Exception: pass` and hides real bugs forever. the call site reports success.
fix:catch the specific exception. if you need a wide net, log + reraise. never silent.