Skip to content

Commit

Permalink
Fix more Path typing that doesn't match Typeshed (#653)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Grönholm <alex.gronholm@nextday.fi>
  • Loading branch information
gschaffner and agronholm committed Dec 16, 2023
1 parent e5fadb3 commit 0b66994
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
15 changes: 14 additions & 1 deletion docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,20 @@ This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.
- Fixed cancellation propagating on asyncio from a task group to child tasks if the task
hosting the task group is in a shielded cancel scope
(`#642 <https://github.com/agronholm/anyio/issues/642>`_)
- Fixed the type annotation of ``anyio.Path.samefile()`` to match Typeshed
- Fixed various type annotations of ``anyio.Path`` to match Typeshed:

- ``anyio.Path.__lt__()``
- ``anyio.Path.__le__()``
- ``anyio.Path.__gt__()``
- ``anyio.Path.__ge__()``
- ``anyio.Path.__truediv__()``
- ``anyio.Path.__rtruediv__()``
- ``anyio.Path.hardlink_to()``
- ``anyio.Path.samefile()``
- ``anyio.Path.symlink_to()``
- ``anyio.Path.with_segments()``

(PR by Ganden Schaffner)

**4.1.0**

Expand Down
20 changes: 11 additions & 9 deletions src/anyio/_core/_fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,26 +292,26 @@ def __eq__(self, other: object) -> bool:
target = other._path if isinstance(other, Path) else other
return self._path.__eq__(target)

def __lt__(self, other: Path) -> bool:
def __lt__(self, other: pathlib.PurePath | Path) -> bool:
target = other._path if isinstance(other, Path) else other
return self._path.__lt__(target)

def __le__(self, other: Path) -> bool:
def __le__(self, other: pathlib.PurePath | Path) -> bool:
target = other._path if isinstance(other, Path) else other
return self._path.__le__(target)

def __gt__(self, other: Path) -> bool:
def __gt__(self, other: pathlib.PurePath | Path) -> bool:
target = other._path if isinstance(other, Path) else other
return self._path.__gt__(target)

def __ge__(self, other: Path) -> bool:
def __ge__(self, other: pathlib.PurePath | Path) -> bool:
target = other._path if isinstance(other, Path) else other
return self._path.__ge__(target)

def __truediv__(self, other: Any) -> Path:
def __truediv__(self, other: str | PathLike[str]) -> Path:
return Path(self._path / other)

def __rtruediv__(self, other: Any) -> Path:
def __rtruediv__(self, other: str | PathLike[str]) -> Path:
return Path(other) / self

@property
Expand Down Expand Up @@ -401,7 +401,9 @@ def glob(self, pattern: str) -> AsyncIterator[Path]:
async def group(self) -> str:
return await to_thread.run_sync(self._path.group, abandon_on_cancel=True)

async def hardlink_to(self, target: str | pathlib.Path | Path) -> None:
async def hardlink_to(
self, target: str | bytes | PathLike[str] | PathLike[bytes]
) -> None:
if isinstance(target, Path):
target = target._path

Expand Down Expand Up @@ -558,7 +560,7 @@ async def stat(self, *, follow_symlinks: bool = True) -> os.stat_result:

async def symlink_to(
self,
target: str | pathlib.Path | Path,
target: str | bytes | PathLike[str] | PathLike[bytes],
target_is_directory: bool = False,
) -> None:
if isinstance(target, Path):
Expand Down Expand Up @@ -608,7 +610,7 @@ def with_stem(self, stem: str) -> Path:
def with_suffix(self, suffix: str) -> Path:
return Path(self._path.with_suffix(suffix))

def with_segments(self, *pathsegments: str) -> Path:
def with_segments(self, *pathsegments: str | PathLike[str]) -> Path:
return Path(*pathsegments)

async def write_bytes(self, data: bytes) -> int:
Expand Down

0 comments on commit 0b66994

Please sign in to comment.