Skip to content

Commit 5abc9ec

Browse files
authored
Updated Path documentation and made is_junction() conditional (#800)
Fixes #794.
1 parent ede2029 commit 5abc9ec

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

docs/versionhistory.rst

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.
1616
- Fixed ``TypeError`` with ``TLSStream`` on Windows when a certificate verification
1717
error occurs when using a `truststore <https://github.com/sethmlarson/truststore>`_
1818
SSL certificate (`#795 <https://github.com/agronholm/anyio/issues/795>`_)
19+
- Corrected documentation on ``anyio.Path`` regarding the limitations imposed by the
20+
current Python version on several of its methods, and made the ``is_junction`` method
21+
unavailable on Python versions earlier than 3.12
22+
(`#794 <https://github.com/agronholm/anyio/issues/794>`_)
1923

2024
**4.6.0**
2125

src/anyio/_core/_fileio.py

+23-3
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,18 @@ class Path:
217217
It implements the Python 3.10 version of :class:`pathlib.Path` interface, except for
218218
the deprecated :meth:`~pathlib.Path.link_to` method.
219219
220+
Some methods may be unavailable or have limited functionality, based on the Python
221+
version:
222+
223+
* :meth:`~pathlib.Path.from_uri` (available on Python 3.13 or later)
224+
* :meth:`~pathlib.Path.full_match` (available on Python 3.13 or later)
225+
* :meth:`~pathlib.Path.is_junction` (available on Python 3.12 or later)
226+
* :meth:`~pathlib.Path.match` (the ``case_sensitive`` paramater is only available on
227+
Python 3.13 or later)
228+
* :meth:`~pathlib.Path.relative_to` (the ``walk_up`` parameter is only available on
229+
Python 3.12 or later)
230+
* :meth:`~pathlib.Path.walk` (available on Python 3.12 or later)
231+
220232
Any methods that do disk I/O need to be awaited on. These methods are:
221233
222234
* :meth:`~pathlib.Path.absolute`
@@ -232,7 +244,10 @@ class Path:
232244
* :meth:`~pathlib.Path.is_dir`
233245
* :meth:`~pathlib.Path.is_fifo`
234246
* :meth:`~pathlib.Path.is_file`
247+
* :meth:`~pathlib.Path.is_junction`
235248
* :meth:`~pathlib.Path.is_mount`
249+
* :meth:`~pathlib.Path.is_socket`
250+
* :meth:`~pathlib.Path.is_symlink`
236251
* :meth:`~pathlib.Path.lchmod`
237252
* :meth:`~pathlib.Path.lstat`
238253
* :meth:`~pathlib.Path.mkdir`
@@ -243,11 +258,14 @@ class Path:
243258
* :meth:`~pathlib.Path.readlink`
244259
* :meth:`~pathlib.Path.rename`
245260
* :meth:`~pathlib.Path.replace`
261+
* :meth:`~pathlib.Path.resolve`
246262
* :meth:`~pathlib.Path.rmdir`
247263
* :meth:`~pathlib.Path.samefile`
248264
* :meth:`~pathlib.Path.stat`
265+
* :meth:`~pathlib.Path.symlink_to`
249266
* :meth:`~pathlib.Path.touch`
250267
* :meth:`~pathlib.Path.unlink`
268+
* :meth:`~pathlib.Path.walk`
251269
* :meth:`~pathlib.Path.write_bytes`
252270
* :meth:`~pathlib.Path.write_text`
253271
@@ -385,9 +403,6 @@ def is_relative_to(self, other: str | PathLike[str]) -> bool:
385403
except ValueError:
386404
return False
387405

388-
async def is_junction(self) -> bool:
389-
return await to_thread.run_sync(self._path.is_junction)
390-
391406
async def chmod(self, mode: int, *, follow_symlinks: bool = True) -> None:
392407
func = partial(os.chmod, follow_symlinks=follow_symlinks)
393408
return await to_thread.run_sync(func, self._path, mode)
@@ -447,6 +462,11 @@ async def is_fifo(self) -> bool:
447462
async def is_file(self) -> bool:
448463
return await to_thread.run_sync(self._path.is_file, abandon_on_cancel=True)
449464

465+
if sys.version_info >= (3, 12):
466+
467+
async def is_junction(self) -> bool:
468+
return await to_thread.run_sync(self._path.is_junction)
469+
450470
async def is_mount(self) -> bool:
451471
return await to_thread.run_sync(
452472
os.path.ismount, self._path, abandon_on_cancel=True

0 commit comments

Comments
 (0)