Use isinstance rather than type checking (PEP8 guidelines)