Skip to content
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

Make most fastparser errors non-fatal #2689

Merged
merged 2 commits into from
Jan 17, 2017
Merged

Make most fastparser errors non-fatal #2689

merged 2 commits into from
Jan 17, 2017

Conversation

ddfisher
Copy link
Collaborator

Instead of throwing an exception up to the parse function when encountering an error, the fast parser will now report it to the errors object and keep parsing. These errors are still considered blocking errors, so type checking will not continue past the parsing stage. This means that mypy will show you all your parse errors, instead of showing them to you one at a time as you fix them.

Fixes #2685.

@gvanrossum
Copy link
Member

Nice, but couldn't at least syntax errors in # type: comments (and forward references) be considered non-blocking? It should be possible to just ignore these as an error recovery method.

@ddfisher
Copy link
Collaborator Author

Yes, but I think that makes sense as a separate PR, as that decision takes place in a somewhat different part of the codebase.

@ddfisher
Copy link
Collaborator Author

I think the other PR should be pretty simple, though. This one has enough going on already that I'd prefer to keep them separate.

@gvanrossum
Copy link
Member

OK. I'll try to make time Monday to review this one.

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except for these nits.

if (len(func_type_ast.argtypes) == 1 and
isinstance(func_type_ast.argtypes[0], ast35.Ellipsis)):
arg_types = [a.type_annotation if a.type_annotation is not None else AnyType()
for a in args]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent one more space. Also below on line 292.

for a in args]
else:
translated_args = (TypeConverter(self.errors, line=n.lineno)
.translate_expr_list(func_type_ast.argtypes))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent 3 more spaces.

self.fail('Type signature has too few arguments', n.lineno, 0)
else:
func_type = CallableType([a if a is not None else
AnyType(implicit=True) for a in arg_types],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent two more spaces; indent the remaining line 1 more space.

raise TypeCommentParseError('Variable annotation syntax is only '
'suppoted in Python 3.6, use type '
'comment instead', n.lineno, n.col_offset)
self.fail('Variable annotation syntax is only suppoted in Python 3.6, '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: suppoted (and you'll have to fix a test in check-newsyntax.test to match the correct spelling :-).

@ddfisher
Copy link
Collaborator Author

Thanks for catching those nits! Not sure how that spacing got messed up...

@gvanrossum gvanrossum merged commit 9141362 into master Jan 17, 2017
@gvanrossum gvanrossum deleted the nonfatal-errors branch January 17, 2017 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect number of arguments in type signature should not be a fatal error
2 participants