Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fast parser: support @no_type_check, give better ellipses error #2722

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 4 commits into from
Jan 23, 2017

Conversation

ddfisher
Copy link
Collaborator

This PR converts 3 more test files to the fast parser. To do so, we add support for the @no_type_check decorator and fixup the error message about mixed ellipses arguments (i.e. fixes #2704).

@@ -73,6 +70,9 @@
'check-class-namedtuple.test',
'check-selftype.test',
'check-python2.test',
'check-columns.test',
'check-functions.test',
'check-tuples.test',
Copy link
Member

Choose a reason for hiding this comment

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

I cannot comment on lines 81 ('check-newsyntax.test') and 84 ('check-underscores.test'), but I think those two could be changed from files.append(...) to fast_parser_files.append(...)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch -- I'll do that in my next PR with the rest of the fixes.


arg_kinds = [arg.kind for arg in args]
arg_names = [arg.variable.name() for arg in args] # type: List[Optional[str]]
arg_names = [None if argument_elide_name(name) else name for name in arg_names]
if special_function_elide_names(n.name):
arg_names = [None] * len(arg_names)
arg_types = None # type: List[Type]
if n.type_comment is not None:
if no_type_check:
arg_types = [None for _ 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.

More idiomatic is [None] * len(args), see a few lines earlier.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed.

A().f('') # E:5: Argument 1 to "f" of "A" has incompatible type "str"; expected "int"
A().f(1, 1) # E:5: Argument 2 to "f" of "A" has incompatible type "int"; expected "str"
A().f(1, 'hello', 'hi') # E:5: Too many arguments for "f" of "A"
A().f('') # E:0: Argument 1 to "f" of "A" has incompatible type "str"; expected "int"
Copy link
Member

Choose a reason for hiding this comment

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

I'm a little sad that the column numbers are no longer correct. Can you file an issue to fix that later?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I looked into this briefly, and it appeared that the parser just associates the wrong number with the call. Filed #2749 to look into it further.

@@ -387,7 +387,7 @@ aa, bb, *cc = t # E: Need type annotation for variable
[case testAssignmentToStarAnnotation]
from typing import List
li, lo = None, None # type: List[int], List[object]
a, b, *c = 1, 2 # type: int, int, *List[int]
a, b, *c = 1, 2 # type: int, int, List[int]
Copy link
Member

Choose a reason for hiding this comment

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

Hm, interesting. This is nowhere spelled out in PEP 484. But given that it was always List[int] I think it's more correct without the star. I filed python/typing#363 to clarify this in the PEP.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this is more correct too.

@@ -289,7 +289,7 @@ def do_func_def(self, n: Union[ast35.FunctionDef, ast35.AsyncFunctionDef],
arg_names = [None] * len(arg_names)
arg_types = None # type: List[Type]
if no_type_check:
arg_types = [None for _ in args]
arg_types = [None] * len(args)
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I should have mentioned there's another like this in fastparse2.py.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops, should've realized.

@gvanrossum gvanrossum merged commit 4afd647 into master Jan 23, 2017
@gvanrossum gvanrossum deleted the fastparser-tests-3 branch January 23, 2017 22:35
@gvanrossum
Copy link
Member

Merged without waiting for Appveyor (they seem to be queueing forever).

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.

Fast parser should warn about using ellipses with other function arguments
3 participants