Skip to content

Commit 1ddca89

Browse files
ddfishergvanrossum
authored andcommitted
Fix --warn-no-return for docstring only functions (#2339)
1 parent c6c5d9c commit 1ddca89

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

mypy/checker.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,10 @@ def is_trivial_body(self, block: Block) -> bool:
656656
isinstance(body[0].expr, StrExpr)):
657657
body = block.body[1:]
658658

659-
if len(body) != 1:
659+
if len(body) == 0:
660+
# There's only a docstring.
661+
return True
662+
elif len(body) > 1:
660663
return False
661664
stmt = body[0]
662665
return (isinstance(stmt, PassStmt) or

test-data/unit/check-flags.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,18 @@ class BaseClass: pass
7979

8080
[out]
8181
tmp/main.py:2: error: Class cannot subclass 'BaseClass' (has type 'Any')
82+
83+
[case testWarnNoReturnIgnoresTrivialFunctions]
84+
# flags: --warn-no-return
85+
def f() -> int:
86+
pass
87+
def g() -> int:
88+
...
89+
def h() -> int:
90+
"""with docstring"""
91+
pass
92+
def i() -> int:
93+
"""with docstring"""
94+
...
95+
def j() -> int:
96+
"""docstring only"""

0 commit comments

Comments
 (0)