mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-09 13:18:18 +00:00
[ty] Detect illegal non-enum attribute accesses in Literal annotation
This commit is contained in:
parent
897889d1ce
commit
cbc8c08016
3 changed files with 28 additions and 8 deletions
|
@ -51,6 +51,13 @@ invalid4: Literal[
|
|||
hello, # error: [invalid-type-form]
|
||||
(1, 2, 3), # error: [invalid-type-form]
|
||||
]
|
||||
|
||||
class NotAnEnum:
|
||||
x: int = 1
|
||||
|
||||
# error: [invalid-type-form]
|
||||
def _(invalid: Literal[NotAnEnum.x]) -> None:
|
||||
reveal_type(invalid) # revealed: Unknown
|
||||
```
|
||||
|
||||
## Shortening unions of literals
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue