Detect and fix holes in an object (not mesh holes)
Assuming you do have a closed, clean, manifold surface, and you're looking for the number of genuine topological holes, you could use the surface's Euler Characteristic? (You'd better get Math SE to check me up on that one) .. anyway...

Object mode, select the object, run this snippet..

import bpy

ob = bpy.context.object
me = ob.data
v = len(me.vertices)
e = len(me.edges) 
f = len (me.polygons)
g =  1 - ((v - e + f)/2)

print(g)


.. and the genus is returned in g.