Usually involves reinventing the wheel or using the wrong eclass.
For the distutils-r1 "foreach_impl" bugs:
Need to swap out "python_foreach_impl ..." -> a call to e.g. distutils-r1_src_install and then define the python_compile() phase.
https://github.com/gentoo/gentoo/pull/25822 has some discussion for it, but it's to fit better with eclass assumptions.