Skip to content

Commit

Permalink
Fixed iterdir making blocking call in Python 3.13 (#874)
Browse files Browse the repository at this point in the history
Fixes #873.

---------

Co-authored-by: Alex Grönholm <[email protected]>
  • Loading branch information
cbornet and agronholm authored Feb 21, 2025
1 parent 8bad9c0 commit 38885f9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.
nesting on asyncio due to exception chaining when raising ``ExceptionGroups``
in ``TaskGroup.__aexit__``
(`#863 <https://github.com/agronholm/anyio/issues/863>`_; PR by @tapetersen)
- Fixed ``anyio.Path.iterdir()`` making a blocking call in Python 3.13
(`#873 <https://github.com/agronholm/anyio/issues/873>`_; PR by @cbornet and
@agronholm)

**4.8.0**

Expand Down
11 changes: 8 additions & 3 deletions src/anyio/_core/_fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,14 @@ async def is_socket(self) -> bool:
async def is_symlink(self) -> bool:
return await to_thread.run_sync(self._path.is_symlink, abandon_on_cancel=True)

def iterdir(self) -> AsyncIterator[Path]:
gen = self._path.iterdir()
return _PathIterator(gen)
async def iterdir(self) -> AsyncIterator[Path]:
gen = (
self._path.iterdir()
if sys.version_info < (3, 13)
else await to_thread.run_sync(self._path.iterdir, abandon_on_cancel=True)
)
async for path in _PathIterator(gen):
yield path

def joinpath(self, *args: str | PathLike[str]) -> Path:
return Path(self._path.joinpath(*args))
Expand Down

0 comments on commit 38885f9

Please sign in to comment.