[ty] Fix Inconsistent casing in diagnostic (#18084)
This commit is contained in:
@@ -318,7 +318,7 @@ def f(cond: bool) -> str:
|
||||
return "hello" if cond else NotImplemented
|
||||
|
||||
def f(cond: bool) -> int:
|
||||
# error: [invalid-return-type] "Return type does not match returned value: Expected `int`, found `Literal["hello"]`"
|
||||
# error: [invalid-return-type] "Return type does not match returned value: expected `int`, found `Literal["hello"]`"
|
||||
return "hello" if cond else NotImplemented
|
||||
```
|
||||
|
||||
|
||||
@@ -194,7 +194,7 @@ def good_return(x: T) -> T:
|
||||
return x
|
||||
|
||||
def bad_return(x: T) -> T:
|
||||
# error: [invalid-return-type] "Return type does not match returned value: Expected `T`, found `int`"
|
||||
# error: [invalid-return-type] "Return type does not match returned value: expected `T`, found `int`"
|
||||
return x + 1
|
||||
```
|
||||
|
||||
@@ -212,7 +212,7 @@ def different_types(cond: bool, t: T, s: S) -> T:
|
||||
if cond:
|
||||
return t
|
||||
else:
|
||||
# error: [invalid-return-type] "Return type does not match returned value: Expected `T`, found `S`"
|
||||
# error: [invalid-return-type] "Return type does not match returned value: expected `T`, found `S`"
|
||||
return s
|
||||
|
||||
def same_types(cond: bool, t1: T, t2: T) -> T:
|
||||
|
||||
@@ -179,7 +179,7 @@ def good_return[T: int](x: T) -> T:
|
||||
return x
|
||||
|
||||
def bad_return[T: int](x: T) -> T:
|
||||
# error: [invalid-return-type] "Return type does not match returned value: Expected `T`, found `int`"
|
||||
# error: [invalid-return-type] "Return type does not match returned value: expected `T`, found `int`"
|
||||
return x + 1
|
||||
```
|
||||
|
||||
@@ -192,7 +192,7 @@ def different_types[T, S](cond: bool, t: T, s: S) -> T:
|
||||
if cond:
|
||||
return t
|
||||
else:
|
||||
# error: [invalid-return-type] "Return type does not match returned value: Expected `T`, found `S`"
|
||||
# error: [invalid-return-type] "Return type does not match returned value: expected `T`, found `S`"
|
||||
return s
|
||||
|
||||
def same_types[T](cond: bool, t1: T, t2: T) -> T:
|
||||
|
||||
@@ -60,7 +60,7 @@ error[invalid-return-type]: Return type does not match returned value
|
||||
17 | yield from i()
|
||||
18 |
|
||||
19 | def j() -> str: # error: [invalid-return-type]
|
||||
| ^^^ Expected `str`, found `types.GeneratorType`
|
||||
| ^^^ expected `str`, found `types.GeneratorType`
|
||||
20 | yield 42
|
||||
21 | import types
|
||||
|
|
||||
@@ -77,7 +77,7 @@ error[invalid-return-type]: Return type does not match returned value
|
||||
34 | yield 42
|
||||
35 |
|
||||
36 | async def j() -> str: # error: [invalid-return-type]
|
||||
| ^^^ Expected `str`, found `types.AsyncGeneratorType`
|
||||
| ^^^ expected `str`, found `types.AsyncGeneratorType`
|
||||
37 | yield 42
|
||||
|
|
||||
info: Function is inferred as returning `types.AsyncGeneratorType` because it is an async generator function
|
||||
|
||||
@@ -41,7 +41,7 @@ error[invalid-return-type]: Return type does not match returned value
|
||||
4 | else:
|
||||
5 | # error: [invalid-return-type]
|
||||
6 | return 1
|
||||
| ^ Expected `str`, found `Literal[1]`
|
||||
| ^ expected `str`, found `Literal[1]`
|
||||
7 |
|
||||
8 | def f(cond: bool) -> str:
|
||||
|
|
||||
@@ -60,7 +60,7 @@ error[invalid-return-type]: Return type does not match returned value
|
||||
9 | if cond:
|
||||
10 | # error: [invalid-return-type]
|
||||
11 | return 1
|
||||
| ^ Expected `str`, found `Literal[1]`
|
||||
| ^ expected `str`, found `Literal[1]`
|
||||
12 | else:
|
||||
13 | # error: [invalid-return-type]
|
||||
|
|
||||
@@ -75,7 +75,7 @@ error[invalid-return-type]: Return type does not match returned value
|
||||
12 | else:
|
||||
13 | # error: [invalid-return-type]
|
||||
14 | return 2
|
||||
| ^ Expected `str`, found `Literal[2]`
|
||||
| ^ expected `str`, found `Literal[2]`
|
||||
|
|
||||
::: src/mdtest_snippet.py:8:22
|
||||
|
|
||||
|
||||
@@ -48,7 +48,7 @@ error[invalid-return-type]: Return type does not match returned value
|
||||
2 | if False:
|
||||
3 | # error: [invalid-return-type]
|
||||
4 | return 1
|
||||
| ^ Expected `None`, found `Literal[1]`
|
||||
| ^ expected `None`, found `Literal[1]`
|
||||
5 |
|
||||
6 | # error: [invalid-return-type]
|
||||
|
|
||||
|
||||
@@ -57,7 +57,7 @@ error[invalid-return-type]: Return type does not match returned value
|
||||
| --- Expected `str` because of return type
|
||||
6 | # error: [invalid-return-type]
|
||||
7 | return 1
|
||||
| ^ Expected `str`, found `Literal[1]`
|
||||
| ^ expected `str`, found `Literal[1]`
|
||||
8 |
|
||||
9 | def f() -> int:
|
||||
|
|
||||
@@ -75,7 +75,7 @@ error[invalid-return-type]: Return type does not match returned value
|
||||
| --- Expected `int` because of return type
|
||||
10 | # error: [invalid-return-type]
|
||||
11 | return
|
||||
| ^^^^^^ Expected `int`, found `None`
|
||||
| ^^^^^^ expected `int`, found `None`
|
||||
12 |
|
||||
13 | from typing import TypeVar
|
||||
|
|
||||
|
||||
@@ -37,7 +37,7 @@ error[invalid-return-type]: Return type does not match returned value
|
||||
| --- Expected `int` because of return type
|
||||
2 | # error: [invalid-return-type]
|
||||
3 | return ...
|
||||
| ^^^ Expected `int`, found `ellipsis`
|
||||
| ^^^ expected `int`, found `ellipsis`
|
||||
4 |
|
||||
5 | # error: [invalid-return-type]
|
||||
|
|
||||
|
||||
@@ -1548,7 +1548,7 @@ pub(super) fn report_invalid_return_type(
|
||||
|
||||
let mut diag = builder.into_diagnostic("Return type does not match returned value");
|
||||
diag.set_primary_message(format_args!(
|
||||
"Expected `{expected_ty}`, found `{actual_ty}`",
|
||||
"expected `{expected_ty}`, found `{actual_ty}`",
|
||||
expected_ty = expected_ty.display(context.db()),
|
||||
actual_ty = actual_ty.display(context.db()),
|
||||
));
|
||||
@@ -1573,7 +1573,7 @@ pub(super) fn report_invalid_generator_function_return_type(
|
||||
let mut diag = builder.into_diagnostic("Return type does not match returned value");
|
||||
let inferred_ty = inferred_return.display(context.db());
|
||||
diag.set_primary_message(format_args!(
|
||||
"Expected `{expected_ty}`, found `{inferred_ty}`",
|
||||
"expected `{expected_ty}`, found `{inferred_ty}`",
|
||||
expected_ty = expected_ty.display(context.db()),
|
||||
));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user