Backport for compatibility with Python 3.13

Hello.

Current Gramps package version in Arch is affected by https://gramps-project.org/bugs/view.php?id=13536. A fix is available in upstream: https://github.com/gramps-project/gramps/commit/4ff81ad211f60a5edeaeca7b2a1d9502aab9f1af

Please cherry-pick it to make Gramps work again. I can confirm the fix addresses the issue.

Thank you.