def extract_tagged_faces(
    obj: bpy.types.Object, tags: set, nonempty=False
) -> bpy.types.Object:
    "extract the surface that satisfies all tags"

    # Ensure we're dealing with a mesh object
    if obj.type != "MESH":
        raise TypeError("Object is not a mesh!")

    face_mask = tagged_face_mask(obj, tags)

    if nonempty and not face_mask.any():
        raise ValueError(
            f"extract_tagged_faces({obj.name=}, {tags=}, {nonempty=}) got empty mask for {len(obj.data.polygons)}"
        )

    return extract_mask(obj, face_mask, nonempty=nonempty)
extract the surface that satisfies all tags
infinigen/core/tagging.py