bpo-41993: Fix possible issues in remove_module() (GH-22631) (GH-22647)

* PyMapping_HasKey() is not safe because it silences all exceptions and can return incorrect result.
* Informative exceptions from PyMapping_DelItem() are overridden with RuntimeError and
  the original exception raised before calling remove_module() is lost.
* There is a race condition between PyMapping_HasKey() and PyMapping_DelItem().
(cherry picked from commit 8287aadb75f6bd0154996424819334cd3839707c)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2 files changed