Skip to content

Commit

Permalink
Updated Path documentation and made is_junction() conditional (#800)
Browse files Browse the repository at this point in the history
Fixes #794.
  • Loading branch information
agronholm authored Oct 13, 2024
1 parent ede2029 commit 5abc9ec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.
- Fixed ``TypeError`` with ``TLSStream`` on Windows when a certificate verification
error occurs when using a `truststore <https://github.com/sethmlarson/truststore>`_
SSL certificate (`#795 <https://github.com/agronholm/anyio/issues/795>`_)
- 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
(`#794 <https://github.com/agronholm/anyio/issues/794>`_)

**4.6.0**

Expand Down
26 changes: 23 additions & 3 deletions src/anyio/_core/_fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,18 @@ 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.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
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`
Expand All @@ -232,7 +244,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`
Expand All @@ -243,11 +258,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`
Expand Down Expand Up @@ -385,9 +403,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)
Expand Down Expand Up @@ -447,6 +462,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
Expand Down

0 comments on commit 5abc9ec

Please sign in to comment.