PY-80493 Inconsistent return inspection adding "return None" after every line in context manager

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

(cherry picked from commit b576e30d433d39e426c8854d3ad485594ac9e958)

IJ-MR-160763

GitOrigin-RevId: cf6a3a4c834ee1df160e1927af1b75eb16eec3dc
This commit is contained in:
Aleksandr.Govenko
2025-04-24 02:27:25 +00:00
committed by intellij-monorepo-bot
parent 91f3589711
commit 5bf9f9ff39
9 changed files with 60 additions and 12 deletions
@@ -1,5 +0,0 @@
def f(x) -> <warning descr="Function returning 'int | None' has implicit return">int | None<caret></warning>:
if x == 1:
return 42
elif x == 2:
<warning descr="Function returning 'int | None' has implicit return">return</warning>
@@ -1,6 +0,0 @@
def f(x) -> int | None:
if x == 1:
return 42
elif x == 2:
return None
return None
@@ -0,0 +1,11 @@
class NotSuppressingContext:
def __enter__(self):
...
def __exit__(self, exc_type, exc_val, exc_tb) -> bool | None:
...
def foo():
with NotSuppressingContext() as st:
foo()
<weak_warning descr="Explicit return statement expected">if bool():
return 1<caret></weak_warning>
@@ -0,0 +1,12 @@
class NotSuppressingContext:
def __enter__(self):
...
def __exit__(self, exc_type, exc_val, exc_tb) -> bool | None:
...
def foo():
with NotSuppressingContext() as st:
foo()
if bool():
return 1
return None
@@ -0,0 +1,10 @@
class SuppressingContext:
def __enter__(self):
...
def __exit__(self, exc_type, exc_val, exc_tb) -> bool:
...
def foo():
<weak_warning descr="Explicit return statement expected">with SuppressingContext() as st:
foo()
return 1<caret></weak_warning>
@@ -0,0 +1,11 @@
class SuppressingContext:
def __enter__(self):
...
def __exit__(self, exc_type, exc_val, exc_tb) -> bool:
...
def foo():
with SuppressingContext() as st:
foo()
return 1
return None