Refactor all uses of type() is pattern w/ isinstance() where applicable