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

Fix column for missing return annotations #108

Merged
merged 2 commits into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions flake8_annotations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def colon_seeker(node: AST_FUNCTION_TYPES, lines: List[str]) -> Tuple[int, int]:

# Use str.rfind() to account for annotations on the same line, definition closure should
# be the last : on the line
def_end_col_offset = lines[def_end_lineno - 1].rfind(":") + 1
def_end_col_offset = lines[def_end_lineno - 1].rfind(":")

return def_end_lineno, def_end_col_offset

Expand All @@ -359,7 +359,7 @@ def _single_line_colon_seeker(node: AST_FUNCTION_TYPES, line: str) -> Tuple[int,
"""Locate the closing colon for a single-line function definition."""
col_start = node.col_offset
col_end = node.body[0].col_offset
def_end_col_offset = line.rfind(":", col_start, col_end) + 1
def_end_col_offset = line.rfind(":", col_start, col_end)

return node.lineno, def_end_col_offset

Expand Down
26 changes: 13 additions & 13 deletions testing/test_cases/column_line_numbers_test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def bar(x): # 1
),
error_locations=(
(1, 8),
(1, 11),
(1, 10),
),
),
"decorated_def": ParserTestCase(
Expand All @@ -44,7 +44,7 @@ def foo( # 4
error_locations=(
(5, 4),
(6, 4),
(7, 2),
(7, 1),
),
),
"single_line_docstring": ParserTestCase(
Expand All @@ -55,7 +55,7 @@ def baz(): # 1
pass # 3
"""
),
error_locations=((1, 10),),
error_locations=((1, 9),),
),
"multiline_docstring": ParserTestCase(
src=dedent(
Expand All @@ -69,7 +69,7 @@ def snek(): # 1
pass # 7
"""
),
error_locations=((1, 11),),
error_locations=((1, 10),),
),
"hinted_arg": ParserTestCase(
src=dedent(
Expand All @@ -78,7 +78,7 @@ def foo(bar: bool): # 1
return True # 2
"""
),
error_locations=((1, 19),),
error_locations=((1, 18),),
),
"docstring_with_colon": ParserTestCase(
src=dedent(
Expand All @@ -88,7 +88,7 @@ def baz(): # 1
pass # 3
"""
),
error_locations=((1, 10),),
error_locations=((1, 9),),
),
"multiline_docstring_with_colon": ParserTestCase(
src=dedent(
Expand All @@ -102,31 +102,31 @@ def snek(): # 1
pass # 7
"""
),
error_locations=((1, 11),),
error_locations=((1, 10),),
),
"single_line_def": ParserTestCase(
src=dedent(
"""\
def lol(): \"\"\"Some docstring.\"\"\" # 1
"""
),
error_locations=((1, 10),),
error_locations=((1, 9),),
),
"single_line_def_docstring_with_colon": ParserTestCase(
src=dedent(
"""\
def lol(): \"\"\"Some: docstring.\"\"\" # 1
"""
),
error_locations=((1, 10),),
error_locations=((1, 9),),
),
"single_line_hinted_def": ParserTestCase(
src=dedent(
"""\
def lol(x: int): \"\"\"Some: docstring.\"\"\" # 1
"""
),
error_locations=((1, 16),),
error_locations=((1, 15),),
),
"multiline_docstring_no_content": ParserTestCase(
src=dedent(
Expand All @@ -137,7 +137,7 @@ def foo(): # 1
... # 4
"""
),
error_locations=((1, 10),),
error_locations=((1, 9),),
),
"multiline_docstring_summary_at_open": ParserTestCase(
src=dedent(
Expand All @@ -148,7 +148,7 @@ def foo(): # 1
... # 4
"""
),
error_locations=((1, 10),),
error_locations=((1, 9),),
),
"multiline_docstring_single_line_summary": ParserTestCase(
src=dedent(
Expand All @@ -160,6 +160,6 @@ def foo(): # 1
... # 5
"""
),
error_locations=((1, 10),),
error_locations=((1, 9),),
),
}