File tree Expand file tree Collapse file tree 6 files changed +17
-11
lines changed Expand file tree Collapse file tree 6 files changed +17
-11
lines changed Original file line number Diff line number Diff line change @@ -5295,10 +5295,15 @@ def format_expr_type() -> str:
5295
5295
else :
5296
5296
return f"Expression has type { typ } "
5297
5297
5298
+ def get_expr_name () -> str :
5299
+ if isinstance (expr , (NameExpr , MemberExpr )):
5300
+ return f'"{ expr .name } "'
5301
+ else :
5302
+ # return type if expr has no name
5303
+ return format_type (t , self .options )
5304
+
5298
5305
if isinstance (t , FunctionLike ):
5299
- self .fail (
5300
- message_registry .FUNCTION_ALWAYS_TRUE .format (format_type (t , self .options )), expr
5301
- )
5306
+ self .fail (message_registry .FUNCTION_ALWAYS_TRUE .format (get_expr_name ()), expr )
5302
5307
elif isinstance (t , UnionType ):
5303
5308
self .fail (message_registry .TYPE_ALWAYS_TRUE_UNIONTYPE .format (format_expr_type ()), expr )
5304
5309
elif isinstance (t , Instance ) and t .type .fullname == "typing.Iterable" :
Original file line number Diff line number Diff line change @@ -900,11 +900,11 @@ if any_or_object:
900
900
# flags: --strict-optional
901
901
def f():
902
902
pass
903
- if f: # E: Function "Callable[[], Any] " could always be true in boolean context [truthy-function]
903
+ if f: # E: Function "f " could always be true in boolean context [truthy-function]
904
904
pass
905
- if not f: # E: Function "Callable[[], Any] " could always be true in boolean context [truthy-function]
905
+ if not f: # E: Function "f " could always be true in boolean context [truthy-function]
906
906
pass
907
- conditional_result = 'foo' if f else 'bar' # E: Function "Callable[[], Any] " could always be true in boolean context [truthy-function]
907
+ conditional_result = 'foo' if f else 'bar' # E: Function "f " could always be true in boolean context [truthy-function]
908
908
909
909
[case testTruthyIterable]
910
910
# flags: --strict-optional --enable-error-code truthy-iterable
Original file line number Diff line number Diff line change @@ -2101,12 +2101,12 @@ import tests.foo
2101
2101
import bar
2102
2102
[file bar.py]
2103
2103
def foo() -> int: ...
2104
- if foo: ... # E: Function "Callable[[], int] " could always be true in boolean context
2104
+ if foo: ... # E: Function "foo " could always be true in boolean context
2105
2105
42 + "no" # type: ignore # E: "type: ignore" comment without error code (consider "type: ignore[operator]" instead)
2106
2106
[file tests/__init__.py]
2107
2107
[file tests/foo.py]
2108
2108
def foo() -> int: ...
2109
- if foo: ... # E: Function "Callable[[], int] " could always be true in boolean context
2109
+ if foo: ... # E: Function "foo " could always be true in boolean context
2110
2110
42 + "no" # type: ignore
2111
2111
[file mypy.ini]
2112
2112
\[mypy]
Original file line number Diff line number Diff line change @@ -192,7 +192,7 @@ if foo: ...
192
192
# mypy: enable-error-code="ignore-without-code"
193
193
194
194
def foo() -> int: ...
195
- if foo: ... # E: Function "Callable[[], int] " could always be true in boolean context
195
+ if foo: ... # E: Function "foo " could always be true in boolean context
196
196
42 + "no" # type: ignore # E: "type: ignore" comment without error code (consider "type: ignore[operator]" instead)
197
197
198
198
[file tests/baz.py]
Original file line number Diff line number Diff line change @@ -310,7 +310,8 @@ def f(x: int = (c := 4)) -> int:
310
310
z2: NT # E: Variable "NT" is not valid as a type \
311
311
# N: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
312
312
313
- if Alias := int: # E: Function "Type[int]" could always be true in boolean context
313
+ if Alias := int: # E: Function "Alias" could always be true in boolean context \
314
+ # E: Function "int" could always be true in boolean context
314
315
z3: Alias # E: Variable "Alias" is not valid as a type \
315
316
# N: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
316
317
Original file line number Diff line number Diff line change @@ -936,7 +936,7 @@ class Case1:
936
936
return False and self.missing() # E: Right operand of "and" is never evaluated
937
937
938
938
def test2(self) -> bool:
939
- return not self.property_decorator_missing and self.missing() # E: Function "Callable[[], bool] " could always be true in boolean context \
939
+ return not self.property_decorator_missing and self.missing() # E: Function "property_decorator_missing " could always be true in boolean context \
940
940
# E: Right operand of "and" is never evaluated
941
941
942
942
def property_decorator_missing(self) -> bool:
You can’t perform that action at this time.
0 commit comments