---
source: crates/ty_test/src/lib.rs
expression: snapshot
---
---
mdtest name: for.md - For loops - `__iter__` does not return an iterator
mdtest path: crates/ty_python_semantic/resources/mdtest/loops/for.md
---

# Python source files

## mdtest_snippet.py

```
1 | from typing_extensions import reveal_type
2 | 
3 | class Bad:
4 |     def __iter__(self) -> int:
5 |         return 42
6 | 
7 | # error: [not-iterable]
8 | for x in Bad():
9 |     reveal_type(x)  # revealed: Unknown
```

# Diagnostics

```
error[not-iterable]: Object of type `Bad` is not iterable
 --> src/mdtest_snippet.py:8:10
  |
7 | # error: [not-iterable]
8 | for x in Bad():
  |          ^^^^^
9 |     reveal_type(x)  # revealed: Unknown
  |
info: Its `__iter__` method returns an object of type `int`, which has no `__next__` method
info: rule `not-iterable` is enabled by default

```

```
info[revealed-type]: Revealed type
 --> src/mdtest_snippet.py:9:17
  |
7 | # error: [not-iterable]
8 | for x in Bad():
9 |     reveal_type(x)  # revealed: Unknown
  |                 ^ `Unknown`
  |

```
