substituting isinstance by "duck type" comparison