facebook / facebook/pyrefly

Tuple-Unpacking defeats first-use inference of empty containers

Open
#4,522 3 comments 0 reactions 1 assignee Claimed by @zfaustk View on GitHub
stale typechecking
Dominant language
Rust
Stars
7k
Forks
516
PR merge metrics
No merged PRs in 30d

Description

### Describe the Bug

If I have:
```python
def single_assignment() -> None:
xs = []

xs.append(1) # inferred as list[int] -- no error

def tuple_unpacking() -> None:
xs, ys = [], []
xs.append(1) # same appends, but both targets error
ys.append(2)
```

The LSP shows that `xs` is a `list[int]` with `single_assignment`, but is `list[Unknown}` in the `tuple_unpacking`). It feels the tuple unpacking shouldn't count as "first use" and `xs, ys = [], []` should be basically the same as `xs = []; ys = []`.

### Sandbox Link

https://pyrefly.org/sandbox/?project=v2.pVTLDoIwEPyVTTggCdDo0a_wrobwqEDElkhr5O-ddtUEFS4e23R3ujOzMxeZTkIYpO5khlnxt4sEt5963t2n9piKDykCRKpqtY6IAqhzwtSycoz6NYQ6R0oSUpoZdlqy5Y3FQmZW9Xl5BugPnJhGxopn8Qa4h_gGzwtrqNCmIYPVkuYpKleO78pN9C1jQDu-QEfPCAIM-tcWMQld04MKkJCSGmP6YSvEq1xfayGVqHQ5iEmFIOfY_Ja3Pnyn7Uh72w1o-49_QrZPuOSe0JkHL9Cga8vWJLkaPQpTs2yUBw

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