facebook / facebook/pyrefly

`Any` declaration before loop ignored

Open
#3,046 3 comments 0 reactions 0 assignees View on GitHub
needs-discussion quansight typechecking
Dominant language
Rust
Stars
7k
Forks
516
PR merge metrics
No merged PRs in 30d

Description

### Describe the Bug

```py
from typing import Protocol, Sequence, reveal_type, Literal, Any
from enum import Enum

def main() -> None:
a: Any
for a in ('b', 3, {'a': 1}):
reveal_type(a)
```

```console
(scratch) marcogorelli@DESKTOP-U8OKFP3:~/scratch$ pyright t.py
/home/marcogorelli/scratch/t.py
/home/marcogorelli/scratch/t.py:7:21 - information: Type of "a" is "Any"
0 errors, 0 warnings, 1 information
(scratch) marcogorelli@DESKTOP-U8OKFP3:~/scratch$ pyrefly check t.py
INFO revealed type: Literal['b', 3] | dict[Any, Any] [reveal-type]
--> t.py:7:20
|
7 | reveal_type(a)
| ---
|
INFO 0 errors
```

I think I'd expect `Any` here too?

### Sandbox Link

_No response_

### (Only applicable for extension issues) IDE Information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.