Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e49e743

Browse filesBrowse files
authored
Support multiline function/class definitions in REPL and InteractiveConsole (#5743)
* Support multiline function/class definitions in REPL and InteractiveConsole
1 parent e8df065 commit e49e743
Copy full SHA for e49e743

File tree

2 files changed

+16
-8
lines changed
Filter options

2 files changed

+16
-8
lines changed

‎Lib/codeop.py

Copy file name to clipboardExpand all lines: Lib/codeop.py
+6-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ def _maybe_compile(compiler, source, filename, symbol):
6666
compiler(source + "\n", filename, symbol)
6767
return None
6868
except SyntaxError as e:
69-
if "incomplete input" in str(e):
69+
# XXX: RustPython; support multiline definitions in REPL
70+
# See also: https://github.com/RustPython/RustPython/pull/5743
71+
strerr = str(e)
72+
if source.endswith(":") and "expected an indented block" in strerr:
73+
return None
74+
elif "incomplete input" in str(e):
7075
return None
7176
# fallthrough
7277

‎src/shell.rs

Copy file name to clipboardExpand all lines: src/shell.rs
+10-7
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,16 @@ fn shell_exec(
4949

5050
let bad_error = match err {
5151
CompileError::Parse(ref p) => {
52-
if matches!(
53-
p.error,
54-
ParseErrorType::Lexical(LexicalErrorType::IndentationError)
55-
) {
56-
continuing // && p.location.is_some()
57-
} else {
58-
true // !matches!(p, ParseErrorType::UnrecognizedToken(Tok::Dedent, _))
52+
match &p.error {
53+
ParseErrorType::Lexical(LexicalErrorType::IndentationError) => continuing, // && p.location.is_some()
54+
ParseErrorType::OtherError(msg) => {
55+
if msg.starts_with("Expected an indented block") {
56+
continuing
57+
} else {
58+
true
59+
}
60+
}
61+
_ => true, // !matches!(p, ParseErrorType::UnrecognizedToken(Tok::Dedent, _))
5962
}
6063
}
6164
_ => true, // It is a bad error for everything else

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.