[ty] Allow annotation expressions to be ast::Attribute nodes (#20413)

Fixes https://github.com/astral-sh/ty/issues/1187
This commit is contained in:
Alex Waygood 2025-09-15 12:06:48 +01:00 committed by GitHub
parent 1f1365a0fa
commit 8341da7f63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 65 additions and 44 deletions

View file

@ -9,6 +9,7 @@ For more details on the semantics of pure class variables, see [this test](../at
## Basic
```py
import typing
from typing import ClassVar, Annotated
class C:
@ -17,12 +18,14 @@ class C:
c: ClassVar[Annotated[int, "the annotation for c"]] = 1
d: ClassVar = 1
e: "ClassVar[int]" = 1
f: typing.ClassVar = 1
reveal_type(C.a) # revealed: int
reveal_type(C.b) # revealed: int
reveal_type(C.c) # revealed: int
reveal_type(C.d) # revealed: Unknown | Literal[1]
reveal_type(C.e) # revealed: int
reveal_type(C.f) # revealed: Unknown | Literal[1]
c = C()
@ -36,6 +39,8 @@ c.c = 2
c.d = 2
# error: [invalid-attribute-access]
c.e = 2
# error: [invalid-attribute-access]
c.f = 3
```
## From stubs