Fix exceptions in the gen module to work correctly with tuple keys.

Previously this would result in a TypeError instead of the intended exception.