PY-20611 Missing warning about functions implicitly returning None when return type is not Optional

Updated PyFunction to account for implicit 'return None' statements when inferring return statement types.

It affected return type inference of PyFunction.

Fixed a failing test related to formatted strings.

Added a quick fix to make all return statements explicit.

Updated the CFG to include PyPassStatements, enabling detection of exit points in empty functions.

Simplified PyMakeFunctionReturnTypeQuickFix to independently infer function types and handle required imports. Currently, it does not support specifying custom suggested types.



Merge-request: IJ-MR-148719
Merged-by: Aleksandr Govenko <aleksandr.govenko@jetbrains.com>

GitOrigin-RevId: 9f58961f9eb70e4f9dbba7359f5aafdfd392b7e2
This commit is contained in:
Aleksandr.Govenko
2024-11-26 17:02:37 +00:00
committed by intellij-monorepo-bot
parent f2982c675f
commit 31dd92576e
32 changed files with 430 additions and 301 deletions
@@ -1,10 +1,10 @@
from typing import Type
import my
from my import X
from my import X, Y
def foo(a) -> Type[X]:
def foo(a) -> Type[X | Y]:
if a:
return my.X<caret>
else:
@@ -0,0 +1,7 @@
def f(x) -> int | None:
if x == 1:
return 42
elif x == 2:
<warning descr="Function returning 'int | None' has implicit 'return None'">return<caret></warning>
elif x == 3:
pass
@@ -0,0 +1,8 @@
def f(x) -> int | None:
if x == 1:
return 42
elif x == 2:
return None
elif x == 3:
return None
return None