This is a backport of https://github.com/python/cpython/pull/24239/ sourced from https://salsa.debian.org/saifelse/python2/-/commit/cac0240f5b8d8460f5e3217fd23de256109b0847