Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,10 @@ def is_trivial_body(self, block: Block) -> bool:
isinstance(body[0].expr, StrExpr)):
body = block.body[1:]

if len(body) != 1:
if len(body) == 0:
# There's only a docstring.
return True
elif len(body) > 1:
return False
stmt = body[0]
return (isinstance(stmt, PassStmt) or
Expand Down
15 changes: 15 additions & 0 deletions test-data/unit/check-flags.test
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,18 @@ class BaseClass: pass

[out]
tmp/main.py:2: error: Class cannot subclass 'BaseClass' (has type 'Any')

[case testWarnNoReturnIgnoresTrivialFunctions]
# flags: --warn-no-return
def f() -> int:
pass
def g() -> int:
...
def h() -> int:
"""with docstring"""
pass
def i() -> int:
"""with docstring"""
...
def j() -> int:
"""docstring only"""