Skip to content

Commit 77b94df

Browse files
committed
Updated Path documentation and made is_junction() conditional (#800)
Fixes #794. (cherry picked from commit 5abc9ec)
1 parent bf130dc commit 77b94df

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
@@ -13,6 +13,10 @@ This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.
1313
- Fixed ``TypeError`` with ``TLSStream`` on Windows when a certificate verification
1414
error occurs when using a `truststore <https://github.com/sethmlarson/truststore>`_
1515
SSL certificate (`#795 <https://github.com/agronholm/anyio/issues/795>`_)
16+
- Corrected documentation on ``anyio.Path`` regarding the limitations imposed by the
17+
current Python version on several of its methods, and made the ``is_junction`` method
18+
unavailable on Python versions earlier than 3.12
19+
(`#794 <https://github.com/agronholm/anyio/issues/794>`_)
1620

1721
**4.6.0**
1822

src/anyio/_core/_fileio.py

+23-3
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,18 @@ class Path:
218218
It implements the Python 3.10 version of :class:`pathlib.Path` interface, except for
219219
the deprecated :meth:`~pathlib.Path.link_to` method.
220220
221+
Some methods may be unavailable or have limited functionality, based on the Python
222+
version:
223+
224+
* :meth:`~pathlib.Path.from_uri` (available on Python 3.13 or later)
225+
* :meth:`~pathlib.Path.full_match` (available on Python 3.13 or later)
226+
* :meth:`~pathlib.Path.is_junction` (available on Python 3.12 or later)
227+
* :meth:`~pathlib.Path.match` (the ``case_sensitive`` paramater is only available on
228+
Python 3.13 or later)
229+
* :meth:`~pathlib.Path.relative_to` (the ``walk_up`` parameter is only available on
230+
Python 3.12 or later)
231+
* :meth:`~pathlib.Path.walk` (available on Python 3.12 or later)
232+
221233
Any methods that do disk I/O need to be awaited on. These methods are:
222234
223235
* :meth:`~pathlib.Path.absolute`
@@ -233,7 +245,10 @@ class Path:
233245
* :meth:`~pathlib.Path.is_dir`
234246
* :meth:`~pathlib.Path.is_fifo`
235247
* :meth:`~pathlib.Path.is_file`
248+
* :meth:`~pathlib.Path.is_junction`
236249
* :meth:`~pathlib.Path.is_mount`
250+
* :meth:`~pathlib.Path.is_socket`
251+
* :meth:`~pathlib.Path.is_symlink`
237252
* :meth:`~pathlib.Path.lchmod`
238253
* :meth:`~pathlib.Path.lstat`
239254
* :meth:`~pathlib.Path.mkdir`
@@ -244,11 +259,14 @@ class Path:
244259
* :meth:`~pathlib.Path.readlink`
245260
* :meth:`~pathlib.Path.rename`
246261
* :meth:`~pathlib.Path.replace`
262+
* :meth:`~pathlib.Path.resolve`
247263
* :meth:`~pathlib.Path.rmdir`
248264
* :meth:`~pathlib.Path.samefile`
249265
* :meth:`~pathlib.Path.stat`
266+
* :meth:`~pathlib.Path.symlink_to`
250267
* :meth:`~pathlib.Path.touch`
251268
* :meth:`~pathlib.Path.unlink`
269+
* :meth:`~pathlib.Path.walk`
252270
* :meth:`~pathlib.Path.write_bytes`
253271
* :meth:`~pathlib.Path.write_text`
254272
@@ -386,9 +404,6 @@ def is_relative_to(self, other: str | PathLike[str]) -> bool:
386404
except ValueError:
387405
return False
388406

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

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

0 commit comments

Comments
 (0)