How detect vertices of Vertexgroup in EDIT mode?

I know how detect if a vertex is selected in a vertexgroup.

o = bpy.context.object
gindex = o.vertex_groups[mygrp].index  # get group index
for v in o.data.vertices:
    for g in v.groups:
        if g.group == gindex:  # compare with index in VertexGroupElement
            print("Ok")



But this works in OBJECT mode. If you are in EDIT mode, the data.vertices array is not updated until you back to OBJECT mode, so if the user add or remove vertices from the vertexgroup I cannot detect it.

I know how to get the vertices in EDIT mode with this:

if myobj.mode == 'EDIT':
    bm = bmesh.from_edit_mesh(myobj.data)
    obverts = bm.verts

But “obverts” hasn’t a groups information.

How can I get if a vertex is inside Vertexgroup in EDIT mode.

Use standard API and call
ob.update_from_editmode()
before you test for selection.

So, if you call this operator the mesh is updated as if I had toggled to OBJECT mode?

I think so, yes. It might be faster though. I believe it flushes the data from edit mode over to the object mode-data structures, without rebuilding the editmode structures, which I think it would in case of mode toggle.