Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
bpo-25625: add contextlib.chdir#28271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This is probably the single snippet of code I find myself re-implementing themost in projects. Not being thread safe is not optimal, but there isn'treally any good way to do so, and that does not negate the hugeusefulness of this function.Signed-off-by: Filipe Laíns <lains@riseup.net>
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Filipe Laíns <filipe.lains@gmail.com>
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Signed-off-by: Filipe Laíns <lains@riseup.net>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'm -1 to add this feature.
The presence of a chdir decorator in Python's stdlib promotes the idea that the feature is a good standard practice. However it is ill-advised to change process global state such as the working directory in most cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Technically it looks correct to me. I am not sure that such feature should be added, although the can of worms was opened byredirect_stdout()
.
I agree with the comment that it can be problematic, but OTOH it'svery common to reimplement this code over and over. There's something to be said for providing a solid reference implementation that at least does the best you can do, but with big red warnings for when it can go wrong. Not having this in the stdlib isn't going to stop people from doing it anyway. |
I disagree. Sure, any global modifications of the environment are potential anti-patterns, like monkey-patching standard input/output that Serhiy already mentioned (seeBPO-30511 for an egregious example why that is a problem). That being said, again, |
I'm really not sure this should be part of contextlib (or the stdlib). I'd just add this as a recipe to the docs. |
Signed-off-by: Filipe Laíns <lains@riseup.net>
Signed-off-by: Filipe Laíns <lains@riseup.net>
Perpython/steering-council#77, it seems that addition of such a context manager was approved, granted that we have an appropriate warning. Otherwise, this PR is now unblocked 🙂 |
Uh oh!
There was an error while loading.Please reload this page.
Non parallel-safe context manager to change the current working directory. | ||
As this changes a global state, the working directory, it is not suitable | ||
for use in most threaded or aync contexts. It is also not suitable for most |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
typo onaync
#29091
This commit implements a non thread-safe context manager to changethe current working directory.Available in Python 3.11 as ``contextlib.chdir`` and adapted frompython/cpython#28271.
This commit implements a non thread-safe context manager to changethe current working directory.Available in Python 3.11 as ``contextlib.chdir`` and adapted frompython/cpython#28271.
Uh oh!
There was an error while loading.Please reload this page.
This is probably the single snippet of code I find myself re-implementing the
most in projects. Not being thread safe is not optimal, but there isn't
really any good way to do so, and that does not negate the huge
usefulness of this function.
Signed-off-by: Filipe Laínslains@riseup.net
https://bugs.python.org/issue25625