To make chdir() return a context manager *and* keep it working without calling `__enter__`, it would have to call `getcwd()`, which I've heard is expensive.
So I don't think that would work, alas. On Wed, Sep 15, 2021 at 11:55 AM Eric V. Smith <e...@trueblade.com> wrote: > On 9/15/2021 2:48 PM, Eric Fahlgren wrote: > > On Wed, Sep 15, 2021 at 12:21 AM Eric V. Smith <e...@trueblade.com> wrote: > >> And I'm not crazy about the name "workdir". To me, it sounds like it >> returns something, not sets and resets something. But I don't have a >> particularly great alternative in mind: in my own code I've used >> "change_dir", which isn't awesome either. >> > > Our version is named "pushdir", modeled after shell's pushd (even though > pushdir is a context manager and does auto-pop). Everyone figures out what > it does at a glance. > > That's a great name! > > Although I think having os.chdir() return a context manager is a better > design (assuming it can work, but at first blush it would seem so). > > Eric > > > _______________________________________________ > 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/U5UQFDAJ4KWG2OQ3YMP2THMSJ72JRV6Y/ > Code of Conduct: http://python.org/psf/codeofconduct/ > -- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________ 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/LZL4YXXRW4TBBSFZVW46PTTUOT36LX62/ Code of Conduct: http://python.org/psf/codeofconduct/