Using python to set object shading to 'smooth'
Can set face to smooth in bmesh with

for f in bm.faces:
    f.smooth = True


Or in object mode

mesh = context.object.data
for f in mesh.polygons:
    f.use_smooth = True


The foreach set routines need a correctly sized value list for example

values = [True] * len(mesh.polygons)
mesh.polygons.foreach_set("use_smooth", values)


which is the equivalent of the for loop above.

Remember that when blender started to handle ngons (faces with more than 4 verts) it changed the mesh.faces collection was renamed to mesh.polygons.