pylint icon indicating copy to clipboard operation
pylint copied to clipboard

False positive assignment-from-no-return on generator with nested yield expression

Open troiganto opened this issue 4 months ago • 0 comments

Bug description

This seems to be the same bug as #3904 but only affecting _nested_ yield expressions. The below example is adapted from the original issue.


# pylint: disable = disallowed-name
# pylint: disable = invalid-name
# pylint: disable = missing-function-docstring
# pylint: disable = missing-module-docstring

from typing import Callable, Generator

CHUNK_SIZE = 5


def chunk(handler: Callable[[str], None]) -> Generator[None, str, None]:
    buf = ""
    while True:
        while len(buf) < CHUNK_SIZE:
            buf += str((yield))  # Double parens required by Python syntax
        head, buf = buf[:CHUNK_SIZE], buf[CHUNK_SIZE:]

        handler(head)


def handle(contents: str) -> None:
    print(f"Got: {contents}")


streamer = chunk(handle)
next(streamer)  # start streaming
streamer.send("foo")

Configuration

No response

Command used

pylint a.py

Pylint output

************* Module example
example.py:25: [E1111(assignment-from-no-return), ] Assigning result of a function call, where the function has no return

Expected behavior

No message

Pylint version

pylint 3.0.4
astroid 3.0.1
Python 3.12.2 (main, Feb 21 2024, 00:00:00) [GCC 13.2.1 20231205 (Red Hat 13.2.1-6)]

OS / Environment

Fedora release 39 (Thirty Nine), inside a Silverblue toolbox

Additional dependencies

No response

troiganto avatar Mar 04 '24 10:03 troiganto