diff --git a/Lib/codeop.py b/Lib/codeop.py index 4dd096574bb..96868047cb4 100644 --- a/Lib/codeop.py +++ b/Lib/codeop.py @@ -66,7 +66,12 @@ def _maybe_compile(compiler, source, filename, symbol): compiler(source + "\n", filename, symbol) return None except SyntaxError as e: - if "incomplete input" in str(e): + # XXX: RustPython; support multiline definitions in REPL + # See also: https://github.com/RustPython/RustPython/pull/5743 + strerr = str(e) + if source.endswith(":") and "expected an indented block" in strerr: + return None + elif "incomplete input" in str(e): return None # fallthrough diff --git a/src/shell.rs b/src/shell.rs index f733e03ddc4..cbe2c9efe0f 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -49,13 +49,16 @@ fn shell_exec( let bad_error = match err { CompileError::Parse(ref p) => { - if matches!( - p.error, - ParseErrorType::Lexical(LexicalErrorType::IndentationError) - ) { - continuing // && p.location.is_some() - } else { - true // !matches!(p, ParseErrorType::UnrecognizedToken(Tok::Dedent, _)) + match &p.error { + ParseErrorType::Lexical(LexicalErrorType::IndentationError) => continuing, // && p.location.is_some() + ParseErrorType::OtherError(msg) => { + if msg.starts_with("Expected an indented block") { + continuing + } else { + true + } + } + _ => true, // !matches!(p, ParseErrorType::UnrecognizedToken(Tok::Dedent, _)) } } _ => true, // It is a bad error for everything else