Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
Add multiline test
  • Loading branch information
mschoettle committed May 9, 2024
commit 5a7c0ec5e9a410642521c646d97746ce857c7fff
17 changes: 17 additions & 0 deletions test-data/unit/check-columns.test
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,23 @@ def f_untyped(x, foo, *args, **kwargs) -> None:
main:5:1:5:43: error: Function is missing a type annotation for one or more arguments
main:8:1:8:47: error: Function is missing a type annotation for one or more arguments

[case testColumnEndMultiline]
# flags: --disallow-untyped-defs --warn-no-return --show-error-end
def f(
x: int,
y: int,
):
pass

def g(
x: int,
y: int,
) -> int:
x = 1
[out]
main:2:1:4:11: error: Function is missing a return type annotation
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's unfortunate that the closing ): isn't included in the range. I imagine that's hard to fix though.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I agree. I unfortunately don't know how this could be fixed since it is unavailable in the AST.

For reference: I did find ast.get_source_segment. However, it also returns the source code for a function definition node including the body.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I understand. I'm still struggling with this case (as well as the one above where if the function has no annotations at all, we emit a one-character range); I'm worried this PR may lead to more confusing output in some cases. However, on balance it's probably fine and we can apply this change, but consider reverting it if there's a lot of negative feedback.

We could also consider looking at the first start position in the body of the function, but then the whitespace between the colon and the first statement would be included in the range.

main:8:1:11:9: error: Missing return statement

[case testColumnNameIsNotDefined]
((x)) # E:3: Name "x" is not defined

Expand Down