facebook / facebook/pyrefly

UnionType should not be assignable to type

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

Description

### Describe the Bug

Pyrefly does not distinguish `UnionType` from `type`. Both `Optional[X]` (which is `Union[X, None]`) and `X | None` are accepted where `type` is expected, but neither is an instance of `type` at runtime.

### Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEALqcROgOZ0Q3G6UN0B5Ygwi50qKAB1006Zhhg6qAMbKYwuAH0mxGAAoGiRsxgBKOgFoAfHQByYmIml0XdSSHfuACqkqoaMAwwlIx0MPi6ygxwSnTKUKhwMXqscAwYanS4ijpmADR06Lj8qMa6YRGU8HCi6ISeHh7ornTEiXCyMugAxHQAKgAW8DB0cAO4AK5QmK3tdIAoBJzoJVijDCG%2BI-Ht8HQp6GkZu9llZtIqahraJvsMpueq6tHXunpplPddvQBCxQNZOSGcBGY0m0zClGoIUWQhEYgkAG1WAwALpKVbIugAHzsDiUVToAFV0LU%2BiYCkV%2BLlpL0IDUDul0Go9LDaojkSiCrlzHS6AAxCTAmmcemHJn6TE4%2BzoGBckw8mICqBC8SPK65FnCNlQJHLFGfC5PLQayW4mWmEB5EBkKpgKCkQgMWhQCi9LykW320YYHAEOJiSBsCZ%2BOF1YUAZRgIwGDAYxDgiAA9ImbQp7YReGxEzB0InMLhlHBE8oAxAgyHaom6GBeEoAG6oaCobCwf3oQPB1ChrJasRweroMgMcboCx14I1MR0AC8bhAAGZCABGABMnnQCOCULgKOkExJ3F4QUwFkwECqUQg45ndAA5GWilVb9JKRYqgBHCbnmAngDWMFICxDSSG9bwAd18dBn3QEAAF8rRUERxz5aAYAoNAsDwIgyDgoA

As seen from the sandbox link, Pyrefly does not error properly

Both Optional[int] and int | None should be rejected where type or type[Any] is expected. They evaluate to UnionType at runtime, not type.

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.