Uh oh!
There was an error while loading. Please reload this page.
AsyncGenerator → AsyncIterator - #2381
Conversation
e86ee25 to
694af4bCompareparaseba
commented
Oct 16, 2024
I think a better type for these functions would be: asyncdeflist(self) ->AsyncIterator[str]:Most implementations probably won't need these functions to be async, but it's a more general type for some implementation that may need it. |
Uh oh!
There was an error while loading. Please reload this page.
46dc84b to
52e66c9Compare
The roadmap defines the Store API as follows and should be updated: asyncdeflist(self) ->List[str]:
... # required for listable storesasyncdeflist_prefix(self, prefix: str) ->List[str]:
... # required for listable storesasyncdeflist_dir(self, prefix: str) ->List[str]:
... # required for listable stores
As for the return value, not sure why it changed from |
paraseba
commented
Oct 16, 2024
Sorry, I just missed the argument in the example, definitely we shouldn't drop it. My point was about returning |
Meanwhile, I tried to revert the return type from As for the |
paraseba
commented
Oct 16, 2024
It's definitely not a big deal, |
DimitriPapadopoulos
commented
Oct 16, 2024
OK, let me try then. It's just that's I'll have to modify all child classes. |
844ccad to
8d3ead3CompareUh oh!
There was an error while loading. Please reload this page.
| if p.is_file(): | ||
| yield str(p).replace(to_strip, "") | ||
| allfiles = [str(p).replace(to_strip, "") for p in self.root.rglob("*") if p.is_file()] | ||
| return (onefile for onefile in allfiles) |
There was a problem hiding this comment.
we don't want to materialize the full allfiles list in memory. Can you use async for instead? Here is an example of how you could do this:
fromcollections.abcimportAsyncIteratorfromabcimportABC, abstractmethodclassFoo(ABC):
@abstractmethodasyncdeffoo(self) ->AsyncIterator[str]:
...
classBar(Foo):
asyncdefhelper(self) ->AsyncIterator[str]:
raiseValueError("")
asyncdeffoo(self) ->AsyncIterator[str]:
return (xasyncforxinawaitself.helper())This code should work and mypy successfully, and doesn't materialize the results of calling helper.
There was a problem hiding this comment.
I'm a little bit lost here.
- What we have here are functions that yield. That's a generator. Why create an iterator?
- I'm afraid I don't have enough experience with
asyncand no time to learn it in the short term. For example, I'm not even sure how to identify iterables and awaitables.
I suggest We keep AsyncGenerator for now. What would be the benefit of an AsyncIterator in this context?
8d3ead3 to
f2d2683Compare97d384a to
2efe135Compare2efe135 to
a0b8bf0Compare1ae24a6 to
93ff6f2Compare5209fac to
c90c23aComparejhamman
commented
Nov 5, 2024
@DimitriPapadopoulos - are you planning to return to this? |
80c5fff to
655a149CompareDimitriPapadopoulos
commented
Nov 5, 2024
I tried briefly, but I cannot get typing to work after rebasing. I need to take a thorough look. |
655a149 to
56764daCompare56764da to
8c48380CompareDimitriPapadopoulos
commented
Nov 7, 2024
113e9cd to
6c8dd5cCompare1a824a5 to
3fa0e1dCompare3fa0e1d to
667ec8dCompare
jhamman
left a comment
There was a problem hiding this comment.
I'm happy here (except for the requested docstring changes).
| Notes | ||
| ----- | ||
| This method should be async, | ||
| `How to correctly specify type hints with AsyncGenerator and AsyncContextManager <https://stackoverflow.com/questions/68905848/how-to-correctly-specify-type-hints-with-asyncgenerator-and-asynccontextmanager>`_ | ||
| explains why it is not. |
There was a problem hiding this comment.
I'd like to move this to a comment rather than the public docstring. Most implementations will inherit this and end users don't need to know about this implementation detail.
There was a problem hiding this comment.
Yes, I wasn't sure about it. I put it in the documentation because it documents an inconsistency in function signatures.
There was a problem hiding this comment.
Ideally, I would document this using something similar to disabling Pylint warning W0236:
# pylint: disable=invalid-overridden-method
Unfortunately there's no equivalent rule in ruff, as far as I can see.
667ec8d to
63b0438Compare63b0438 to
782bfa4Compare
Fixes#2377.
See microsoft/pyright#4741.
TODO: