bpo-31416: Fix assertion failures in case of a bad warnings.filters or warnings.defaultaction. (#3496)

Patch by Oren Milman.
3 files changed