backporting a16afb4a31ed30ca063aea0e28474a3b97c40830 to RTD