Skip to content

Commit a67b4af

Browse files
authored
Make reveal_type work with call expressions returning None (#8924)
I think it's unnecessarily strict to raise an error in case like this. Was: error: "foo" does not return a value
1 parent fe216a3 commit a67b4af

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

mypy/checkexpr.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3023,7 +3023,8 @@ def visit_reveal_expr(self, expr: RevealExpr) -> Type:
30233023
"""Type check a reveal_type expression."""
30243024
if expr.kind == REVEAL_TYPE:
30253025
assert expr.expr is not None
3026-
revealed_type = self.accept(expr.expr, type_context=self.type_context[-1])
3026+
revealed_type = self.accept(expr.expr, type_context=self.type_context[-1],
3027+
allow_none_return=True)
30273028
if not self.chk.current_node_deferred:
30283029
self.msg.reveal_type(revealed_type, expr.expr)
30293030
if not self.chk.in_checked_function():

test-data/unit/check-functions.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,3 +2572,9 @@ lambda a=nonsense: a # E: Name 'nonsense' is not defined
25722572
lambda a=(1 + 'asdf'): a # E: Unsupported operand types for + ("int" and "str")
25732573
def f(x: int = i): # E: Name 'i' is not defined
25742574
i = 42
2575+
2576+
[case testRevealTypeOfCallExpressionReturningNoneWorks]
2577+
def foo() -> None:
2578+
pass
2579+
2580+
reveal_type(foo()) # N: Revealed type is 'None'

0 commit comments

Comments
 (0)