From 63ca2a1dfe6bf28f06b4d491860d2193e030ee8e Mon Sep 17 00:00:00 2001 From: STerliakov Date: Thu, 23 Jan 2025 18:12:19 +0100 Subject: [PATCH 1/2] Add missing lineno --- mypy/checkexpr.py | 1 + test-data/unit/check-statements.test | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index a10dc00bb1dea..0752fa0b466fb 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -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 ) diff --git a/test-data/unit/check-statements.test b/test-data/unit/check-statements.test index 44880cf352043..3a2cbde748807 100644 --- a/test-data/unit/check-statements.test +++ b/test-data/unit/check-statements.test @@ -2283,6 +2283,19 @@ 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]: + return [] + +def fn() -> Iterator[int]: + yield from A().foo() +[builtins fixtures/tuple.pyi] + [case testNoCrashOnStarRightHandSide] x = *(1, 2, 3) # E: can't use starred expression here [builtins fixtures/tuple.pyi] From 72a596a3c19a1f8ca002382211f4ac4d0972f28b Mon Sep 17 00:00:00 2001 From: STerliakov Date: Thu, 23 Jan 2025 18:39:18 +0100 Subject: [PATCH 2/2] ...I forgot to commit the test results. --- test-data/unit/check-statements.test | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test-data/unit/check-statements.test b/test-data/unit/check-statements.test index 3a2cbde748807..14904bc32e1bf 100644 --- a/test-data/unit/check-statements.test +++ b/test-data/unit/check-statements.test @@ -2289,11 +2289,12 @@ from collections.abc import Iterator class A: def list(self) -> None: ... - def foo(self) -> list[int]: + 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() + yield from A().foo() # E: "list?[builtins.int]" has no attribute "__iter__" (not iterable) [builtins fixtures/tuple.pyi] [case testNoCrashOnStarRightHandSide]