In case you're open to something for JS instead of Python, my life has been much better since I switched from AHK to nutjs for my own automation scripts: https://nutjs.dev/
A real programming language, and support for multiple platforms!
Alternatively if you're into dotnet, FlaUI is amazing for automation and gives you a sane environment. I moved to it when I couldn't deal with AutoIT scripts anymore and it's everything I needed. https://github.com/FlaUI/FlaUI
A real programming language, and support for multiple platforms!