Refactor scalar type hints implementation per Dmitry's patch