The short answer is: No, MySQLdb does not support passing an empty iterator argument to executemany
.
Why not? Because of the line if not args: return
. This handles the case where you provide no parameters by cutting the server out entirely and returning None
. The truth value of an empty list, dict, set, or tuple is False
, but the truth value of an iterator is always True
.
If you comment out that line in cursors.py
, then any empty sequence or mapping will throw the same ER_PARSE_ERROR
as the empty iterator.
In order for executemany
to support empty arguments, it has to test whether args
is empty somehow. If args
is an iterator, the only way to do this is to call .next()
and observe whether the result is a StopIteration
exception; there's no other way to determine whether an arbitrary iterator is empty. This would be impractical because it consumes an item from the iterator and doesn't work for any non-iterator type, and pointless because executemany
is not intended to be used without parameters in the first place.