[1.5.x] Fixed #19576 -- Use `six.with_metaclass` uniformously accross code base.

Backport of f58efd07f from master.