Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move contextlib.chdir to shutil.chdir_context contingent on gh-128432 #128499

Closed
jb2170 opened this issue Jan 4, 2025 · 6 comments
Closed

Move contextlib.chdir to shutil.chdir_context contingent on gh-128432 #128499

jb2170 opened this issue Jan 4, 2025 · 6 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@jb2170
Copy link
Contributor

jb2170 commented Jan 4, 2025

Feature or enhancement

Proposal:

Summary

  • We relocate contextlib.chdir to shutil.chdir_context.
  • We silently change the contextlib.chdir member to be a compatibility import, which can be removed when Python <=3.13 is no longer supported, for a gentle deprecation path.

Rationale

This is really part (2/2) of #128432 which is resolved by the pending #128433. The naming convention chdir_context follows umask_context. Documentation re-organising, and code style introduced in #128433 allows this one to slot right in.

contextlib shouldn't have been the location that chdir was added to in the first place, and now is the opportune time to correct this mis-step.

PR Preview

Git (re)based on #128433, the PR draft branch is on my fork

Discussions

On discuss.python.org.

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

https://discuss.python.org/t/move-contextlib-chdir-to-become-shutil-chdir/76007/

@jb2170 jb2170 added the type-feature A feature request or enhancement label Jan 4, 2025
@JelleZijlstra
Copy link
Member

I believe we should not change anything here (some people expressed the same sentiment in the Discourse thread, though it got a little buried around the naming discussion). Deprecations have a cost in terms of making Python upgrades harder, and this change isn't worth that cost.

@picnixz picnixz added the stdlib Python modules in the Lib dir label Jan 5, 2025
@picnixz
Copy link
Member

picnixz commented Jan 5, 2025

which can be removed when Python <=3.13 is no longer supported, for a gentle deprecation path.

This essentially means that we're removing it in 2029, when it's no more accepting security patches but many distributions are still patching very old releases (e.g., openSUSE with 3.6 patches) so, if we can alleviate the work on their side (even if this targets an EOL branch), why not doing it. So I'm rather a -0.5 on this one even though it's for the sake of consistency (if we really want to change it, I would prefer that contextlib.chdir stays indefinitely as an alias to shutil.chdir_context).

@jb2170
Copy link
Contributor Author

jb2170 commented Jan 6, 2025

We're continuing with this issue / PR.

We'll see in 2029 whether the contextlib.chdir compatibility import should be removed as planned, or kept indefinitely. 🙂

Really though for distros who choose to use dead versions of Python it's up to them to write compatibility code, eg

import sys
if sys.version_info >= (3,18):
    from shutil import chdir_context as chdir
else:
    from contextlib import chdir

beyond the lifespan of chdir inside contextlib

@erlend-aasland
Copy link
Contributor

We're continuing with this issue / PR.

Hold on; there is no consensus for making this change. Several core devs seem to want to reject this. Please wait with a PR until there is consensus.

@ncoghlan
Copy link
Contributor

ncoghlan commented Jan 7, 2025

With the umask proposal in #128432 closed, the motivation to move away from the status quo with regards to contextlib.chdir goes away. Accordingly, closing this proposal as well.

However, we'll continue with the contextlib.ModificationContext pattern extraction proposal in #128574

@ncoghlan ncoghlan closed this as not planned Won't fix, can't repro, duplicate, stale Jan 7, 2025
@jb2170
Copy link
Contributor Author

jb2170 commented Jan 8, 2025

Closed due to cancellation of #128432

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

5 participants