The reason my os.py
didn't work was because it is a frozen module in python 3.13. The same code would have called the custom os in python 3.10 as stated by user2357112 in comments. I tried my code with re
which is not a frozen module in python 3.13 but is present in sys.modules and it called the custom re file.
So, it is true that because os
was present in sys.modules
the custom file was not loaded. And later on as described in my import process, the frozen module took preference over the custom one.