Correct methods to apply modifiers to curve in 2.8

This was one of my most important functions in 2.7 Python, and there seem to be conflicting opinions on how to update it for 2.8. Any suggestions?

def applyModifiers(obj):
    mesh = obj.to_mesh(scene = bpy.context.scene, apply_modifiers=True, settings = 'PREVIEW')
    meshObj = bpy.data.objects.new(obj.name + "_mesh", mesh)
    bpy.context.scene.objects.link(meshObj)
    bpy.context.scene.objects.active = meshObj
    meshObj.matrix_world = obj.matrix_world
    bpy.ops.object.select_all(action='DESELECT')
    bpy.data.objects[obj.name].hide = False
    bpy.data.objects[obj.name].select = True
    bpy.ops.object.delete()
    return meshObj

Not sure this is the best way to do it but an alternative is using bpy.ops.object.convert(). You might want to make sure the context is correct and that only the relevant object is selected before executing the operator.

Interesting–that method would be much more straightforward, but I avoid it because I get context errors whenever I try it, whether in 2.7 or 2.8. Have you got an example of how to use it correctly in 2.8?

Ha, solved it–in 2.8 it can be done with just:

bpy.ops.object.convert(target='MESH')