From c40c851b1b3c3ca36382568daad68950285614f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Wed, 2 Oct 2024 22:22:56 +0300 Subject: [PATCH 1/2] Updated Path documentation and made is_junction() conditional Fixes #794. --- docs/versionhistory.rst | 6 ++++++ src/anyio/_core/_fileio.py | 25 ++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/docs/versionhistory.rst b/docs/versionhistory.rst index 22ae559c..384f9f4e 100644 --- a/docs/versionhistory.rst +++ b/docs/versionhistory.rst @@ -3,6 +3,12 @@ Version history This library adheres to `Semantic Versioning 2.0 `_. +**UNRELEASED** + +- Corrected documentation on ``anyio.Path`` regarding the limitations imposed by the + current Python version on several of its methods, and made the ``is_junction`` method + unavailable on Python versions earlier than 3.12 + **4.6.0** - Dropped support for Python 3.8 diff --git a/src/anyio/_core/_fileio.py b/src/anyio/_core/_fileio.py index 23ccb0d6..86b8fe77 100644 --- a/src/anyio/_core/_fileio.py +++ b/src/anyio/_core/_fileio.py @@ -217,6 +217,17 @@ class Path: It implements the Python 3.10 version of :class:`pathlib.Path` interface, except for the deprecated :meth:`~pathlib.Path.link_to` method. + Some methods may be unavailable or have limited functionality, based on the Python + version: + + * :meth:`~pathlib.Path.from_uri` (available on Python 3.13 or later) + * :meth:`~pathlib.Path.full_match` (available on Python 3.13 or later) + * :meth:`~pathlib.Path.match` (the ``case_sensitive`` paramater is only available on + Python 3.13 or later) + * :meth:`~pathlib.Path.relative_to` (the ``walk_up`` parameter is only available on + Python 3.12 or later) + * :meth:`~pathlib.Path.walk` (available on Python 3.12 or later) + Any methods that do disk I/O need to be awaited on. These methods are: * :meth:`~pathlib.Path.absolute` @@ -232,7 +243,10 @@ class Path: * :meth:`~pathlib.Path.is_dir` * :meth:`~pathlib.Path.is_fifo` * :meth:`~pathlib.Path.is_file` + * :meth:`~pathlib.Path.is_junction` * :meth:`~pathlib.Path.is_mount` + * :meth:`~pathlib.Path.is_socket` + * :meth:`~pathlib.Path.is_symlink` * :meth:`~pathlib.Path.lchmod` * :meth:`~pathlib.Path.lstat` * :meth:`~pathlib.Path.mkdir` @@ -243,11 +257,14 @@ class Path: * :meth:`~pathlib.Path.readlink` * :meth:`~pathlib.Path.rename` * :meth:`~pathlib.Path.replace` + * :meth:`~pathlib.Path.resolve` * :meth:`~pathlib.Path.rmdir` * :meth:`~pathlib.Path.samefile` * :meth:`~pathlib.Path.stat` + * :meth:`~pathlib.Path.symlink_to` * :meth:`~pathlib.Path.touch` * :meth:`~pathlib.Path.unlink` + * :meth:`~pathlib.Path.walk` * :meth:`~pathlib.Path.write_bytes` * :meth:`~pathlib.Path.write_text` @@ -385,9 +402,6 @@ def is_relative_to(self, other: str | PathLike[str]) -> bool: except ValueError: return False - async def is_junction(self) -> bool: - return await to_thread.run_sync(self._path.is_junction) - async def chmod(self, mode: int, *, follow_symlinks: bool = True) -> None: func = partial(os.chmod, follow_symlinks=follow_symlinks) return await to_thread.run_sync(func, self._path, mode) @@ -447,6 +461,11 @@ async def is_fifo(self) -> bool: async def is_file(self) -> bool: return await to_thread.run_sync(self._path.is_file, abandon_on_cancel=True) + if sys.version_info >= (3, 12): + + async def is_junction(self) -> bool: + return await to_thread.run_sync(self._path.is_junction) + async def is_mount(self) -> bool: return await to_thread.run_sync( os.path.ismount, self._path, abandon_on_cancel=True From 44eda8c159d2b112b2f21d91a6e53c46362bbe37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Sun, 13 Oct 2024 13:33:20 +0300 Subject: [PATCH 2/2] Mentioned is_junction on the partially available methods list --- src/anyio/_core/_fileio.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/anyio/_core/_fileio.py b/src/anyio/_core/_fileio.py index 86b8fe77..53d3288c 100644 --- a/src/anyio/_core/_fileio.py +++ b/src/anyio/_core/_fileio.py @@ -222,6 +222,7 @@ class Path: * :meth:`~pathlib.Path.from_uri` (available on Python 3.13 or later) * :meth:`~pathlib.Path.full_match` (available on Python 3.13 or later) + * :meth:`~pathlib.Path.is_junction` (available on Python 3.12 or later) * :meth:`~pathlib.Path.match` (the ``case_sensitive`` paramater is only available on Python 3.13 or later) * :meth:`~pathlib.Path.relative_to` (the ``walk_up`` parameter is only available on