gh-37163: moving modular stuff to "CommutativeRing" class
as a step towards simplifying old coercion framework
also adding some typing annotations
### :memo: Checklist
- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
URL: https://github.com/sagemath/sage/pull/37163
Reported by: Frédéric Chapoton
Reviewer(s): Alex J Best