From 39e0d5e14f7f6815af867d2c2662b8fdcf3ddd4d Mon Sep 17 00:00:00 2001 From: Aneesh Durg Date: Thu, 24 Apr 2025 11:47:49 -0500 Subject: [PATCH 1/3] Support multiline function/class definitions in REPL and InteractiveConsole --- Lib/codeop.py | 5 ++++- src/shell.rs | 17 ++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Lib/codeop.py b/Lib/codeop.py index 4dd096574b..8aa2d6b148 100644 --- a/Lib/codeop.py +++ b/Lib/codeop.py @@ -66,7 +66,10 @@ def _maybe_compile(compiler, source, filename, symbol): compiler(source + "\n", filename, symbol) return None except SyntaxError as e: - if "incomplete input" in str(e): + 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 f733e03ddc..549f68ae64 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 From 8c4e62f2e4c4c04e517fd2d7f81e43b87d086b7d Mon Sep 17 00:00:00 2001 From: Aneesh Durg Date: Thu, 24 Apr 2025 14:13:37 -0500 Subject: [PATCH 2/3] lint --- src/shell.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shell.rs b/src/shell.rs index 549f68ae64..cbe2c9efe0 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -58,7 +58,7 @@ fn shell_exec( true } } - _ => true, // !matches!(p, ParseErrorType::UnrecognizedToken(Tok::Dedent, _)) + _ => true, // !matches!(p, ParseErrorType::UnrecognizedToken(Tok::Dedent, _)) } } _ => true, // It is a bad error for everything else From ffb051c603d69ea677656d7a127b81c182264072 Mon Sep 17 00:00:00 2001 From: "Jeong, YunWon" <69878+youknowone@users.noreply.github.com> Date: Wed, 30 Apr 2025 14:52:57 +0900 Subject: [PATCH 3/3] Update Lib/codeop.py --- Lib/codeop.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/codeop.py b/Lib/codeop.py index 8aa2d6b148..96868047cb 100644 --- a/Lib/codeop.py +++ b/Lib/codeop.py @@ -66,6 +66,8 @@ def _maybe_compile(compiler, source, filename, symbol): compiler(source + "\n", filename, symbol) return None except SyntaxError as 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