mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:24:57 +00:00
[ty] Allow annotation expressions to be ast::Attribute
nodes (#20413)
Fixes https://github.com/astral-sh/ty/issues/1187
This commit is contained in:
parent
1f1365a0fa
commit
8341da7f63
2 changed files with 65 additions and 44 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue