-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
4286095
to
a33f618
Compare
@@ -73,6 +70,9 @@ | |||
'check-class-namedtuple.test', | |||
'check-selftype.test', | |||
'check-python2.test', | |||
'check-columns.test', | |||
'check-functions.test', | |||
'check-tuples.test', |
There was a problem hiding this comment.
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(...)
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, should've realized.
Merged without waiting for Appveyor (they seem to be queueing forever). |
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).