facebook / facebook/pyrefly

report error when ambiguous `FunctionType` as `Enum` value

Open
#1,131 1 comment 0 reactions 0 assignees View on GitHub
needs-discussion typechecking
Dominant language
Rust
Stars
7k
Forks
519
PR merge metrics
No merged PRs in 30d

Description

### Describe the Bug

```py
from enum import Enum

def f() -> object:
return lambda: 1

class E(Enum):
a = f() # expect error: `object` can potentially be `FunctionType`, wrap this value with `enum.member` to enforce expected runtime behaviour

E.a.name # fails at runtime
```

`FunctionType` becomes a non-member, but currently pyrefly assumes a super type of `FunctionType` is a member, use `enum.member` to override this and make it a member

in this case i would expect `E.a` to become either `Unknown` or a type of `member | non-member`, either way i would expect an error message to be shown on the declaration of `E.a`

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