Skip to content

Turn --fast-parser on by default #2734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ def parse(source: Union[str, bytes], fnam: str = None, errors: Errors = None,

The pyversion (major, minor) argument determines the Python syntax variant.
"""
raise_on_error = False
if errors is None:
errors = Errors()
raise_on_error = True
errors.set_file('<input>' if fnam is None else fnam)
is_stub_file = bool(fnam) and fnam.endswith('.pyi')
try:
Expand All @@ -72,14 +74,14 @@ def parse(source: Union[str, bytes], fnam: str = None, errors: Errors = None,
).visit(ast)
tree.path = fnam
tree.is_stub = is_stub_file
return tree
except SyntaxError as e:
if errors:
errors.report(e.lineno, e.offset, e.msg)
else:
raise
errors.report(e.lineno, e.offset, e.msg)
tree = MypyFile([], [], False, set())

if raise_on_error and errors.is_errors():
errors.raise_error()

return MypyFile([], [], False, set())
return tree


def parse_type_comment(type_comment: str, line: int, errors: Errors) -> Optional[Type]:
Expand Down
14 changes: 8 additions & 6 deletions mypy/fastparse2.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ def parse(source: Union[str, bytes], fnam: str = None, errors: Errors = None,

The pyversion (major, minor) argument determines the Python syntax variant.
"""
raise_on_error = False
if errors is None:
errors = Errors()
raise_on_error = True
errors.set_file('<input>' if fnam is None else fnam)
is_stub_file = bool(fnam) and fnam.endswith('.pyi')
try:
Expand All @@ -89,14 +91,14 @@ def parse(source: Union[str, bytes], fnam: str = None, errors: Errors = None,
assert isinstance(tree, MypyFile)
tree.path = fnam
tree.is_stub = is_stub_file
return tree
except SyntaxError as e:
if errors:
errors.report(e.lineno, e.offset, e.msg)
else:
raise
errors.report(e.lineno, e.offset, e.msg)
tree = MypyFile([], [], False, set())

if raise_on_error and errors.is_errors():
errors.raise_error()

return MypyFile([], [], False, set())
return tree


def with_line(f: Callable[['ASTConverter', T], U]) -> Callable[['ASTConverter', T], U]:
Expand Down
4 changes: 2 additions & 2 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ def add_invertible_flag(flag: str,
add_invertible_flag('--show-error-context', default=True,
dest='hide_error_context',
help='Precede errors with "note:" messages explaining context')
add_invertible_flag('--fast-parser', default=False,
help="enable fast parser (recommended)")
add_invertible_flag('--no-fast-parser', default=True, dest='fast_parser',
help="disable the fast parser (not recommended)")
parser.add_argument('-i', '--incremental', action='store_true',
help="enable experimental module cache")
parser.add_argument('--cache-dir', action='store', metavar='DIR',
Expand Down
2 changes: 1 addition & 1 deletion mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__(self) -> None:
self.use_builtins_fixtures = False

# -- experimental options --
self.fast_parser = False
self.fast_parser = True
self.incremental = False
self.cache_dir = defaults.CACHE_DIR
self.debug_cache = False
Expand Down
Loading