Skip to content

AsyncPath using synchronous Path.walk #33

Open
@Fisch37

Description

@Fisch37

The AsyncPath.walk method does not return an AsyncGenerator as expected, but instead a synchronous Generator object. This appears to be because of .walk not being defined in AsyncPath and thus the method from Path is used instead.

Expected Behaviour

AsyncPath.walk should return an AsyncGenerator object that can be used in async for statements and implements __aiter__ and __anext__.

Actual Behaviour

AsyncPath.walk follows the MRO and is really Path.walk, thus returning a normal generator. Using it in async for will cause a TypeError.

>>> async for p in AsyncPath(".").walk():
...     print(p)
... 
Traceback (most recent call last):
  File "/usr/lib/python3.12/concurrent/futures/_base.py", line 456, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "<console>", line 1, in <module>
TypeError: 'async for' requires an object with __aiter__ method, got generator

Steps to reproduce

  1. Install aiopath
  2. In a console, IDLE, or some program of your choice that runs python enter the following:
from aiopath import AsyncPath
print(*AsyncPath(".").walk())
  1. See that there was an output instead of the error that should have occured.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions