Skip to content

Commit c40c851

Browse files
committed
Updated Path documentation and made is_junction() conditional
Fixes #794.
1 parent 63af371 commit c40c851

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

docs/versionhistory.rst

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ Version history
33

44
This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.
55

6+
**UNRELEASED**
7+
8+
- Corrected documentation on ``anyio.Path`` regarding the limitations imposed by the
9+
current Python version on several of its methods, and made the ``is_junction`` method
10+
unavailable on Python versions earlier than 3.12
11+
612
**4.6.0**
713

814
- Dropped support for Python 3.8

src/anyio/_core/_fileio.py

+22-3
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,17 @@ 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.match` (the ``case_sensitive`` paramater is only available on
226+
Python 3.13 or later)
227+
* :meth:`~pathlib.Path.relative_to` (the ``walk_up`` parameter is only available on
228+
Python 3.12 or later)
229+
* :meth:`~pathlib.Path.walk` (available on Python 3.12 or later)
230+
220231
Any methods that do disk I/O need to be awaited on. These methods are:
221232
222233
* :meth:`~pathlib.Path.absolute`
@@ -232,7 +243,10 @@ class Path:
232243
* :meth:`~pathlib.Path.is_dir`
233244
* :meth:`~pathlib.Path.is_fifo`
234245
* :meth:`~pathlib.Path.is_file`
246+
* :meth:`~pathlib.Path.is_junction`
235247
* :meth:`~pathlib.Path.is_mount`
248+
* :meth:`~pathlib.Path.is_socket`
249+
* :meth:`~pathlib.Path.is_symlink`
236250
* :meth:`~pathlib.Path.lchmod`
237251
* :meth:`~pathlib.Path.lstat`
238252
* :meth:`~pathlib.Path.mkdir`
@@ -243,11 +257,14 @@ class Path:
243257
* :meth:`~pathlib.Path.readlink`
244258
* :meth:`~pathlib.Path.rename`
245259
* :meth:`~pathlib.Path.replace`
260+
* :meth:`~pathlib.Path.resolve`
246261
* :meth:`~pathlib.Path.rmdir`
247262
* :meth:`~pathlib.Path.samefile`
248263
* :meth:`~pathlib.Path.stat`
264+
* :meth:`~pathlib.Path.symlink_to`
249265
* :meth:`~pathlib.Path.touch`
250266
* :meth:`~pathlib.Path.unlink`
267+
* :meth:`~pathlib.Path.walk`
251268
* :meth:`~pathlib.Path.write_bytes`
252269
* :meth:`~pathlib.Path.write_text`
253270
@@ -385,9 +402,6 @@ def is_relative_to(self, other: str | PathLike[str]) -> bool:
385402
except ValueError:
386403
return False
387404

388-
async def is_junction(self) -> bool:
389-
return await to_thread.run_sync(self._path.is_junction)
390-
391405
async def chmod(self, mode: int, *, follow_symlinks: bool = True) -> None:
392406
func = partial(os.chmod, follow_symlinks=follow_symlinks)
393407
return await to_thread.run_sync(func, self._path, mode)
@@ -447,6 +461,11 @@ async def is_fifo(self) -> bool:
447461
async def is_file(self) -> bool:
448462
return await to_thread.run_sync(self._path.is_file, abandon_on_cancel=True)
449463

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

0 commit comments

Comments
 (0)