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

Fixes to column number reporting #7078

Merged
merged 13 commits into from Jun 27, 2019

Conversation

@JukkaL
Copy link
Collaborator

commented Jun 27, 2019

Previously many types and AST nodes didn't have
(good) column numbers. This fixes several such issues.

In particular, this gives correct column number of simple
types like Foo and List[Foo] in Python 3 type
annotations.

For type comments we cheat a bit and point them to the
surrounding statement or definition, which is still a
small improvement.

For some types we may still be missing column numbers,
but this covers the most common cases.

JukkaL added some commits Jun 26, 2019

Fix column numbers of type annotations
Previously many types didn't have column numbers.

This gives correct column number of simple types like
`Foo` and `List[Foo]` in Python 3 type annotations.

For type comments we cheat a bit and point them to the
surrounding statement or definition, which is still a
small improvement.

For some types we may still be missing column numbers,
but this covers the most common cases.
Fix column number of type applications
This only affects new semantic analyzer.

@JukkaL JukkaL requested a review from ilevkivskyi Jun 27, 2019

@ilevkivskyi
Copy link
Collaborator

left a comment

Thanks, looks good! I only have minor comments.

self.node_stack = [] # type: List[AST]
self.assume_str_is_unicode = assume_str_is_unicode

def convert_column(self, column: int) -> int:

This comment has been minimized.

Copy link
@ilevkivskyi

ilevkivskyi Jun 27, 2019

Collaborator

Add a docstring what is the intended use of this method?

@@ -3516,6 +3517,7 @@ def analyze_type_application(self, expr: IndexExpr) -> None:
base = expr.base
expr.analyzed = TypeApplication(base, types)
expr.analyzed.line = expr.line
expr.analyzed.column = expr.column

This comment has been minimized.

Copy link
@ilevkivskyi

ilevkivskyi Jun 27, 2019

Collaborator

There are couple more similar places: process_typevar_declaration() and process_newtype_declaration() not sure if they are important.

main:7: error: Type argument "__main__.G[builtins.int]" of "G" must be a subtype of "builtins.str"
main:7: error: Type argument "builtins.int" of "G" must be a subtype of "builtins.str"

This comment has been minimized.

Copy link
@ilevkivskyi

ilevkivskyi Jun 27, 2019

Collaborator

Maybe add --show-column-numbers in this test? (IIUC columns caused the change of order.)


class function: pass

property = object() # Dummy definition.

This comment has been minimized.

Copy link
@ilevkivskyi

ilevkivskyi Jun 27, 2019

Collaborator

Two spaces before comment?

@JukkaL JukkaL merged commit 6348356 into master Jun 27, 2019

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@JelleZijlstra JelleZijlstra deleted the columns-2 branch Jun 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.