[3.10] bpo-44654: Refactor and clean up the union type implementation (GH-27196) (GH-27219)

(cherry picked from commit 0fd27375cabd12e68a2f12cfeca11a2d5043429e)
8 files changed