Skip to content

Commit 01fed1a

Browse files
committed
Use bool() in tests when we want an unspecified bool in a conditional
1 parent 35f6454 commit 01fed1a

8 files changed

+47
-41
lines changed

test-data/unit/check-fastparse.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class C:
3636
[case testFastParseConditionalProperty]
3737
# flags: fast-parser
3838
class C:
39-
if 1:
39+
if bool():
4040
@property
4141
def x(self) -> str: pass
4242
@x.setter

test-data/unit/check-functions.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1534,12 +1534,13 @@ g()
15341534
[builtins fixtures/list.py]
15351535

15361536
[case testFunctionDefinitionWithWhileStatement]
1537-
while 1:
1537+
while bool():
15381538
def f(): pass
15391539
else:
15401540
def g(): pass
15411541
f()
15421542
g()
1543+
[builtins fixtures/bool.py]
15431544

15441545
[case testBareCallable]
15451546
from typing import Callable, Any

test-data/unit/check-isinstance.test

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ x = None # type: List[Any]
1212
def foo() -> List[int]: pass
1313
def bar() -> List[str]: pass
1414

15-
if 1:
15+
if bool():
1616
x = foo()
1717
else:
1818
x = bar()
@@ -143,11 +143,11 @@ def bar() -> None:
143143
x = foo()
144144
if isinstance(x, int):
145145
return
146-
while 1:
146+
while bool():
147147
x + 'a'
148-
while 1:
148+
while bool():
149149
x = foo()
150-
if 1:
150+
if bool():
151151
return
152152
x = 'a'
153153
x + 'a'
@@ -163,24 +163,24 @@ def bar() -> None:
163163
x = foo()
164164
if isinstance(x, int):
165165
return
166-
while 1:
166+
while bool():
167167
x + 'a'
168-
while 1:
168+
while bool():
169169
x = foo()
170-
if 1:
170+
if bool():
171171
return
172172
x = 'a'
173173
x + 'a'
174174

175175
x = foo()
176176
if isinstance(x, int):
177177
return
178-
while 1:
178+
while bool():
179179
x + 'a'
180-
while 1:
180+
while bool():
181181
x + 'a' # E: Unsupported operand types for + (likely involving Union)
182182
x = foo()
183-
if 1:
183+
if bool():
184184
continue
185185
x = 'a'
186186
x = 'a'
@@ -269,7 +269,7 @@ class A: pass
269269
class B(A): z = 1
270270

271271
x = A()
272-
while 1:
272+
while bool():
273273
try:
274274
x.z # E: "A" has no attribute "z"
275275
x = A()
@@ -473,7 +473,7 @@ class House:
473473
h = House()
474474
h.pet = Dog()
475475

476-
while 1:
476+
while bool():
477477
if isinstance(h.pet, Dog):
478478
if isinstance(h.pet.paws, str):
479479
x = h.pet.paws + 'a'
@@ -560,7 +560,7 @@ if isinstance(h.pet, Dog):
560560
if isinstance(h.pet.paws, str):
561561
for i in [1]:
562562
h.pet.paws + 'a'
563-
if 1:
563+
if bool():
564564
break
565565
h.pet.paws = 1
566566
h.pet.paws + 1
@@ -612,7 +612,7 @@ from typing import Union, List
612612

613613
x = None # type: Union[int, str, List[int]]
614614

615-
while 1:
615+
while bool():
616616
if isinstance(x, int):
617617
x + 1
618618
elif isinstance(x, str):
@@ -628,7 +628,7 @@ from typing import Union, List
628628

629629
x = None # type: Union[int, str, List[int]]
630630

631-
while 1:
631+
while bool():
632632
if isinstance(x, int):
633633
x + 1
634634
break
@@ -644,7 +644,7 @@ x + [1] # E: Unsupported operand types for + (likely involving Uni
644644
[case testIsInstanceThreeUnion3]
645645
from typing import Union, List
646646

647-
while 1:
647+
while bool():
648648
x = None # type: Union[int, str, List[int]]
649649
x = 1
650650
if isinstance(x, int):
@@ -724,7 +724,7 @@ x + 1 # E: Unsupported operand types for + ("str" and "int")
724724
x = 1
725725
x + 1
726726

727-
while 1:
727+
while bool():
728728
x + 1 # E: Unsupported operand types for + (likely involving Union)
729729
x = 'a'
730730
[builtins fixtures/isinstancelist.py]
@@ -757,7 +757,7 @@ def foo() -> Union[int, str]: pass
757757
x = foo()
758758
x = 1
759759

760-
while 1:
760+
while bool():
761761
x + 1
762762
x = 'a'
763763
break
@@ -782,19 +782,19 @@ def foo() -> Union[int, str]: pass
782782
x = foo()
783783
x = 1
784784

785-
while 1:
785+
while bool():
786786
x + 1
787-
if 1:
787+
if bool():
788788
x = 'a'
789789
break
790790
else:
791791
x + 1
792792
x = 'a'
793793
x + 'a'
794794
x = 1
795-
while 1:
795+
while bool():
796796
x + 1 # E: Unsupported operand types for + (likely involving Union)
797-
if 1:
797+
if bool():
798798
x = 'a'
799799
continue
800800
else:
@@ -812,7 +812,7 @@ x = 1
812812

813813
for y in [1]:
814814
x + 1
815-
if 1:
815+
if bool():
816816
x = 'a'
817817
break
818818
else:
@@ -822,7 +822,7 @@ x + 'a'
822822
x = 1
823823
for y in [1]:
824824
x + 1 # E: Unsupported operand types for + (likely involving Union)
825-
if 1:
825+
if bool():
826826
x = 'a'
827827
continue
828828
else:
@@ -848,8 +848,8 @@ else:
848848
x + 1
849849
x + 1 # E: Unsupported operand types for + (likely involving Union)
850850
x = 1
851-
while 1:
852-
while 1:
851+
while bool():
852+
while bool():
853853
break
854854
else:
855855
x = 'a'
@@ -883,21 +883,21 @@ def bar() -> None:
883883
if isinstance(x, str):
884884
x + 'a'
885885
else:
886-
while 1:
886+
while bool():
887887
if isinstance(x, int):
888888
x + 1
889889
else:
890890
x.a
891891
break
892-
while 1:
892+
while bool():
893893
if isinstance(x, int):
894894
x + 1
895895
else:
896896
x.a
897897
continue
898898

899899
#for i in [1]:
900-
while 1:
900+
while bool():
901901
if isinstance(x, int):
902902
x + 1
903903
else:
@@ -967,15 +967,15 @@ x + 'a' # E: Unsupported operand types for + ("int" and "str")
967967
[case testUnreachableCode]
968968
x = 1 # type: int
969969

970-
while 1:
970+
while bool():
971971
x = 'a' # E: Incompatible types in assignment (expression has type "str", variable has type "int")
972972
break
973973
x = 'a' # Note: no error because unreachable code
974974
[builtins fixtures/isinstancelist.py]
975975

976976
[case testUnreachableCode2]
977977
x = 1
978-
while 1:
978+
while bool():
979979
try:
980980
pass
981981
except:

test-data/unit/check-unreachable-code.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,11 @@ def f(): pass
104104
PY3 = f()
105105
if PY3:
106106
pass
107-
elif 1:
107+
elif bool():
108108
import nonexistent
109109
1 + ''
110110
else:
111111
import bad_name
112112
1 + ''
113+
[builtins fixtures/bool.py]
113114
[out]

test-data/unit/check-weak-typing.test

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ x + 'a'
165165
[case testWeakConditionalChanges]
166166
# mypy: weak
167167
def f():
168-
if 1:
168+
if bool():
169169
x = 1
170170
x + 1
171171
x + 'a' # E: Unsupported operand types for + ("int" and "str")
@@ -177,11 +177,11 @@ def f():
177177
x + 'a'
178178
def g():
179179
x = 1
180-
if 1:
180+
if bool():
181181
x = 1
182182
else:
183183
x = 'a'
184-
if 1:
184+
if bool():
185185
return
186186
x + 'a'
187187
[builtins fixtures/ops.py]
@@ -213,17 +213,18 @@ f(*args, y=2)
213213

214214
# I couldn't come up with a simple example, but this showed a bug in
215215
# binders.
216-
if 1:
217-
if 1:
216+
if bool():
217+
if bool():
218218
pass
219-
if 1:
219+
if bool():
220220
z = ''
221221
pat = 1
222222
pat() # E: "int" not callable
223223
pat()
224224
pat = ''
225225
pat() # E: "str" not callable
226-
while 1:
226+
while bool():
227227
pass
228228
pat() # E: "str" not callable
229+
[builtins fixtures/bool.py]
229230
[out]

test-data/unit/fixtures/exception.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ class tuple: pass
77
class function: pass
88
class int: pass
99
class str: pass
10+
class bool: pass
1011

1112
class BaseException: pass

test-data/unit/fixtures/list.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ class tuple: pass
2525
class function: pass
2626
class int: pass
2727
class str: pass
28+
class bool: pass

test-data/unit/fixtures/property.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ class int: pass
1414
class str: pass
1515
class bytes: pass
1616
class tuple: pass
17+
class bool: pass

0 commit comments

Comments
 (0)