@@ -687,6 +687,110 @@ e = 1 # E: Assignment to variable 'e' outside except: block
687
687
e = E1() # E: Assignment to variable 'e' outside except: block
688
688
[builtins fixtures/exception.pyi]
689
689
690
+ [case testExceptionVariableReuseInDeferredNode1]
691
+ def f(*a: BaseException) -> int:
692
+ x
693
+ try: pass
694
+ except BaseException as err: pass
695
+ try: pass
696
+ except BaseException as err: f(err)
697
+ x = f()
698
+ [builtins fixtures/exception.pyi]
699
+
700
+ [case testExceptionVariableReuseInDeferredNode2]
701
+ def f(*a: BaseException) -> int:
702
+ try: pass
703
+ except BaseException as err: pass
704
+ x
705
+ try: pass
706
+ except BaseException as err: f(err)
707
+ x = f()
708
+ [builtins fixtures/exception.pyi]
709
+
710
+ [case testExceptionVariableReuseInDeferredNode3]
711
+ def f(*a: BaseException) -> int:
712
+ try: pass
713
+ except BaseException as err: pass
714
+ try: pass
715
+ except BaseException as err: f(err)
716
+ x
717
+ x = f()
718
+ [builtins fixtures/exception.pyi]
719
+
720
+ [case testExceptionVariableReuseInDeferredNode4]
721
+ class EA(BaseException):
722
+ a = None # type: int
723
+ class EB(BaseException):
724
+ b = None # type: str
725
+ def f(*arg: BaseException) -> int:
726
+ x
727
+ try: pass
728
+ except EA as err:
729
+ f(err)
730
+ a = err.a
731
+ reveal_type(a)
732
+ try: pass
733
+ except EB as err:
734
+ f(err)
735
+ b = err.b
736
+ reveal_type(b)
737
+ x = f()
738
+ [builtins fixtures/exception.pyi]
739
+ [out]
740
+ main: note: In function "f":
741
+ main:11: error: Revealed type is 'builtins.int'
742
+ main:16: error: Revealed type is 'builtins.str'
743
+
744
+ [case testExceptionVariableReuseInDeferredNode5]
745
+ class EA(BaseException):
746
+ a = None # type: int
747
+ class EB(BaseException):
748
+ b = None # type: str
749
+ def f(*arg: BaseException) -> int:
750
+ try: pass
751
+ except EA as err:
752
+ f(err)
753
+ a = err.a
754
+ reveal_type(a)
755
+ x
756
+ try: pass
757
+ except EB as err:
758
+ f(err)
759
+ b = err.b
760
+ reveal_type(b)
761
+ x = f()
762
+ [builtins fixtures/exception.pyi]
763
+ [out]
764
+ main: note: In function "f":
765
+ main:10: error: Revealed type is 'builtins.int'
766
+ main:16: error: Revealed type is 'builtins.str'
767
+
768
+ [case testExceptionVariableReuseInDeferredNode6]
769
+ class EA(BaseException):
770
+ a = None # type: int
771
+ class EB(BaseException):
772
+ b = None # type: str
773
+ def f(*arg: BaseException) -> int:
774
+ try: pass
775
+ except EA as err:
776
+ f(err)
777
+ a = err.a
778
+ reveal_type(a)
779
+ try: pass
780
+ except EB as err:
781
+ f(err)
782
+ b = err.b
783
+ reveal_type(b)
784
+ x
785
+ x = f()
786
+ [builtins fixtures/exception.pyi]
787
+ [out]
788
+ main: note: In function "f":
789
+ main:10: error: Revealed type is 'builtins.int'
790
+ main:15: error: Revealed type is 'builtins.str'
791
+
792
+
793
+
690
794
[case testArbitraryExpressionAsExceptionType]
691
795
import typing
692
796
a = BaseException
0 commit comments