The appended patch should address both issues. Thanks Zack!! I installed the changes (separately).
Note that I have only tested it with Python 2.7 and 3.6. It _may_ not be correct for Python in the 3.0--3.3 (inclusive) range I didn't test any of those versions either. Certainly your change is a vast improvement in any case. The test suite now passes on my Alma Linux 8 system (I had one unrelated failure which I could now fix). For the record, this has Python 2.7.18 and 3.9.7. Thanks again! -k