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
1 change: 0 additions & 1 deletion mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,6 @@ def visit_call_expr_inner(self, e: CallExpr, allow_none_return: bool = False) ->
and self.always_returns_none(e.callee)
):
self.chk.msg.does_not_return_value(callee_type, e)
return AnyType(TypeOfAny.from_error)
return ret_type

def check_str_format_call(self, e: CallExpr) -> None:
Expand Down
36 changes: 24 additions & 12 deletions test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -1075,15 +1075,17 @@ class A:
a: A
o: object
if int():
a = f() # E: "f" does not return a value (it only ever returns None)
a = f() # E: "f" does not return a value (it only ever returns None) \
# E: Incompatible types in assignment (expression has type "None", variable has type "A")
if int():
o = a() # E: Function does not return a value (it only ever returns None)
if int():
o = A().g(a) # E: "g" of "A" does not return a value (it only ever returns None)
if int():
o = A.g(a, a) # E: "g" of "A" does not return a value (it only ever returns None)
A().g(f()) # E: "f" does not return a value (it only ever returns None)
x: A = f() # E: "f" does not return a value (it only ever returns None)
x: A = f() # E: "f" does not return a value (it only ever returns None) \
# E: Incompatible types in assignment (expression has type "None", variable has type "A")
f()
A().g(a)
[builtins fixtures/tuple.pyi]
Expand All @@ -1100,7 +1102,8 @@ while f(): # E: "f" does not return a value (it only ever returns None)
pass
def g() -> object:
return f() # E: "f" does not return a value (it only ever returns None)
raise f() # E: "f" does not return a value (it only ever returns None)
raise f() # E: Exception must be derived from BaseException \
# E: "f" does not return a value (it only ever returns None)
[builtins fixtures/exception.pyi]

[case testNoneReturnTypeWithExpressions]
Expand All @@ -1112,12 +1115,16 @@ class A:

a: A
[f()] # E: "f" does not return a value (it only ever returns None)
f() + a # E: "f" does not return a value (it only ever returns None)
a + f() # E: "f" does not return a value (it only ever returns None)
f() + a # E: "f" does not return a value (it only ever returns None) \
# E: Unsupported left operand type for + ("None")
a + f() # E: "f" does not return a value (it only ever returns None) \
# E: Unsupported operand types for + ("A" and "None")
f() == a # E: "f" does not return a value (it only ever returns None)
a != f() # E: "f" does not return a value (it only ever returns None)
a != f() # E: Unsupported left operand type for != ("A") \
# E: "f" does not return a value (it only ever returns None)
cast(A, f())
f().foo # E: "f" does not return a value (it only ever returns None)
f().foo # E: "f" does not return a value (it only ever returns None) \
# E: "None" has no attribute "foo"
[builtins fixtures/list.pyi]

[case testNoneReturnTypeWithExpressions2]
Expand All @@ -1130,11 +1137,16 @@ class A:

a: A
b: bool
f() in a # E: "f" does not return a value (it only ever returns None) # E: Unsupported right operand type for in ("A")
a < f() # E: "f" does not return a value (it only ever returns None)
f() <= a # E: "f" does not return a value (it only ever returns None)
a in f() # E: "f" does not return a value (it only ever returns None)
-f() # E: "f" does not return a value (it only ever returns None)
f() in a # E: "f" does not return a value (it only ever returns None) \
# E: Unsupported right operand type for in ("A")
a < f() # E: Unsupported left operand type for < ("A") \
# E: "f" does not return a value (it only ever returns None)
f() <= a # E: "f" does not return a value (it only ever returns None) \
# E: Unsupported left operand type for <= ("None")
a in f() # E: Unsupported right operand type for in ("None") \
# E: "f" does not return a value (it only ever returns None)
-f() # E: Unsupported operand type for unary - ("None") \
# E: "f" does not return a value (it only ever returns None)
not f() # E: "f" does not return a value (it only ever returns None)
f() and b # E: "f" does not return a value (it only ever returns None)
b or f() # E: "f" does not return a value (it only ever returns None)
Expand Down
4 changes: 3 additions & 1 deletion test-data/unit/check-inference.test
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,8 @@ for e, f in [[]]: # E: Need type annotation for "e" \
[case testForStatementInferenceWithVoid]
def f() -> None: pass

for x in f(): # E: "f" does not return a value (it only ever returns None)
for x in f(): # E: "f" does not return a value (it only ever returns None) \
# E: "None" has no attribute "__iter__" (not iterable)
pass
[builtins fixtures/for.pyi]

Expand Down Expand Up @@ -2176,6 +2177,7 @@ arr.append(arr.append(1))
[builtins fixtures/list.pyi]
[out]
main:3: error: "append" of "list" does not return a value (it only ever returns None)
main:3: error: Argument 1 to "append" of "list" has incompatible type "None"; expected "int"

-- Multipass
-- ---------
Expand Down
3 changes: 2 additions & 1 deletion test-data/unit/check-optional.test
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ def g(x: Optional[int]) -> int:
pass

x = f() # E: "f" does not return a value (it only ever returns None)
f() + 1 # E: "f" does not return a value (it only ever returns None)
f() + 1 # E: "f" does not return a value (it only ever returns None) \
# E: Unsupported left operand type for + ("None")
g(f()) # E: "f" does not return a value (it only ever returns None)

[case testEmptyReturn]
Expand Down
6 changes: 4 additions & 2 deletions test-data/unit/check-varargs.test
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ c: C

f(c) # E: Argument 1 to "f" has incompatible type "C"; expected "A"
f(a, b, c) # E: Argument 3 to "f" has incompatible type "C"; expected "A"
f(g()) # E: "g" does not return a value (it only ever returns None)
f(a, g()) # E: "g" does not return a value (it only ever returns None)
f(g()) # E: "g" does not return a value (it only ever returns None) \
# E: Argument 1 to "f" has incompatible type "None"; expected "A"
f(a, g()) # E: "g" does not return a value (it only ever returns None) \
# E: Argument 2 to "f" has incompatible type "None"; expected "A"
f()
f(a)
f(b)
Expand Down