[ty] Support iterating over enums (#19486)
## Summary
Infer the correct type in a scenario like this:
```py
class Color(Enum):
RED = 1
GREEN = 2
BLUE = 3
for color in Color:
reveal_type(color) # revealed: Color
```
We should eventually support this out-of-the-box when
https://github.com/astral-sh/ty/issues/501 is implemented. For this
reason, @AlexWaygood would prefer to keep things as they are (we
currently infer `Unknown`, so false positives seem unlikely). But it
seemed relatively easy to support, so I'm opening this for discussion.
part of https://github.com/astral-sh/ty/issues/183
## Test Plan
Adapted existing test.
## Ecosystem analysis
```diff
- warning[unused-ignore-comment] rotkehlchen/chain/aggregator.py:591:82: Unused blanket `type: ignore` directive
```
This `unused-ignore-comment` goes away due to a new true positive.
This commit is contained in:
@@ -406,8 +406,7 @@ class Color(Enum):
|
||||
BLUE = 3
|
||||
|
||||
for color in Color:
|
||||
# TODO: Should be `Color`
|
||||
reveal_type(color) # revealed: Unknown
|
||||
reveal_type(color) # revealed: Color
|
||||
|
||||
# TODO: Should be `list[Color]`
|
||||
reveal_type(list(Color)) # revealed: list[Unknown]
|
||||
|
||||
Reference in New Issue
Block a user