(partially cherry-picked from #32432)
CC: @tscrim @kliem
Component: refactoring
Author: Matthias Koeppe
Branch/Commit: 73aabd2
Reviewer: Travis Scrimshaw
Issue created by migration from https://trac.sagemath.org/ticket/32599