[ty] Recognise functions containing yield from expressions as being generator functions (#17930)

This commit is contained in:
Alex Waygood
2025-05-07 23:29:44 +01:00
committed by GitHub
parent 2cf5cba7ff
commit 51cef5a72b
3 changed files with 30 additions and 24 deletions

View File

@@ -345,7 +345,7 @@ def f(cond: bool) -> str:
<!-- snapshot-diagnostics -->
A function with a `yield` statement anywhere in its body is a
A function with a `yield` or `yield from` expression anywhere in its body is a
[generator function](https://docs.python.org/3/glossary.html#term-generator). A generator function
implicitly returns an instance of `types.GeneratorType` even if it does not contain any `return`
statements.
@@ -366,6 +366,9 @@ def h() -> typing.Iterator:
def i() -> typing.Iterable:
yield 42
def i2() -> typing.Generator:
yield from i()
def j() -> str: # error: [invalid-return-type]
yield 42
```