Skip to content

Commit 5c6d763

Browse files
author
hauntsaninja
committed
more copy changes
1 parent 31977ab commit 5c6d763

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

docs/source/error_code_list2.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,18 @@ mypy generates an error if it thinks that an expression is redundant.
216216
[i for i in range(x) if isinstance(i, int)]
217217
218218
219-
Check that expression is not implicitly true in boolean context [implicit-bool]
219+
Check that expression is not implicitly true in boolean context [truthy-bool]
220220
--------------------------------------------------------------------------------
221221

222222
Warn when an expression whose type does not implement __bool__ or __len__ is used in boolean context
223-
since it would always evaluate as true.
223+
since it could always evaluate to true (if one also assumes that no subtype implements __bool__ or
224+
__len__).
224225

225226
.. code-block:: python
226227
227228
class Foo:
228229
pass
229230
foo = Foo()
230-
# Error: "foo" has type "Foo" which does not implement __bool__ or __len__ so it will always be true in boolean context
231+
# Error: "foo" has type "Foo" which does not implement __bool__ or __len__ so it could always be true in boolean context
231232
if foo:
232233
...

mypy/checker.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4026,22 +4026,22 @@ def format_expr_type() -> str:
40264026

40274027
if isinstance(t, FunctionLike):
40284028
self.msg.fail(
4029-
f'Function "{t}" will always be true in boolean context', expr,
4030-
code=codes.IMPLICIT_BOOL,
4029+
f'Function "{t}" could always be true in boolean context', expr,
4030+
code=codes.TRUTHY_BOOL,
40314031
)
40324032
elif isinstance(t, UnionType):
40334033
self.msg.fail(
40344034
f"{format_expr_type()} of which no members implement __bool__ or __len__ "
4035-
"so it will always be true in boolean context",
4035+
"so it could always be true in boolean context",
40364036
expr,
4037-
code=codes.IMPLICIT_BOOL,
4037+
code=codes.TRUTHY_BOOL,
40384038
)
40394039
else:
40404040
self.msg.fail(
40414041
f'{format_expr_type()} which does not implement __bool__ or __len__ '
4042-
'so it will always be true in boolean context',
4042+
'so it could always be true in boolean context',
40434043
expr,
4044-
code=codes.IMPLICIT_BOOL,
4044+
code=codes.TRUTHY_BOOL,
40454045
)
40464046

40474047
def find_type_equals_check(self, node: ComparisonExpr, expr_indices: List[int]

mypy/errorcodes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ def __str__(self) -> str:
122122
REDUNDANT_EXPR: Final = ErrorCode(
123123
"redundant-expr", "Warn about redundant expressions", "General", default_enabled=False
124124
)
125-
IMPLICIT_BOOL: Final = ErrorCode(
126-
'implicit-bool',
127-
"Warn about potential use of implicit bool (that always returns true)",
125+
TRUTHY_BOOL: Final = ErrorCode(
126+
'truthy-bool',
127+
"Warn about expressions that could always evaluate to true in boolean contexts",
128128
'General',
129129
default_enabled=False
130130
)

test-data/unit/check-errorcodes.test

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -808,14 +808,14 @@ from typing_extensions import TypedDict
808808
Foo = TypedDict("Bar", {}) # E: First argument "Bar" to TypedDict() does not match variable name "Foo" [name-match]
809809
[builtins fixtures/dict.pyi]
810810
[case testImplicitBool]
811-
# flags: --enable-error-code implicit-bool
811+
# flags: --enable-error-code truthy-bool
812812
from typing import List, Union
813813

814814
class Foo:
815815
pass
816816

817817
foo = Foo()
818-
if foo: # E: "__main__.foo" has type "__main__.Foo" which does not implement __bool__ or __len__ so it will always be true in boolean context [implicit-bool]
818+
if foo: # E: "__main__.foo" has type "__main__.Foo" which does not implement __bool__ or __len__ so it could always be true in boolean context [truthy-bool]
819819
pass
820820

821821
zero = 0
@@ -839,14 +839,14 @@ if good_union:
839839
pass
840840

841841
bad_union: Union[Foo, object] = Foo()
842-
if bad_union: # E: "__main__.bad_union" has type "Union[__main__.Foo, builtins.object]" of which no members implement __bool__ or __len__ so it will always be true in boolean context [implicit-bool]
842+
if bad_union: # E: "__main__.bad_union" has type "Union[__main__.Foo, builtins.object]" of which no members implement __bool__ or __len__ so it could always be true in boolean context [truthy-bool]
843843
pass
844844

845845
def f():
846846
pass
847-
if f: # E: Function "def () -> Any" will always be true in boolean context [implicit-bool]
847+
if f: # E: Function "def () -> Any" could always be true in boolean context [truthy-bool]
848848
pass
849-
conditional_result = 'foo' if f else 'bar' # E: Function "def () -> Any" will always be true in boolean context [implicit-bool]
849+
conditional_result = 'foo' if f else 'bar' # E: Function "def () -> Any" could always be true in boolean context [truthy-bool]
850850

851851
lst: List[int] = []
852852
if lst:

0 commit comments

Comments
 (0)