[ty] Detect illegal non-enum attribute accesses in Literal annotation

This commit is contained in:
David Peter 2025-07-22 09:18:50 +02:00
parent 897889d1ce
commit cbc8c08016
3 changed files with 28 additions and 8 deletions

View file

@ -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