A fully general transformation from naive to thread-safe code seems like it would make you one of the giants of computer science alongside Knuth and Dijkstra.
I think this is where concepts from Rust and Go could come in handy. Things like Go’s race condition detection and rust’s compiler validation approaches can be used to statically analyze code. Sure, it’s a meaningful change from how many Python devs approach the language and challenging problem but not insurmountable given the existing work in the field.