Skip to content

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

@jb2170

Description

@jb2170

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/

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions