How to "wrap" several operations to "macros" which can be undo-ed?

If we type something like:
bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
bpy.ops.transform.tosphere()
etc.

So its some list of operations which we want to apply at once. We can run this as a “macro” and all list of operations will run one by one.

The problem if its would look like this:
import bpy
bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
bpy.ops.transform.tosphere()

It will work, but if we ctrl+z we can get unexpected results.

What is the easiest way to “wrap” a list of operations to “one” single function which we can undo properly all at once?

Currently i was try this method:
import bpy

def my_macro():
some operator 1
some operator 2
some operator 3

return {'FINISHED'}

my_macro()

Unfortunately it doesnt work.