On Wed, Sep 15, 2021 at 11:56:17AM +0200, Marc-Andre Lemburg wrote:

> > - The context manager could be made more elaborate, e.g. adding optional
> >   logging for debugging purposes.
> 
> We could add a logger parameter to the context manager for
> this to customize the logger, or simply use the default one
> from logging.

That seems unnecessary. We don't put logging in other context managers.

    with open(filename, logging=...) as f:

Keep workdir() nice and simple, let it do one thing (change the working 
directory and restore it on exit) and not overload it with "elaborate" 
functionality. If people want logging, they can handle logging 
themselves.

Or maybe they can use a logging context manager?


>   We could even have os.chdir() return the context
>   manager, without introducing any new API in the os module.

That's an interesting suggestion. I think I like it. No, I'm *sure* that 
I really like it. Let's do this!

    # The old way:
    os.chdir(dirname)
    ...
    os.chdir(prevdir)

    # The new way:
    with os.chdir(dirname):
        ...

Of course the old way would still work.



-- 
Steve
_______________________________________________
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/F4HYGBPJIMKBGBVSWF3KS3C3L25NGUVE/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to