Use isinstance instead of checking explicit type.