Thanks to visit codestin.com
Credit goes to github.com

Skip to content

stubgen: Add support for yield statements - #10745

Merged
JelleZijlstra merged 6 commits into
python:masterfrom
srittau:stubgen-yield
Jul 11, 2021
Merged

stubgen: Add support for yield statements#10745
JelleZijlstra merged 6 commits into
python:masterfrom
srittau:stubgen-yield

Conversation

@srittau

@srittau srittau commented Jun 30, 2021

Copy link
Copy Markdown
Contributor

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.

Comment thread mypy/stubgen.py

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

Copy link
Copy Markdown
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
Copy Markdown
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

srittau commented Jul 11, 2021

Copy link
Copy Markdown
Contributor Author

Gentle pingedy pong.

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

Copy link
Copy Markdown
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