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

AsyncPath using synchronous Path.walk #33

Open
Fisch37 opened this issue Dec 23, 2023 · 1 comment
Open

AsyncPath using synchronous Path.walk #33

Fisch37 opened this issue Dec 23, 2023 · 1 comment

Comments

@Fisch37
Copy link

Fisch37 commented Dec 23, 2023

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.
@SerGeRybakov
Copy link

@alexdelorenzo Shall we expect any updates on this in the nearest future or you'd prefer a PR?

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

2 participants