Setting animation curves always makes 'curves'

I’m trying to set an animation curve via a script. It sets. Thing is, it introduces some ‘curviness’ to the curve. What happens is, the value changes from zero to something else, and I don’t set extra key frames. So it looks like some Bezier or something smoothing happens at what should be a sharp change from zero.

Is there any easy way around this? The only thing I could think would be to insert an extra keyframe just before the change to make a very short segment where this curving would happen and be very minimal.

I thought there might be a parameter for setting each key, to tell it to curve or not.

Right mouse click on the key and change its type to “broken.” Then adjust the handles to get your sharp turn.