Skip to content

pytest: typecheck with pyrefly#5898

Open
Tpt wants to merge 1 commit intoPyO3:mainfrom
Tpt:tpt/pyrefly
Open

pytest: typecheck with pyrefly#5898
Tpt wants to merge 1 commit intoPyO3:mainfrom
Tpt:tpt/pyrefly

Conversation

@Tpt
Copy link
Contributor

@Tpt Tpt commented Mar 20, 2026

Helps to ensure the generated type stubs are compatible with it

Helps to ensure the generated type stubs are compatible with it
@Tpt Tpt added the CI-skip-changelog Skip checking changelog entry label Mar 20, 2026
}
}

fn send(&mut self, value: Bound<'_, PyAny>) -> PyResult<Py<PyAny>> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needed to make sure that IterAwaitable is a Generator

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does pyrefly require that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Tpt Tpt marked this pull request as ready for review March 20, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI-skip-changelog Skip checking changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants