factoring out common implementation for python.intrinsic