Problem with bpy.ops.sculpt.mask_expand I want create simple button.
class Interactive_mask(bpy.types.Operator):
    def execute(self, context):
        bpy.ops.object.mode_set(mode='SCULPT')
        bpy.ops.sculpt.sculptmode_toggle()        
        bpy.ops.sculpt.mask_expand(invert=True, smooth_iterations=2, use_normals=False, keep_previous_mask=False,)
        
        return {'FINISHED'} 

And I have problem with bpy.ops.sculpt.mask_expand When I press my button i have such a error
RuntimeError: Operator bpy.ops.sculpt.mask_expand()failed, context is incorrect
What I should change or add to code ?
Not in sculpt mode.
Result in python console of changing absolute mode of object to 'SCULPT' followed by toggling mode
&gt;&gt;&gt; bpy.ops.object.mode_set(mode='SCULPT')
{'FINISHED'}

&gt;&gt;&gt; bpy.ops.sculpt.sculptmode_toggle()
{'FINISHED'}

&gt;&gt;&gt; C.mode
'OBJECT'

hence out of context, since bpy.ops.sculpt.* operators require sculpt mode for context.
Remove toggle to remain in sculpt mode or  move to  the last line to toggle.
Tip
Making a poll method for your operator returning false for selected objects that cannot be sculpted will disable button in UI and remove it from context operator search.