KEMBAR78
stubgen: Add support for yield statements by srittau · Pull Request #10745 · python/mypy · GitHub
Skip to content

Conversation

srittau
Copy link
Contributor

@srittau srittau commented Jun 30, 2021

Description

Stubgen: Support functions that yield values:

def foo():
    x = yield 123
    return ""
def bar():
    yield

will be generated as:

from collections.abc import Generator
from typing import Any

def foo() -> Generator[Any, Any, Any]: ...
def bar() -> Generator[None, None, None]: ...

Before this change, these function were annotated with a None return type.

This PR doesn't support yield from expressions (see #10744).

Test Plan

Tests for this feature and a few corner cases were added.

The import will be internal to the stub.
"""
name = self.typing_name(name)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The name typing_name is not really correct anymore, since we use it for collections.abc as well. Should we rename it?

Copy link
Member

Choose a reason for hiding this comment

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

I don't feel strongly, it's still a typing concept even if it lives in collections.abc.

@srittau
Copy link
Contributor Author

srittau commented Jul 11, 2021

Gentle pingedy pong.

@JelleZijlstra JelleZijlstra merged commit d569ccc into python:master Jul 11, 2021
@JelleZijlstra
Copy link
Member

Thanks! I even ran into this when writing the beautifulsoup stubs the other day :)

@srittau srittau deleted the stubgen-yield branch July 11, 2021 14:50
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

Successfully merging this pull request may close these issues.

2 participants