Skip to content

fixed indicator position in code with tabs #8307

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 2 commits into from
Jan 22, 2020
Merged

Conversation

dosisod
Copy link
Contributor

@dosisod dosisod commented Jan 21, 2020

PR for issue #8306.

@dosisod
Copy link
Contributor Author

dosisod commented Jan 21, 2020

Now that the tests are actually failing for code related reasons, what is the suggested change for the 2 failing tests?

[case testParseErrorShowSource]
# flags: --pretty --show-error-codes
import a
a.f()
[file a.py]
def f() -> None: pass
[file a.py.2]
def f(x: int) ->
[file a.py.3]
def f(x: int) -> None: pass
[file a.py.4]
def f() -> None: pass
[out]
==
a.py:1: error: invalid syntax [syntax]
def f(x: int) ->
^
==
main:3: error: Too few arguments for "f" [call-arg]
a.f()
^
==

The cursor is off by 1 character, though I would think that the new position of the cursor makes more sense. Also, where should I put new tests to check for consistency between tabs and spaces when pretty printing?

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

Thanks, generally looks good, although I have one question.

mypy/errors.py Outdated
@@ -451,12 +451,17 @@ def format_messages(self, error_info: List[ErrorInfo],
# Add source code fragment and a location marker.
if severity == 'error' and source_lines and line > 0:
source_line = source_lines[line - 1]
source_line_expanded = source_line.replace('\t', ' ' * 8)
Copy link
Member

Choose a reason for hiding this comment

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

Why not source_line.expandtabs()? (Also 8 is default for the latter.)

mypy/errors.py Outdated
if column < 0:
# Something went wrong, take first non-empty column.
column = len(source_line) - len(source_line.lstrip())

# Shifts column after tab expansion
column = len(source_line[:column].replace('\t', ' ' * 8))
Copy link
Member

Choose a reason for hiding this comment

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

Same question here.

@ilevkivskyi
Copy link
Member

The cursor is off by 1 character, though I would think that the new position of the cursor makes more sense.

This doesn't look important, you can just update the existing tests.

Also, where should I put new tests to check for consistency between tabs and spaces when pretty printing?

I would put them at the end of cmdline.test.

@dosisod
Copy link
Contributor Author

dosisod commented Jan 21, 2020

Did not know that expandtabs() existed. Changed that, then added and modified the tests.

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

LGTM now.

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.

2 participants