You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: crates/ty_python_semantic/resources/mdtest/pep695_type_aliases.md
+30Lines changed: 30 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,6 +40,36 @@ type OptionalInt = int | None
40
40
x: OptionalInt ="1"
41
41
```
42
42
43
+
## No type qualifiers
44
+
45
+
The right-hand side of a type alias definition is a type expression, not an annotation expression.
46
+
Type qualifiers like `ClassVar` and `Final` are only valid in annotation expressions, so they cannot
47
+
appear at the top level of a PEP 695 alias definition:
48
+
49
+
```py
50
+
from typing_extensions import ClassVar, Final, Required, NotRequired, ReadOnly
51
+
from dataclasses import InitVar
52
+
53
+
# error: [invalid-type-form] "Type qualifier `typing.ClassVar` is not allowed in type expressions (only in annotation expressions)"
54
+
type Bad1 = ClassVar[str]
55
+
# error: [invalid-type-form] "Type qualifier `typing.ClassVar` is not allowed in type expressions (only in annotation expressions)"
56
+
type Bad2 = ClassVar
57
+
# error: [invalid-type-form] "Type qualifier `typing.Final` is not allowed in type expressions (only in annotation expressions)"
58
+
type Bad3 = Final[int]
59
+
# error: [invalid-type-form] "Type qualifier `typing.Final` is not allowed in type expressions (only in annotation expressions)"
60
+
type Bad4 = Final
61
+
# error: [invalid-type-form] "Type qualifier `typing.Required` is not allowed in type expressions (only in annotation expressions)"
62
+
type Bad5 = Required[int]
63
+
# error: [invalid-type-form] "Type qualifier `typing.NotRequired` is not allowed in type expressions (only in annotation expressions)"
64
+
type Bad6 = NotRequired[int]
65
+
# error: [invalid-type-form] "Type qualifier `typing.ReadOnly` is not allowed in type expressions (only in annotation expressions)"
66
+
type Bad7 = ReadOnly[int]
67
+
# error: [invalid-type-form] "Type qualifier `dataclasses.InitVar` is not allowed in type expressions (only in annotation expressions)"
68
+
type Bad8 = InitVar[int]
69
+
# error: [invalid-type-form] "Type qualifier `dataclasses.InitVar` is not allowed in type expressions (only in annotation expressions, and only with exactly one argument)"
0 commit comments