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

report columns in 1-based, not 0-based #4482

Merged
merged 3 commits into from Jan 20, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion mypy/errors.py
Expand Up @@ -411,7 +411,8 @@ def format_messages(self, error_info: List[ErrorInfo]) -> List[str]:
if file is not None:
if self.show_column_numbers and line is not None and line >= 0 \
and column is not None and column >= 0:
srcloc = '{}:{}:{}'.format(file, line, column)
col = 1 + column
srcloc = '{}:{}:{}'.format(file, line, col)
Copy link
Member

Choose a reason for hiding this comment

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

Any reason why you're not just inlining column + 1 here?

elif line is not None and line >= 0:
srcloc = '{}:{}'.format(file, line)
else:
Expand Down
28 changes: 14 additions & 14 deletions test-data/unit/check-columns.test
Expand Up @@ -2,7 +2,7 @@
# flags: --show-column-numbers
1 +
[out]
main:2:4: error: invalid syntax
main:2:5: error: invalid syntax


[case testColumnsNestedFunctions]
Expand All @@ -15,8 +15,8 @@ def f() -> 'A':
class A: pass
class B: pass
[out]
main:5:8: error: Incompatible return value type (got "A", expected "B")
main:6:4: error: Incompatible return value type (got "B", expected "A")
main:5:9: error: Incompatible return value type (got "A", expected "B")
main:6:5: error: Incompatible return value type (got "B", expected "A")

[case testColumnsNestedFunctionsWithFastParse]
# flags: --show-column-numbers
Expand All @@ -28,8 +28,8 @@ def f() -> 'A':
class A: pass
class B: pass
[out]
main:5:8: error: Incompatible return value type (got "A", expected "B")
main:6:4: error: Incompatible return value type (got "B", expected "A")
main:5:9: error: Incompatible return value type (got "A", expected "B")
main:6:5: error: Incompatible return value type (got "B", expected "A")


[case testColumnsMethodDefaultArgumentsAndSignatureAsComment]
Expand All @@ -40,28 +40,28 @@ class A:
pass
A().f()
A().f(1)
A().f('') # E:0: Argument 1 to "f" of "A" has incompatible type "str"; expected "int"
A().f(1, 1) # E:0: Argument 2 to "f" of "A" has incompatible type "int"; expected "str"
A().f(1, 'hello', 'hi') # E:0: Too many arguments for "f" of "A"
A().f('') # E:1: Argument 1 to "f" of "A" has incompatible type "str"; expected "int"
A().f(1, 1) # E:1: Argument 2 to "f" of "A" has incompatible type "int"; expected "str"
A().f(1, 'hello', 'hi') # E:1: Too many arguments for "f" of "A"

[case testColumnsMultipleStatementsPerLine]
# flags: --show-column-numbers
x = 1
x = 15
y = 'hello'
x = 2; y = x; y += 1
[out]
main:4:7: error: Incompatible types in assignment (expression has type "int", variable has type "str")
main:4:14: error: Unsupported operand types for + ("str" and "int")
main:4:8: error: Incompatible types in assignment (expression has type "int", variable has type "str")
main:4:15: error: Unsupported operand types for + ("str" and "int")

[case testColumnsSimpleIsinstance]
# flags: --show-column-numbers
import typing
def f(x: object, n: int, s: str) -> None:
n = x # E:4: Incompatible types in assignment (expression has type "object", variable has type "int")
n = x # E:5: Incompatible types in assignment (expression has type "object", variable has type "int")
if isinstance(x, int):
n = x
s = x # E:8: Incompatible types in assignment (expression has type "int", variable has type "str")
n = x # E:4: Incompatible types in assignment (expression has type "object", variable has type "int")
s = x # E:9: Incompatible types in assignment (expression has type "int", variable has type "str")
n = x # E:5: Incompatible types in assignment (expression has type "object", variable has type "int")
[builtins fixtures/isinstance.pyi]
[out]

Expand Down
24 changes: 12 additions & 12 deletions test-data/unit/check-generics.test
Expand Up @@ -615,17 +615,17 @@ X = T # Error

[builtins fixtures/list.pyi]
[out]
main:9:4: error: "Node" expects 2 type arguments, but 1 given
main:11:4: error: "Node" expects 2 type arguments, but 3 given
main:15:9: error: "list" expects 1 type argument, but 2 given
main:16:18: error: "list" expects 1 type argument, but 2 given
main:17:24: error: "Node" expects 2 type arguments, but 1 given
main:18:3: error: "Node" expects 2 type arguments, but 1 given
main:19:4: error: Bad number of arguments for type alias, expected: 1, given: 2
main:19:4: error: "Node" expects 2 type arguments, but 1 given
main:22:0: error: Revealed type is '__main__.Node[builtins.int, builtins.str]'
main:24:0: error: Revealed type is '__main__.Node[__main__.Node[builtins.int, builtins.int], builtins.list[builtins.int]]'
main:26:4: error: Type variable "__main__.T" is invalid as target for type alias
main:9:5: error: "Node" expects 2 type arguments, but 1 given
main:11:5: error: "Node" expects 2 type arguments, but 3 given
main:15:10: error: "list" expects 1 type argument, but 2 given
main:16:19: error: "list" expects 1 type argument, but 2 given
main:17:25: error: "Node" expects 2 type arguments, but 1 given
main:18:4: error: "Node" expects 2 type arguments, but 1 given
main:19:5: error: Bad number of arguments for type alias, expected: 1, given: 2
main:19:5: error: "Node" expects 2 type arguments, but 1 given
main:22:1: error: Revealed type is '__main__.Node[builtins.int, builtins.str]'
main:24:1: error: Revealed type is '__main__.Node[__main__.Node[builtins.int, builtins.int], builtins.list[builtins.int]]'
main:26:5: error: Type variable "__main__.T" is invalid as target for type alias

[case testGenericTypeAliasesForAliases]
from typing import TypeVar, Generic, List, Union
Expand Down Expand Up @@ -1068,7 +1068,7 @@ y = None # type: SameA[str] # Two errors here, for both args of A

[builtins fixtures/list.pyi]
[out]
main:9:7: error: Value of type variable "T" of "A" cannot be "str"
main:9:8: error: Value of type variable "T" of "A" cannot be "str"
main:13: error: Value of type variable "T" of "A" cannot be "str"
main:13: error: Value of type variable "S" of "A" cannot be "str"

Expand Down