(from #30371)
This straightforward cleanup is preparation for necessary changes for Python 3.9 (#30184)
CC:  @tobiasdiez @jdemeyer
Component: refactoring
Author: Tobias Diez
Branch/Commit: 8f71b29
Reviewer: Matthias Koeppe
Issue created by migration from https://trac.sagemath.org/ticket/30590