ENH Improve PyodideConsole error messages (#1759)

when code causes a lexer error
This commit is contained in:
Hood Chatham 2021-07-30 16:55:13 +02:00 committed by GitHub
parent 6eac16825c
commit 5264b687df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -12,6 +12,7 @@ from contextlib import _RedirectStream # type: ignore
import rlcompleter
import platform
import sys
from tokenize import TokenError
import traceback
from typing import Literal
from typing import (
@ -97,8 +98,13 @@ class _Compile(Compile):
def __call__(self, source, filename, symbol) -> CodeRunner: # type: ignore
return_mode = self.return_mode
if self.quiet_trailing_semicolon and should_quiet(source):
return_mode = None
try:
if self.quiet_trailing_semicolon and should_quiet(source):
return_mode = None
except (TokenError, SyntaxError):
# Invalid code, let the Python parser throw the error later.
pass
code_runner = CodeRunner(
source,
mode=symbol,