-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
pathlib.Path.__enter__() should emit DeprecationWarning #90714
Comments
In Python 3.9 / bpo-39682 we made Path.__exit__() a no-op, and added a comment in the code mentioning that it should be deprecated in future. The future is here, so let's deprecate it. |
Path as a contextmanager is deprecated from 3.11 onwards, and was a no-op since Python 3.11. Also this functionality was never documented. See [cpython/Lib/pathlib.py#L810-L816][1], python/cpython#83863 and, python/cpython#90714. [1]: https://github.com/python/cpython/blob/120b4ab2b68aebf96ce0de243eab89a25fc2d282/Lib/pathlib.py#L810-L816
Path as a contextmanager is deprecated from 3.11 onwards, and was a no-op since Python 3.9. Also this functionality was never documented. See [cpython/Lib/pathlib.py#L810-L816][1], python/cpython#83863 and, python/cpython#90714. [1]: https://github.com/python/cpython/blob/120b4ab2b68aebf96ce0de243eab89a25fc2d282/Lib/pathlib.py#L810-L816
Path as a contextmanager is deprecated from 3.11 onwards, and was a no-op since Python 3.9. Also this functionality was never documented. See [cpython/Lib/pathlib.py#L810-L816][1], python/cpython#83863 and, python/cpython#90714. [1]: https://github.com/python/cpython/blob/120b4ab2b68aebf96ce0de243eab89a25fc2d282/Lib/pathlib.py#L810-L816
so how do we use Path to avoid this warning? |
anyone..anyone... |
Don't use a path object as a context manager, e.g. rather than: with Path('foo') as path:
... use: path = Path('foo') |
Ah got it. that is what i had ended up doing - wasn't sure if there still was a way to use it with the 'with' block. |
DeprecationWarning
frompathlib.Path.__enter__()
#30971Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: