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:
52955295 else :
52965296 return f"Expression has type { typ } "
52975297
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+
52985305 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 )
53025307 elif isinstance (t , UnionType ):
53035308 self .fail (message_registry .TYPE_ALWAYS_TRUE_UNIONTYPE .format (format_expr_type ()), expr )
53045309 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:
900900# flags: --strict-optional
901901def f():
902902 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]
904904 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]
906906 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]
908908
909909[case testTruthyIterable]
910910# 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
21012101import bar
21022102[file bar.py]
21032103def 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
2105210542 + "no" # type: ignore # E: "type: ignore" comment without error code (consider "type: ignore[operator]" instead)
21062106[file tests/__init__.py]
21072107[file tests/foo.py]
21082108def 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
2110211042 + "no" # type: ignore
21112111[file mypy.ini]
21122112\[mypy]
Original file line number Diff line number Diff line change @@ -192,7 +192,7 @@ if foo: ...
192192# mypy: enable-error-code="ignore-without-code"
193193
194194def 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
19619642 + "no" # type: ignore # E: "type: ignore" comment without error code (consider "type: ignore[operator]" instead)
197197
198198[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:
310310 z2: NT # E: Variable "NT" is not valid as a type \
311311 # N: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
312312
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
314315 z3: Alias # E: Variable "Alias" is not valid as a type \
315316 # N: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
316317
Original file line number Diff line number Diff line change @@ -936,7 +936,7 @@ class Case1:
936936 return False and self.missing() # E: Right operand of "and" is never evaluated
937937
938938 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 \
940940 # E: Right operand of "and" is never evaluated
941941
942942 def property_decorator_missing(self) -> bool:
You can’t perform that action at this time.
0 commit comments