Conversation
Helps to ensure the generated type stubs are compatible with it
Tpt
commented
Mar 20, 2026
| } | ||
| } | ||
|
|
||
| fn send(&mut self, value: Bound<'_, PyAny>) -> PyResult<Py<PyAny>> { |
Contributor
Author
There was a problem hiding this comment.
needed to make sure that IterAwaitable is a Generator
Member
There was a problem hiding this comment.
Why does pyrefly require that?
Contributor
Author
There was a problem hiding this comment.
Pyrefly requires that await is called on an Awaitable that is defined in typeshed as:
@runtime_checkable
class Awaitable(Protocol[_T_co]):
@abstractmethod
def __await__(self) -> Generator[Any, Any, _T_co]: ...so, because IterAwaitable.__await__ returns IterAwaitable then IterAwaitable must be a Generator that is defined as:
@runtime_checkable
class Generator(Iterator[_YieldT_co], Protocol[_YieldT_co, _SendT_contra, _ReturnT_co]):
def __next__(self) -> _YieldT_co: ...
@abstractmethod
def send(self, value: _SendT_contra, /) -> _YieldT_co: ...
@overload
@abstractmethod
def throw(
self, typ: type[BaseException], val: BaseException | object = None, tb: TracebackType | None = None, /
) -> _YieldT_co: ...
@overload
@abstractmethod
def throw(self, typ: BaseException, val: None = None, tb: TracebackType | None = None, /) -> _YieldT_co: ...
if sys.version_info >= (3, 13):
def close(self) -> _ReturnT_co | None: ...
else:
def close(self) -> None: ...
def __iter__(self) -> Generator[_YieldT_co, _SendT_contra, _ReturnT_co]: ...Hence the need for send, throw and close methods.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Helps to ensure the generated type stubs are compatible with it