8000 Check expr that are implicitly true for lack dunder bool/len by ikonst · Pull Request #10666 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Check expr that are implicitly true for lack dunder bool/len #10666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1bc2b9d
wip
ikonst May 29, 2021
b3b301f
fix fixtures and tests
ikonst Jun 18, 2021
76bd3e2
Undo unneeded test change
ikonst Jun 25, 2021
801f274
Let’s try to just warn in boolean context (no tests yet)
ikonst Jun 25, 2021
cbcd9d9
disable for non-strict optional + message
ikonst Jun 25, 2021
c58bb6a
futile attempt to improve _format_expr_name
ikonst Jun 25, 2021
6e497bb
kick CI
ikonst Jun 25, 2021
f0a5081
even more futile attempts on _format_expr_name
ikonst Jun 25, 2021
12278df
add error code
ikonst Jun 25, 2021
bcf8706
docs
ikonst Jun 25, 2021
050bd67
fix type_guard support
ikonst Jun 25, 2021
d2851a3
fix _format_expr_name sig
ikonst Jun 25, 2021
6f0951d
revert change to testConditionalBoolLiteralUnionNarrowing
ikonst Jun 25, 2021
dc70b7c
handle FunctionLikes + re-add test
ikonst Jun 25, 2021
c68df2f
fix list fixture
ikonst Jun 25, 2021
f346448
fix typing
ikonst Jun 26, 2021
903d72b
Merge remote-tracking branch 'origin/master' into check-always-true
ikonst Jun 30, 2021
d36a54c
fix type errors
ikonst Jun 30, 2021
b9dd548
fix TypeFixture
ikonst Jun 30, 2021
212af09
fix sphinx syntax
ikonst Jun 30, 2021
246d065
restructure _check_for_truthy_type
ikonst Jun 30, 2021
9e19e85
Rewrite implicit_bool short description
ikonst Jun 30, 2021
1753f2c
Remove unused _is_truthy_instance
ikonst Jul 1, 2021
e60082d
why did I ever change this code?
ikonst Jul 1, 2021
250c19b
testImplicitBool: clean up newlines
ikonst Aug 5, 2021
7166b54
Revert most of the changes to test fixtures
ikonst Aug 5, 2021
9349eef
Merge remote-tracking branch 'origin/master' into check-always-true
ikonst Aug 5, 2021
d432220
confused but removing timedelta.__bool__
ikonst Aug 5, 2021
6267456
Apply suggestions from code review
hauntsaninja Aug 5, 2021
31977ab
Update test-data/unit/check-errorcodes.test
hauntsaninja Aug 5, 2021
5c6d763
more copy changes
Aug 8, 2021
13af1eb
add a test
Aug 8, 2021
338e35b
Try to provide more color in the docs
ikonst Sep 3, 2021
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
Prev Previous commit
Next Next commit
Revert most of the changes to test fixtures
  • Loading branch information
ikonst committed Aug 5, 2021
commit 7166b54a7ac6e8c73a7c0bd1869d15c577e913d4
5 changes: 2 additions & 3 deletions test-data/unit/check-dynamic-typing.test
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,8 @@ class C: pass
[file builtins.py]
class object:
def __init__(self): pass
class int:
def __bool__(self) -> bool: pass
class bool(int): pass
class bool: pass
class int: pass
class type: pass
class function: pass
class str: pass
Expand Down
6 changes: 3 additions & 3 deletions test-data/unit/check-enum.test
Original file line number Diff line number Diff line change
Expand Up @@ -894,13 +894,13 @@ else:

[case testEnumReachabilityWithNone]
# flags: --strict-optional
from enum import Flag
from enum import Enum
from typing import Optional

class Foo(Flag):
class Foo(Enum):
A = 1
B = 2
C = 4
C = 3

x: Optional[Foo]
if x:
Expand Down
6 changes: 2 additions & 4 deletions test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,7 @@ if int():
b = b or a # E: Incompatible types in assignment (expression has type "Union[bool, A]", variable has type "bool")
if int():
b = a or b # E: Incompatible types in assignment (expression has type "Union[A, bool]", variable has type "bool")
class A:
def __bool__(self) -> bool: pass
class A: pass

[builtins fixtures/bool.pyi]

Expand Down Expand Up @@ -376,8 +375,7 @@ if int():
d = c or d # E: Incompatible types in assignment (expression has type "C", variable has type "D")
if int():
d = d or c # E: Incompatible types in assignment (expression has type "C", variable has type "D")
class C:
def __bool__(self) -> bool: pass
class C: pass
class D(C): pass
[builtins fixtures/bool.pyi]

Expand Down
6 changes: 2 additions & 4 deletions test-data/unit/check-inference-context.test
Original file line number Diff line number Diff line change
Expand Up @@ -749,10 +749,8 @@ if int():
if int():
b = b or c # E: Incompatible types in assignment (expression has type "Union[List[B], List[C]]", variable has type "List[B]")

class A:
def __bool__(self) -> bool: ...
class B:
def __bool__(self) -> bool: ...
class A: pass
class B: pass
class C(B): pass
[builtins fixtures/list.pyi]

Expand Down
3 changes: 1 addition & 2 deletions test-data/unit/check-typevar-values.test
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ class B:
def g(self) -> B: return B()
AB = TypeVar('AB', A, B)
def f(x: AB) -> AB:
indeterminate: bool
y = x
if indeterminate:
if y:
return y.f()
else:
return y.g() # E: Incompatible return value type (got "B", expected "A")
Expand Down
6 changes: 2 additions & 4 deletions test-data/unit/fixtures/bool.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ class object:
class type: pass
class tuple(Generic[T]): pass
class function: pass
class int:
def __bool__(self) -> 'bool': pass
class int: pass
class bool(int): pass
class float: pass
class str:
def __len__(self) -> int: pass
class str: pass
class unicode: pass
class ellipsis: pass
1 change: 0 additions & 1 deletion test-data/unit/fixtures/dict.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class dict(Mapping[KT, VT]):

class int: # for convenience
def __add__(self, x: int) -> int: pass
def __bool__(self) -> bool: pass

class str: pass # for keyword argument key type
class unicode: pass # needed for py2 docstrings
Expand Down
2 changes: 0 additions & 2 deletions test-data/unit/fixtures/isinstancelist.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ def issubclass(x: object, t: Union[type, Tuple]) -> bool: pass

class int:
def __add__(self, x: int) -> int: pass
def __bool__(self) -> bool: pass
class float: pass
class bool(int): pass
class str:
def __add__(self, x: str) -> str: pass
def __getitem__(self, x: int) -> str: pass
def __len__(self) -> int: pass

T = TypeVar('T')
KT = TypeVar('KT')
Expand Down
4 changes: 1 addition & 3 deletions test-data/unit/fixtures/ops.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ class tuple(Sequence[Tco]):

class function: pass

class bool(int): pass
class bool: pass

class str:
def __init__(self, x: 'int') -> None: pass
def __add__(self, x: 'str') -> 'str': pass
def __eq__(self, x: object) -> bool: pass
def __len__(self) -> int: pass
def startswith(self, x: 'str') -> bool: pass
def strip(self) -> 'str': pass

Expand All @@ -56,7 +55,6 @@ class int:
def __le__(self, x: 'int') -> bool: pass
def __gt__(self, x: 'int') -> bool: pass
def __ge__(self, x: 'int') -> bool: pass
def __bool__(self) -> bool: pass

class float:
def __add__(self, x: 'float') -> 'float': pass
Expand Down
1 change: 0 additions & 1 deletion test-data/unit/fixtures/primitives.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class int:
def __init__(self, x: object = ..., base: int = ...) -> None: pass
def __add__(self, i: int) -> int: pass
def __rmul__(self, x: int) -> int: pass
def __bool__(self) -> bool: pass
class float:
def __float__(self) -> float: pass
class complex: pass
Expand Down
7 changes: 2 additions & 5 deletions test-data/unit/lib-stub/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ class type:
# These are provided here for convenience.
class int:
def __add__(self, other: int) -> int: pass
def __bool__(self) -> bool: pass
class bool(int): pass
class float: pass

class str:
def __len__(self) -> int: pass
class bytes:
def __len__(self) -> int: pass
class str: pass
class bytes: pass

class function: pass
class ellipsis: pass
Expand Down
1 change: 0 additions & 1 deletion test-data/unit/lib-stub/enum.pyi
9C6C
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def unique(enumeration: _T) -> _T: pass

class Flag(Enum):
def __or__(self: _T, other: Union[int, _T]) -> _T: pass
def __bool__(self) -> bool: ...


class IntFlag(int, Flag):
Expand Down
1 change: 0 additions & 1 deletion test-data/unit/lib-stub/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class Generator(Iterator[T], Generic[T, U, V]):

class Sequence(Iterable[T_co]):
def __getitem__(self, n: Any) -> T_co: pass
def __len__(self) -> int: pass

class Mapping(Generic[T, T_co]): pass

Expand Down
0