facebook / facebook/pyrefly

Ignored `issubclass(categories, enum.Enum)` check

Open
#3,283 2 comments 0 reactions 1 assignee Claimed by @asukaminato0721 View on GitHub
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 Iterable
import enum

def main(categories: Iterable[str] | type[enum.Enum]) -> None:
cached_categories: tuple[str, ...]
if isinstance(categories, type) and issubclass(categories, enum.Enum):
cached_categories = tuple(member.value for member in categories)
else:
cached_categories = tuple(categories)
```

```console
(scratch) mgorelli@marcoslaptop:~/scratch$ mypy t.py
Success: no issues found in 1 source file
(scratch) mgorelli@marcoslaptop:~/scratch$ pyright t.py
0 errors, 0 warnings, 0 informations
(scratch) mgorelli@marcoslaptop:~/scratch$ ty check t.py
All checks passed!
(scratch) mgorelli@marcoslaptop:~/scratch$ zuban check t.py
Success: no issues found in 1 source file
(scratch) mgorelli@marcoslaptop:~/scratch$ pyrefly check t.py
ERROR `tuple[Enum | str, ...]` is not assignable to variable `cached_categories` with type `tuple[str, ...]` [bad-assignment]
--> t.py:9:29
|
5 | cached_categories: tuple[str, ...]
| --------------- declared type
6 | if isinstance(categories, type) and issubclass(categories, enum.Enum):
7 | cached_categories = tuple(member.value for member in categories)
8 | else:
9 | cached_categories = tuple(categories)
| ^^^^^^^^^^^^^^^^^
|
INFO 1 error
```

Spotted in Narwhals

### Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEALqcROgOZ0Q3G6UN0BJBjEqpssADrouPPnRjoArjSlTMMMHRqpWACgDGqYW14R4iQcNHiYAbTgNKAXToAfRszsLlhAKJKaJwBKOgBaAD46ADlcdBhEKTokukN9AAsYTAB9Q2NTc0ZFYlh7RwAaOkIqp0TkiE0IOFYHDH0YAyMYE0ozOAqmYhgQjExOODhFbH0oVHGOvJ74Cu8aPwCghPRk7ZTUdMyczu7eugBeQuL2mhgabBFCADdUKEUYOjBeLRu7yk4t3K6%2BTgQVqSRgUDg8VBO1SGWyAOO8DOF1g80Bi2BIDKIDIlA0UFIhAYtCgFAAxHQAAqkPFgAl0NBYPD4FKxSBsRSiBgQWKEKQUgDKMDeaQYDGIcEQAHopbj8YTeGwpQopZhcPo4FL9GyIByuTz0FL3p9UE9oGJYKz0OzOUYDXRcMRubE4Hz0GQGGlYqEHiImrFkRIQABmQgARgATEGpLYRNRKHAakppNxeMJMKFMBA8fpub7kQByXXoXgwAtSEsMUJ4gCOimzmVCAGsYKRQns2uNCwB3VCUdDl9AgAC%2B2L2eZgADFoDAKIycAQSORh0A

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