(cherry-picked from #32432)
CC: @mwageringel @kwankyu
Component: refactoring
Author: Matthias Koeppe
Branch/Commit: bdd0325
Reviewer: Kwankyu Lee
Issue created by migration from https://trac.sagemath.org/ticket/32634