code: def is_polygon_layer(layer):
      
      try:
          return (layer.type() == QgsMapLayer.VectorLayer) and (
              layer.geometryType() == QgsWkbTypes.PolygonGeometry)
      except AttributeError:
          return False
docs: Check if a QGIS layer is vector and its geometries are polygons.
  
      :param layer: A vector layer.
      :type layer: QgsVectorLayer, QgsMapLayer
  
      :returns: True if the layer contains polygons, otherwise False.
      :rtype: bool