Basically the same changes as in 81d15948cc19c2584f13031518349327ce353c82 but for python3.9 instead of python3.8.