|
6 | 6 |
|
7 | 7 | import os |
8 | 8 | import sys |
| 9 | +from typing import assert_type |
9 | 10 |
|
| 11 | +def test(a: int, b: str): |
| 12 | + val1: int | str |
| 13 | + if sys.version_info >= (3, 8): |
| 14 | + val1 = a |
| 15 | + else: |
| 16 | + val1 = b |
10 | 17 |
|
11 | | -if sys.version_info >= (3, 8): |
12 | | - pass |
13 | | -else: |
14 | | - val1: int = "" # Should not generate an error |
| 18 | + assert_type(val1, int) |
15 | 19 |
|
16 | | -if sys.version_info >= (3, 8, 0): |
17 | | - pass |
18 | | -else: |
19 | | - val2: int = "" # E?: May not generate an error (support for three-element sys.version is optional) |
| 20 | + val2: int | str |
| 21 | + if sys.version_info >= (3, 8, 0): |
| 22 | + val2 = a |
| 23 | + else: |
| 24 | + val2 = b |
20 | 25 |
|
21 | | -if sys.version_info < (3, 8): |
22 | | - val3: int = "" # Should not generate an error |
| 26 | + assert_type(val2, int) # E?: May not generate an error (support for three-element sys.version is optional) |
23 | 27 |
|
24 | | -if sys.version_info < (3, 100, 0): |
25 | | - pass |
26 | | -else: |
27 | | - val3: int = "" # E?: May not generate an error (support for three-element sys.version is optional) |
| 28 | + if sys.version_info < (3, 8): |
| 29 | + val3 = "" |
| 30 | + else: |
| 31 | + val4 = "" |
28 | 32 |
|
| 33 | + this_raises = val3 # E: `val3` is undefined |
| 34 | + does_not_raise = val4 # should not error |
29 | 35 |
|
30 | | -if sys.platform == "bogus_platform": |
31 | | - val5: int = "" # Should not generate an error |
| 36 | + val5: int | str |
| 37 | + if sys.version_info < (3, 100, 0): |
| 38 | + val5 = a |
| 39 | + else: |
| 40 | + val5 = b |
32 | 41 |
|
33 | | -if sys.platform != "bogus_platform": |
34 | | - pass |
35 | | -else: |
36 | | - val6: int = "" # Should not generate an error |
| 42 | + assert_type(val5, int) # E?: May not generate an error (support for three-element sys.version is optional) |
37 | 43 |
|
38 | 44 |
|
39 | | -if os.name == "bogus_os": |
40 | | - val7: int = "" # E?: May not generate an error (support for os.name is optional) |
| 45 | + if sys.platform == "bogus_platform": |
| 46 | + val6 = "" |
| 47 | + else: |
| 48 | + val7 = "" |
41 | 49 |
|
42 | | -if os.name != "bogus_platform": |
43 | | - pass |
44 | | -else: |
45 | | - val8: int = "" # E?: May not generate an error (support for os.name is optional) |
| 50 | + this_raises = val6 # E: `val6` is undefined |
| 51 | + does_not_raise = val7 # should not error |
| 52 | + |
| 53 | + if sys.platform != "bogus_platform": |
| 54 | + val8 = "" |
| 55 | + else: |
| 56 | + val9 = "" |
| 57 | + |
| 58 | + does_not_raise = val8 # should not error |
| 59 | + this_raises = val9 # E: `val9` is undefined |
| 60 | + |
| 61 | + if os.name == "bogus_os": |
| 62 | + val10 = "" |
| 63 | + else: |
| 64 | + val11 = "" |
| 65 | + |
| 66 | + this_raises = val10 # E?: `val10` is undefined, but support for `os.name` is optional |
| 67 | + does_not_raise = val11 # E? should not error if `os.name` control flow is supported, but might be flagged as possibly undefined otherwise |
| 68 | + |
| 69 | + if os.name != "bogus_os": |
| 70 | + val12 = "" |
| 71 | + else: |
| 72 | + val13 = "" |
| 73 | + |
| 74 | + does_not_raise = val12 # E?: should not error if `os.name` control flow is supported, but might be flagged as possibly undefined otherwise |
| 75 | + this_raises = val13 # E?: `val13` is undefined, but support for `os.name` is optional |
0 commit comments