Skip to content

Commit 6ecd7c6

Browse files
committed
slightly expand tests
1 parent 00c073b commit 6ecd7c6

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

crates/ty_python_semantic/resources/mdtest/dataclasses/dataclasses.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,22 @@ reveal_type(D.__init__) # revealed: (self: D, x: int) -> None
110110
```
111111

112112
If attributes without default values are declared after attributes with default values, a
113-
`TypeError` will be raised at runtime. Ideally, we would emit a diagnostic in that case:
113+
`TypeError` will be raised at runtime. We emit a diagnostic in that case:
114114

115115
```py
116+
from dataclasses import field
117+
116118
@dataclass
117119
class D:
118120
x: int = 1
119121
# error: [dataclass-field-order] "Required field `y` cannot be defined after fields with default values"
120122
y: str
123+
124+
@dataclass
125+
class E:
126+
x: int = field(default=3)
127+
# error: [dataclass-field-order]
128+
y: str
121129
```
122130

123131
Pure class attributes (`ClassVar`) are not included in the signature of `__init__`:

0 commit comments

Comments
 (0)