-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unreachable yield should still make a function a generator #5972
Comments
…as performed only for `yield` statements, but it's possible to define a generator function that has no reachable yield statements. This addresses #5972.
…as performed only for `yield` statements, but it's possible to define a generator function that has no reachable yield statements. This addresses #5972.
Pyright validates that the annotated return type of a generator function is compatible with I've enhanced the logic that validates the annotated return address for a generator so it is performed regardless of whether a |
This is addressed in pyright 1.1.328, which I just published. It will also be included in a future release of pylance. |
Describe the bug
According to https://docs.python.org/3/reference/expressions.html#yieldexpr, when a function contains a
yield
expression, it becomes a generator function, regardless of the reachability of thatyield
expression. But in the code below, an unconditionalreturn
makes theyield
unreachable and pyright seems to stop type checking as soon as it sees thereturn
.This function signature is accepted by pyright but seems incorrect, since the presence of the
yield
keyword, even if unreachable, turns this function into a generator function. Callingfoo()
as written gives me<generator object foo at 0x12dfd54e0>
rather than the promisedNone
.Removing the
return
, I get the expected error message:I believe this to be a bug and I couldn't find a duplicate, but I'm definitely no expert so I'm sorry if I'm off about something here.
VS Code extension or command-line
Pylance v2023.9.10
The text was updated successfully, but these errors were encountered: