Repository navigation
Raise ValueError for None in Stmt lists to match CPython validator - #7670
Conversation
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).
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe PR enhances the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] lib: cpython/Lib/ast.py dependencies:
dependent tests: (136 tests)
Legend:
|
…7670) Sibling fix to #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 #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).
Sibling fix to #7656 (which handled
Vec<Expr>). The same catch-allTypeError(\"expected some sort of stmt, but got {}\")inStmt::ast_from_objectsilently swallowedNone, socompile()on an AST withNonein a statement-list field (ClassDef.body,Try.body,For.body, etc.) raisedTypeErrorwhere CPython raisesValueError(\"None disallowed in statement list\").Fix
One check in
Stmt::ast_from_object(crates/vm/src/stdlib/_ast/statement.rs) before the catch-all, matching the Expr-side shape from #7656:Option<Stmt>positions are unaffected —node.rsOption<T>::ast_from_objectshort-circuitsNoneearlier.Verification
CPython 3.13.4 baseline message:
After the fix, RustPython raises the byte-identical message for
ClassDef,For,While,Try, andFunctionDefbody positions.Full
test.test_ast.test_astsuite (227 tests):0 failures, 0 unexpected successes. One less expected failure than upstream/main (was 39), corresponding to
test_classdefunmasked.Unmasks
ASTValidatorTests.test_classdef(was@unittest.expectedFailure;body=[None]sub-case now passes)Part of the skip-test inventory in #7611.
Summary by CodeRabbit
Nonevalues are encountered instead of generic type errors.