Skip to content

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

Merged
gvanrossum merged 4 commits intomasterfrom
fastparser-tests-3
Jan 23, 2017
Merged

Fast parser: support @no_type_check, give better ellipses error#2722
gvanrossum merged 4 commits intomasterfrom
fastparser-tests-3

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).

'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_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.

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.

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