@@ -481,25 +481,101 @@ import typing
481
481
def make() -> bool: pass
482
482
PY2 = PY3 = make()
483
483
484
- a = PY2 and 's'
485
- b = PY3 and 's'
486
- c = PY2 or 's'
487
- d = PY3 or 's'
488
- e = (PY2 or PY3) and 's'
489
- f = (PY3 or PY2) and 's'
490
- g = (PY2 or PY3) or 's'
491
- h = (PY3 or PY2) or 's'
484
+ a = PY2 and str()
485
+ b = PY3 and str()
486
+ c = PY2 or str()
487
+ d = PY3 or str()
488
+ e = (PY2 or PY3) and str()
489
+ f = (PY3 or PY2) and str()
490
+ g = (PY2 or PY3) or str()
491
+ h = (PY3 or PY2) or str()
492
492
reveal_type(a) # N: Revealed type is "builtins.bool"
493
- reveal_type(b) # N: Revealed type is "Literal['s'] "
494
- reveal_type(c) # N: Revealed type is "Literal['s'] "
493
+ reveal_type(b) # N: Revealed type is "builtins.str "
494
+ reveal_type(c) # N: Revealed type is "builtins.str "
495
495
reveal_type(d) # N: Revealed type is "builtins.bool"
496
- reveal_type(e) # N: Revealed type is "Literal['s'] "
497
- reveal_type(f) # N: Revealed type is "Literal['s'] "
496
+ reveal_type(e) # N: Revealed type is "builtins.str "
497
+ reveal_type(f) # N: Revealed type is "builtins.str "
498
498
reveal_type(g) # N: Revealed type is "builtins.bool"
499
499
reveal_type(h) # N: Revealed type is "builtins.bool"
500
500
[builtins fixtures/ops.pyi]
501
501
[out]
502
502
503
+ [case testConditionalValuesBinaryOps]
504
+ # flags: --platform linux
505
+ import sys
506
+
507
+ t_and_t = (sys.platform == 'linux' and sys.platform == 'linux') and str()
508
+ t_or_t = (sys.platform == 'linux' or sys.platform == 'linux') and str()
509
+ t_and_f = (sys.platform == 'linux' and sys.platform == 'windows') and str()
510
+ t_or_f = (sys.platform == 'linux' or sys.platform == 'windows') and str()
511
+ f_and_t = (sys.platform == 'windows' and sys.platform == 'linux') and str()
512
+ f_or_t = (sys.platform == 'windows' or sys.platform == 'linux') and str()
513
+ f_and_f = (sys.platform == 'windows' and sys.platform == 'windows') and str()
514
+ f_or_f = (sys.platform == 'windows' or sys.platform == 'windows') and str()
515
+ reveal_type(t_and_t) # N: Revealed type is "builtins.str"
516
+ reveal_type(t_or_t) # N: Revealed type is "builtins.str"
517
+ reveal_type(f_and_t) # N: Revealed type is "builtins.bool"
518
+ reveal_type(f_or_t) # N: Revealed type is "builtins.str"
519
+ reveal_type(t_and_f) # N: Revealed type is "builtins.bool"
520
+ reveal_type(t_or_f) # N: Revealed type is "builtins.str"
521
+ reveal_type(f_and_f) # N: Revealed type is "builtins.bool"
522
+ reveal_type(f_or_f) # N: Revealed type is "builtins.bool"
523
+ [builtins fixtures/ops.pyi]
524
+
525
+ [case testConditionalValuesNegation]
526
+ # flags: --platform linux
527
+ import sys
528
+
529
+ not_t = not sys.platform == 'linux' and str()
530
+ not_f = not sys.platform == 'windows' and str()
531
+ not_and_t = not (sys.platform == 'linux' and sys.platform == 'linux') and str()
532
+ not_and_f = not (sys.platform == 'linux' and sys.platform == 'windows') and str()
533
+ not_or_t = not (sys.platform == 'linux' or sys.platform == 'linux') and str()
534
+ not_or_f = not (sys.platform == 'windows' or sys.platform == 'windows') and str()
535
+ reveal_type(not_t) # N: Revealed type is "builtins.bool"
536
+ reveal_type(not_f) # N: Revealed type is "builtins.str"
537
+ reveal_type(not_and_t) # N: Revealed type is "builtins.bool"
538
+ reveal_type(not_and_f) # N: Revealed type is "builtins.str"
539
+ reveal_type(not_or_t) # N: Revealed type is "builtins.bool"
540
+ reveal_type(not_or_f) # N: Revealed type is "builtins.str"
541
+ [builtins fixtures/ops.pyi]
542
+
543
+ [case testConditionalValuesUnsupportedOps]
544
+ # flags: --platform linux
545
+ import sys
546
+
547
+ unary_minus = -(sys.platform == 'linux') and str()
548
+ binary_minus = ((sys.platform == 'linux') - (sys.platform == 'linux')) and str()
549
+ reveal_type(unary_minus) # N: Revealed type is "Union[Literal[0], builtins.str]"
550
+ reveal_type(binary_minus) # N: Revealed type is "Union[Literal[0], builtins.str]"
551
+ [builtins fixtures/ops.pyi]
552
+
553
+ [case testMypyFalseValuesInBinaryOps_no_empty]
554
+ # flags: --platform linux
555
+ import sys
556
+ from typing import TYPE_CHECKING
557
+
558
+ MYPY = 0
559
+
560
+ if TYPE_CHECKING and sys.platform == 'linux':
561
+ def foo1() -> int: ...
562
+ if sys.platform == 'linux' and TYPE_CHECKING:
563
+ def foo2() -> int: ...
564
+ if MYPY and sys.platform == 'linux':
565
+ def foo3() -> int: ...
566
+ if sys.platform == 'linux' and MYPY:
567
+ def foo4() -> int: ...
568
+
569
+ if TYPE_CHECKING or sys.platform == 'linux':
570
+ def bar1() -> int: ... # E: Missing return statement
571
+ if sys.platform == 'linux' or TYPE_CHECKING:
572
+ def bar2() -> int: ... # E: Missing return statement
573
+ if MYPY or sys.platform == 'linux':
574
+ def bar3() -> int: ... # E: Missing return statement
575
+ if sys.platform == 'linux' or MYPY:
576
+ def bar4() -> int: ... # E: Missing return statement
577
+ [builtins fixtures/ops.pyi]
578
+
503
579
[case testShortCircuitAndWithConditionalAssignment]
504
580
# flags: --platform linux
505
581
import sys
0 commit comments