You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test-data/unit/check-errorcodes.test
+26Lines changed: 26 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -846,53 +846,75 @@ foo = Foo()
846
846
if foo: # E: "__main__.foo" has type "Foo" which does not implement __bool__ or __len__ so it could always be true in boolean context [truthy-bool]
847
847
pass
848
848
849
+
not foo # E: "__main__.foo" has type "Foo" which does not implement __bool__ or __len__ so it could always be true in boolean context [truthy-bool]
850
+
849
851
zero = 0
850
852
if zero:
851
853
pass
852
854
855
+
not zero
856
+
853
857
false = False
854
858
if false:
855
859
pass
856
860
861
+
not false
862
+
857
863
null = None
858
864
if null:
859
865
pass
860
866
867
+
not null
868
+
861
869
s = ''
862
870
if s:
863
871
pass
864
872
873
+
not s
874
+
865
875
good_union: Union[str, int] = 5
866
876
if good_union:
867
877
pass
868
878
if not good_union:
869
879
pass
870
880
881
+
not good_union
882
+
871
883
bad_union: Union[Foo, Bar] = Foo()
872
884
if bad_union: # E: "__main__.bad_union" has type "Union[Foo, Bar]" of which no members implement __bool__ or __len__ so it could always be true in boolean context [truthy-bool]
873
885
pass
874
886
if not bad_union: # E: "__main__.bad_union" has type "Union[Foo, Bar]" of which no members implement __bool__ or __len__ so it could always be true in boolean context [truthy-bool]
875
887
pass
876
888
889
+
not bad_union # E: "__main__.bad_union" has type "Union[Foo, Bar]" of which no members implement __bool__ or __len__ so it could always be true in boolean context [truthy-bool]
890
+
877
891
# 'object' is special and is treated as potentially falsy
878
892
obj: object = Foo()
879
893
if obj:
880
894
pass
881
895
if not obj:
882
896
pass
883
897
898
+
not obj
899
+
884
900
lst: List[int] = []
885
901
if lst:
886
902
pass
887
903
904
+
not lst
905
+
888
906
a: Any
889
907
if a:
890
908
pass
891
909
910
+
not a
911
+
892
912
any_or_object: Union[object, Any]
893
913
if any_or_object:
894
914
pass
895
915
916
+
not any_or_object
917
+
896
918
if (my_foo := Foo()): # E: "__main__.my_foo" has type "Foo" which does not implement __bool__ or __len__ so it could always be true in boolean context [truthy-bool]
897
919
pass
898
920
@@ -909,13 +931,17 @@ if not f: # E: Function "f" could always be true in boolean context [truthy-fu
909
931
pass
910
932
conditional_result = 'foo' if f else 'bar' # E: Function "f" could always be true in boolean context [truthy-function]
911
933
934
+
not f # E: Function "f" could always be true in boolean context [truthy-function]
935
+
912
936
[case testTruthyIterable]
913
937
# flags: --enable-error-code truthy-iterable
914
938
from typing import Iterable
915
939
def func(var: Iterable[str]) -> None:
916
940
if var: # E: "var" has type "Iterable[str]" which can always be true in boolean context. Consider using "Collection[str]" instead. [truthy-iterable]
917
941
...
918
942
943
+
not var # E: "var" has type "Iterable[str]" which can always be true in boolean context. Consider using "Collection[str]" instead. [truthy-iterable]
0 commit comments