Add type guard to deal with python3 differences