Uh oh!
There was an error while loading. Please reload this page.
Possible fix for 'PosixPath' object does not support the context manager protocol - #474
Possible fix for 'PosixPath' object does not support the context manager protocol#474jdegenstein wants to merge 1 commit into
Conversation
snoyer
commented
Jan 30, 2025
Looks like this is the right bug but not the right fix. Key points from the Discord discussion:
|
jmwright
commented
Feb 1, 2025
@snoyer So would we check to see if |
snoyer
commented
Feb 1, 2025
Defining try:
fromcontextlibimportchdirexceptImportError:
defchdir(path): # ...It looks like importosfromcontextlibimportcontextmanagerfrompathlibimportPath@contextmanagerdefchdir(path: str|Path):
old_path=os.getcwd()
os.chdir(path)
yieldos.chdir(old_path)
withchdir("/tmp"):
assertos.getcwd() =="/tmp"withchdir("/opt"):
assertos.getcwd() =="/opt"assertos.getcwd() =="/tmp" |
per user report on python 3.13
thanks also to @snoyer
see also: https://bugs.python.org/issue39682
This is untested so far as I haven't been able to reproduce the bug myself yet.