On Mon, 11 Apr 2022 at 19:30, Steven D'Aprano <st...@pearwood.info> wrote: > > On Mon, Apr 11, 2022 at 12:21:41PM +1000, Chris Angelico wrote: > > On Mon, 11 Apr 2022 at 10:41, Steven D'Aprano <st...@pearwood.info> wrote: > > > > > > On Sat, Apr 09, 2022 at 02:52:50AM +1000, Chris Angelico wrote: > > > > > > > We aren't bothered by the fact that os.chdir() > > > > is global, we just accept that it belongs to the application, not a > > > > library. > > > > > > You might not be, but those of us who use it, or *would* use it if it > > > wasn't so dangerous, think differently. > > > > Would you? What would the behaviour of os.chdir be if it had module > > scope? Please explain, I am very curious. > > You know how every OS process has its own working directory? Just like > that, except every module.
That's a really lovely theory. The problem is, it doesn't work that way. Every process is spawned in the working directory of its parent (modulo deliberate changes), and thereafter is completely independent. If one process sends a signal to another process, they have independent working directories. That doesn't make sense with modules, since they constantly call back and forth to each other. Imagine: import subprocess import os os.change_local_dir(...) What's the working directory of the subprocess module? Is it independent of the calling module? If so, what's the point of even HAVING a per-module working directory, since no Python code can ever directly open a file - it always calls a function in another module? > Its probably too hard to implement in Python, at least for the benefit. > (Lots of effort, only a small benefit, nett negative worth.) Massive negative worth. > This is not a PEP proposing per-module WDs, not even a serious proposal > for it. "One WD per process" is baked so deep into file I/O on Posix > systems (and I presume Windows) that its probably impossible to > implement in current systems. The context manager changes the entire process's WD for a section of code. This makes sense, although it has its own consequences. Per-module *simply does not work*, nor does it make any sense. The module-scope hammer does not fit every nail. Stop trying to hammer in screws. ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/RCKX7DYJXURZPHLAHLZ6SDOS23MVPZGL/ Code of Conduct: http://python.org/psf/codeofconduct/