Fast parser: support @no_type_check, give better ellipses error#2722
Fast parser: support @no_type_check, give better ellipses error#2722gvanrossum merged 4 commits intomasterfrom
Conversation
4286095 to
a33f618
Compare
| 'check-python2.test', | ||
| 'check-columns.test', | ||
| 'check-functions.test', | ||
| 'check-tuples.test', |
There was a problem hiding this comment.
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.
Good catch -- I'll do that in my next PR with the rest of the fixes.
mypy/fastparse.py
Outdated
| 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.
More idiomatic is [None] * len(args), see a few lines earlier.
| 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.
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.
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.
| 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.
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.
I think this is more correct too.
| 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.
Sorry, I should have mentioned there's another like this in fastparse2.py.
There was a problem hiding this comment.
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_checkdecorator and fixup the error message about mixed ellipses arguments (i.e. fixes #2704).