Skip to content

Missing line number for yield from an invalid type #18517

@sterliakov

Description

@sterliakov

Bug Report

Error for yield from from a malformed type that isn't Iterable is missing line number. This prevents me even from suppressing the error inline.

I wasn't able to reproduce it with simpler "bad" types. Direct attribute access works as intended.

To Reproduce

playground

from collections.abc import Iterator

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

    def foo(self) -> list[int]:
        return []

def fn() -> Iterator[int]:
    A().foo().sort()
    yield from A().foo()

Expected Behavior

attr-defined error correctly attached to yield from line.

Actual Behavior

main.py: error: "list?[builtins.int]" has no attribute "__iter__" (not iterable)  [attr-defined]
main.py:6: error: Function "__main__.A.list" is not valid as a type  [valid-type]
main.py:6: note: Perhaps you need "Callable[...]" or a callback protocol?
main.py:10: error: "list?[builtins.int]" has no attribute "sort"  [attr-defined]

Your Environment

  • Mypy version used: 1.14.1, master (#58de753b6b76227ff726e9ce1888cfc24c7ba44b)
  • Mypy command-line flags: both --strict and without it
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions