I delved into this problem some time ago and developed a library for it (GitHub - diegojromerolopez/gelidum: Freeze your objects in python). It has some issues (mainly the type hinting should be improved) and I’m missing some basic functionality like freezing modules for example.
My main issue in gelidum was trying to change the object in place, i.e. not making a frozen copy but to change the object without using new memory.
Thank you for bringing this topic up @stw I think this idea should be considered as it has many use cases and I’m very happy to see it discussed here.