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 intoCadQuery:masterfrom
Conversation
|
Looks like this is the right bug but not the right fix. Key points from the Discord discussion:
|
|
@snoyer So would we check to see if |
Defining try:
from contextlib import chdir
except ImportError:
def chdir(path):
# ...It looks like import os
from contextlib import contextmanager
from pathlib import Path
@contextmanager
def chdir(path: str | Path):
old_path = os.getcwd()
os.chdir(path)
yield
os.chdir(old_path)
with chdir("/tmp"):
assert os.getcwd() == "/tmp"
with chdir("/opt"):
assert os.getcwd() == "/opt"
assert os.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.