Skip to content

Commit b1ce8a3

Browse files
Use Never instead of None for stores (#13984)
## Summary See: #13981 (comment)
1 parent 262c04f commit b1ce8a3

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

crates/red_knot_python_semantic/resources/mdtest/unpacking.md

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ reveal_type(b) # revealed: Literal[2]
8181

8282
```py
8383
# TODO: Add diagnostic (need more values to unpack)
84-
# TODO: Remove 'not-iterable' diagnostic
85-
[a, *b, c, d] = (1, 2) # error: "Object of type `None` is not iterable"
84+
[a, *b, c, d] = (1, 2)
8685
reveal_type(a) # revealed: Literal[1]
8786
# TODO: Should be list[Any] once support for assigning to starred expression is added
8887
reveal_type(b) # revealed: @Todo
@@ -93,7 +92,7 @@ reveal_type(d) # revealed: Unknown
9392
### Starred expression (2)
9493

9594
```py
96-
[a, *b, c] = (1, 2) # error: "Object of type `None` is not iterable"
95+
[a, *b, c] = (1, 2)
9796
reveal_type(a) # revealed: Literal[1]
9897
# TODO: Should be list[Any] once support for assigning to starred expression is added
9998
reveal_type(b) # revealed: @Todo
@@ -103,8 +102,7 @@ reveal_type(c) # revealed: Literal[2]
103102
### Starred expression (3)
104103

105104
```py
106-
# TODO: Remove 'not-iterable' diagnostic
107-
[a, *b, c] = (1, 2, 3) # error: "Object of type `None` is not iterable"
105+
[a, *b, c] = (1, 2, 3)
108106
reveal_type(a) # revealed: Literal[1]
109107
# TODO: Should be list[int] once support for assigning to starred expression is added
110108
reveal_type(b) # revealed: @Todo
@@ -114,8 +112,7 @@ reveal_type(c) # revealed: Literal[3]
114112
### Starred expression (4)
115113

116114
```py
117-
# TODO: Remove 'not-iterable' diagnostic
118-
[a, *b, c, d] = (1, 2, 3, 4, 5, 6) # error: "Object of type `None` is not iterable"
115+
[a, *b, c, d] = (1, 2, 3, 4, 5, 6)
119116
reveal_type(a) # revealed: Literal[1]
120117
# TODO: Should be list[int] once support for assigning to starred expression is added
121118
reveal_type(b) # revealed: @Todo
@@ -126,8 +123,7 @@ reveal_type(d) # revealed: Literal[6]
126123
### Starred expression (5)
127124

128125
```py
129-
# TODO: Remove 'not-iterable' diagnostic
130-
[a, b, *c] = (1, 2, 3, 4) # error: "Object of type `None` is not iterable"
126+
[a, b, *c] = (1, 2, 3, 4)
131127
reveal_type(a) # revealed: Literal[1]
132128
reveal_type(b) # revealed: Literal[2]
133129
# TODO: Should be list[int] once support for assigning to starred expression is added
@@ -215,8 +211,7 @@ reveal_type(b) # revealed: LiteralString
215211

216212
```py
217213
# TODO: Add diagnostic (need more values to unpack)
218-
# TODO: Remove 'not-iterable' diagnostic
219-
(a, *b, c, d) = "ab" # error: "Object of type `None` is not iterable"
214+
(a, *b, c, d) = "ab"
220215
reveal_type(a) # revealed: LiteralString
221216
# TODO: Should be list[LiteralString] once support for assigning to starred expression is added
222217
reveal_type(b) # revealed: @Todo
@@ -227,7 +222,7 @@ reveal_type(d) # revealed: Unknown
227222
### Starred expression (2)
228223

229224
```py
230-
(a, *b, c) = "ab" # error: "Object of type `None` is not iterable"
225+
(a, *b, c) = "ab"
231226
reveal_type(a) # revealed: LiteralString
232227
# TODO: Should be list[Any] once support for assigning to starred expression is added
233228
reveal_type(b) # revealed: @Todo
@@ -237,8 +232,7 @@ reveal_type(c) # revealed: LiteralString
237232
### Starred expression (3)
238233

239234
```py
240-
# TODO: Remove 'not-iterable' diagnostic
241-
(a, *b, c) = "abc" # error: "Object of type `None` is not iterable"
235+
(a, *b, c) = "abc"
242236
reveal_type(a) # revealed: LiteralString
243237
# TODO: Should be list[LiteralString] once support for assigning to starred expression is added
244238
reveal_type(b) # revealed: @Todo
@@ -248,8 +242,7 @@ reveal_type(c) # revealed: LiteralString
248242
### Starred expression (4)
249243

250244
```py
251-
# TODO: Remove 'not-iterable' diagnostic
252-
(a, *b, c, d) = "abcdef" # error: "Object of type `None` is not iterable"
245+
(a, *b, c, d) = "abcdef"
253246
reveal_type(a) # revealed: LiteralString
254247
# TODO: Should be list[LiteralString] once support for assigning to starred expression is added
255248
reveal_type(b) # revealed: @Todo
@@ -260,8 +253,7 @@ reveal_type(d) # revealed: LiteralString
260253
### Starred expression (5)
261254

262255
```py
263-
# TODO: Remove 'not-iterable' diagnostic
264-
(a, b, *c) = "abcd" # error: "Object of type `None` is not iterable"
256+
(a, b, *c) = "abcd"
265257
reveal_type(a) # revealed: LiteralString
266258
reveal_type(b) # revealed: LiteralString
267259
# TODO: Should be list[int] once support for assigning to starred expression is added

crates/red_knot_python_semantic/src/types/infer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,11 +1414,11 @@ impl<'db> TypeInferenceBuilder<'db> {
14141414
// Resolve the target type, assuming a load context.
14151415
let target_type = match &**target {
14161416
Expr::Name(name) => {
1417-
self.store_expression_type(target, Type::None);
1417+
self.store_expression_type(target, Type::Never);
14181418
self.infer_name_load(name)
14191419
}
14201420
Expr::Attribute(attr) => {
1421-
self.store_expression_type(target, Type::None);
1421+
self.store_expression_type(target, Type::Never);
14221422
self.infer_attribute_load(attr)
14231423
}
14241424
_ => self.infer_expression(target),
@@ -2506,7 +2506,7 @@ impl<'db> TypeInferenceBuilder<'db> {
25062506
fn infer_name_expression(&mut self, name: &ast::ExprName) -> Type<'db> {
25072507
match name.ctx {
25082508
ExprContext::Load => self.infer_name_load(name),
2509-
ExprContext::Store | ExprContext::Del => Type::None,
2509+
ExprContext::Store | ExprContext::Del => Type::Never,
25102510
ExprContext::Invalid => Type::Unknown,
25112511
}
25122512
}
@@ -2536,7 +2536,7 @@ impl<'db> TypeInferenceBuilder<'db> {
25362536
ExprContext::Load => self.infer_attribute_load(attribute),
25372537
ExprContext::Store | ExprContext::Del => {
25382538
self.infer_expression(value);
2539-
Type::None
2539+
Type::Never
25402540
}
25412541
ExprContext::Invalid => {
25422542
self.infer_expression(value);

0 commit comments

Comments
 (0)