Skip to content

Commit 0913563

Browse files
Raise ValueError for None in Stmt lists to match CPython validator (RustPython#7670)
Sibling fix to RustPython#7656 (which handled Vec<Expr>). The same catch-all TypeError ("expected some sort of stmt, but got {}") in Stmt::ast_from_object silently swallowed None, so compile() on an AST with None in a statement-list field (ClassDef.body, Try.body, For.body, etc.) raised TypeError where CPython raises ValueError("None disallowed in statement list"). Add an is_none check before the catch-all, matching the Expr-side shape introduced in RustPython#7656. Option<Stmt> positions are unaffected — they short-circuit None earlier in node.rs. Unmasks test_classdef (body=[None] sub-case). Full test.test_ast.test_ast run: 227 tests, 0 unexpected successes, 38 expected failures (was 39).
1 parent 1ab76d0 commit 0913563

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

Lib/test/test_ast/test_ast.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2108,7 +2108,6 @@ def foo(bar) -> pacarana:
21082108
self.assertIsInstance(funcdef, ast.FunctionDef)
21092109
self.assertTrue(matcher(funcdef))
21102110

2111-
@unittest.expectedFailure # TODO: RUSTPYTHON; ValueError not raised
21122111
def test_classdef(self):
21132112
def cls(bases=None, keywords=None, body=None, decorator_list=None, type_params=None):
21142113
if bases is None:

crates/vm/src/stdlib/_ast/statement.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ impl Node for ast::Stmt {
135135
source_file,
136136
_object,
137137
)?)
138+
} else if _vm.is_none(&_object) {
139+
return Err(_vm.new_value_error("None disallowed in statement list"));
138140
} else {
139141
return Err(_vm.new_type_error(format!(
140142
"expected some sort of stmt, but got {}",

0 commit comments

Comments
 (0)