On Tue, 14 Sept 2021 at 22:59, David Mertz, Ph.D. <david.me...@gmail.com>
wrote:

> I think this would be convenient.
>
> And yes, it's not thread safe. But neither is os.chdir() to start with.
> Someone whose script, or library, wants to chdir can already shoot
> themselves in the foot. This makes that slightly less likely, not more.
>
The problem is someone thinking that by using this they would not be
shooting themselves on the foot
because "wow, a 2021 adition to the stdlib will certainly be thread and
async safe".

I am with Chris Angelico in that this would be dangerous.




>
> In terms of the bikeshed color, I think putting this in `pathlib` is the
> best approach for "modern Python."
>
OTOH, on  Pathlib we could have a proper implementation that could take care
of _all_ in context file operations, and internally use absolute paths
(instead
of calling chdir). Such an implementation would work.
```
with Path("/tmp").workdir as mydir:
    with mydir.open("myfile"):
         ...
```
and maybe could be practical enough to stirr people away from "chdir".

>
>
> On Tue, Sep 14, 2021, 7:37 PM Cameron Simpson <c...@cskk.id.au> wrote:
>
>> On 15Sep2021 07:50, Chris Angelico <ros...@gmail.com> wrote:
>> >On Wed, Sep 15, 2021 at 7:43 AM Cameron Simpson <c...@cskk.id.au> wrote:
>> >> I know I'm atypical, but I have quite a lot of multithreaded stuff,
>> >> including command line code. So while it'd be ok to avoid this context
>> >> manager for my own code, I fear library modules, either stdlib or pypi,
>> >> quietly using this in their code, making them unuseable in the general
>> >> case. Unrepairably unuseable, for the user.
>> >
>> >Library code shouldn't be changing the working directory, context
>> >manager or not. That belongs to the application.
>>
>> Entirely agree.
>>
>> I'm concerned that convenient stackable chdir is a bug magnet, and would
>> creep into library code. Maybe not in the stdlib, but there's no point
>> writing such a context manager if it isn't goingg to be used, and
>> therefore it could get used in library code. Imagine when a popular pypi
>> module starts using it internally and breaks a multithreaded app
>> previously relying on it?
>>
>> _______________________________________________
> 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/KM6NEMJTUIMRTRTR4IZCW3CAZ264JBY2/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
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/6SURJ3IUMBH7IJTHQTZLOYXAY4SLFHIM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to