facebook / facebook/pyrefly

implicit-any-empty-container raised on chained assignment

Open
#3,969 6 comments 0 reactions 1 assignee Claimed by @ak4-sh View on GitHub
typechecking
Dominant language
Rust
Stars
7k
Forks
516
PR merge metrics
No merged PRs in 30d

Description

### Describe the Bug

pyrefly is able to infer the empty container type in the following code:

```python
key: str = "foo"
table: dict[str, dict[str, int]] = {}
foo = table.get(key, None)
if foo is None:
foo = {}
table[key] = foo
```

however, if chained assignment is used to save one line, then pyrefly now reports an implicit-any-empty-container error:
```python
key: str = "foo"
table: dict[str, dict[str, int]] = {}
foo = table.get(key, None)
if foo is None:
foo = table[key] = {} # pyrefly reports error here
```

The chain assignment order does not matter, this also fails:
```python
key: str = "foo"
table: dict[str, dict[str, int]] = {}
foo = table.get(key, None)
if foo is None:
table[key] = foo = {} # pyrefly reports error here
```

### 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.