PY-16055 Add warnings for functions with no return and empty return

Add warnings for functions with return type annotation but empty return or no return at all.
This commit is contained in:
Lada Gagina
2016-08-30 17:12:55 +03:00
parent f2a8c62367
commit dd95592ff4
5 changed files with 125 additions and 58 deletions
@@ -1,4 +1,4 @@
from typing import Optional, List
from typing import Optional, List, Union
def a(x):
# type: (List[int]) -> List[str]
@@ -13,7 +13,7 @@ def c():
return <warning descr="Expected type 'int', got 'str' instead">'abc'</warning>
def d(x):
# type: (x: int) -> List[str]
# type: (int) -> List[str]
return [str(x)]
def e():
@@ -35,4 +35,21 @@ def g(x):
if x:
return <warning descr="Expected type 'int', got 'str' instead">'abc'</warning>
else:
return <warning descr="Expected type 'int', got 'dict' instead">{}</warning>
return <warning descr="Expected type 'int', got 'dict' instead">{}</warning>
def h(x):
# type: (Any) -> int
<warning descr="Expected type 'int', got 'None' instead">return</warning>
def i():
# type: () -> Union[int, str]
pass
def j(x):
<warning descr="Expected to return 'Union[int, str]', got no return"># type: () -> Union[int, str]</warning>
x = 42
def k():
# type: () -> None
if True:
pass
@@ -28,4 +28,17 @@ def g(x) -> int:
if x:
return <warning descr="Expected type 'int', got 'str' instead">'abc'</warning>
else:
return <warning descr="Expected type 'int', got 'dict' instead">{}</warning>
return <warning descr="Expected type 'int', got 'dict' instead">{}</warning>
def h(x) -> int:
<warning descr="Expected type 'int', got 'None' instead">return</warning>
def i() -> Union[int, str]:
pass
def j(x) <warning descr="Expected to return 'Union[int, str]', got no return">-> Union[int, str]</warning>:
x = 42
def k() -> None:
if True:
pass