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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6141,6 +6141,7 @@ def visit_yield_from_expr(self, e: YieldFromExpr, allow_none_return: bool = Fals
generic_generator_type = self.chk.named_generic_type(
"typing.Generator", [any_type, any_type, any_type]
)
generic_generator_type.set_line(e)
iter_type, _ = self.check_method_call_by_name(
"__iter__", subexpr_type, [], [], context=generic_generator_type
)
Expand Down
14 changes: 14 additions & 0 deletions test-data/unit/check-statements.test
Original file line number Diff line number Diff line change
Expand Up @@ -2283,6 +2283,20 @@ def get_strings(foo: bool) -> Iterator[str]:
yield "bar2"
[builtins fixtures/tuple.pyi]

[case testYieldFromInvalidType]
from collections.abc import Iterator

class A:
def list(self) -> None: ...

def foo(self) -> list[int]: # E: Function "__main__.A.list" is not valid as a type \
# N: Perhaps you need "Callable[...]" or a callback protocol?
return []

def fn() -> Iterator[int]:
yield from A().foo() # E: "list?[builtins.int]" has no attribute "__iter__" (not iterable)
[builtins fixtures/tuple.pyi]

[case testNoCrashOnStarRightHandSide]
x = *(1, 2, 3) # E: can't use starred expression here
[builtins fixtures/tuple.pyi]
Expand Down