Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rglob is broken on python 3.12 #35

Open
valerino opened this issue Jan 4, 2024 · 0 comments
Open

rglob is broken on python 3.12 #35

valerino opened this issue Jan 4, 2024 · 0 comments

Comments

@valerino
Copy link

valerino commented Jan 4, 2024

on python 3.12 (at least, have not tested 3.11), using rglob() leads to this:

/usr/lib/python3.12/pathlib.py:169: RuntimeWarning: coroutine 'AsyncPath.is_dir' was never awaited
  if not parent_path.is_dir():
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

sample code:

async def _list_directory_async_recursive(path: str, mask: str = None, files_only: bool = False) -> list[str]:
    paths = []
    if mask is None:
        mask = '*'

    p: AsyncPath = AsyncPath(path)
    async for pp in p.rglob(mask):
        if files_only and await pp.is_dir():
            # skip directories
            continue
        paths.append(str(pp))

    return paths

glob() seems unaffected.

a simple fix is, in aiopath.path.py, to change this:

async def rglob(self: Self, pattern: str, *, case_sensitive: bool | None = None) -> AsyncIterable[Self]:
    for path in await to_thread(super().rglob, pattern, case_sensitive=case_sensitive):
      yield AsyncPath(path)

to this

async def rglob(self: Self, pattern: str, *, case_sensitive: bool | None = None) -> AsyncIterable[Self]:
    for path in await to_thread(self._path.rglob, pattern, case_sensitive=case_sensitive):
      yield AsyncPath(path)

if you agree, i could make a PR. i also see the same pattern with super() is used in other functions in aiopath.path.py, though i have not tested if they have the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant