Need some help in a script

So I’ve been messing around with object’s meshes and came into trouble when getting Polygon’s material.
The API says:


KX_PolygonMaterial(PyObjectPlus)

 getMaterial()[TABLE="class: docutils field-list"]
    [TR="class: field-odd field"]
[TH="class: field-name"]Returns:[/TH]
The polygon material
 [/TR]
 [TR="class: field-even field"]
[TH="class: field-name"]Return type:[/TH]
[KX_PolygonMaterial](http://www.blender.org/documentation/blender_python_api_2_69_1/bge.types.KX_PolygonMaterial.html#bge.types.KX_PolygonMaterial) or [KX_BlenderMaterial](http://www.blender.org/documentation/blender_python_api_2_69_1/bge.types.KX_BlenderMaterial.html#bge.types.KX_BlenderMaterial)

[/TR]
[/TABLE]

As you can see theres 2 return types and the question is: how do I define which return type it should return?
In my case I need KX_PolygonMaterial, but polygon.getMaterial() returns KX_BlenderMaterial

No, it says it returns wether one or the other. What you get depends on the configuration of the mesh. If you do can assume a specific type you better check what you get bye type validation.


if type(polygonMaterial) == bge.types.KX_PolygonMaterial:
    dealWithPolygonMaterial
elif type(...

In OOP it is usually a better idea to check for instances but in this situation type should be good enough.