This is the same as when you do it ‘by hand’ rather than using the Python API. The general rule of thumb is that anything that can apply to multiple objects works on all those currently selected, while anything that can only apply to one object works on the active one.