-
Notifications
You must be signed in to change notification settings - Fork 293
Expand file tree
/
Copy pathdirectives_version_platform.py
More file actions
75 lines (56 loc) · 1.93 KB
/
directives_version_platform.py
File metadata and controls
75 lines (56 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""
Tests checking the version or platform.
"""
# Specification: https://typing.readthedocs.io/en/latest/spec/directives.html#version-and-platform-checking
import os
import sys
from typing import assert_type
def test(a: int, b: str):
val1: int | str
if sys.version_info >= (3, 8):
val1 = a
else:
val1 = b
assert_type(val1, int)
val2: int | str
if sys.version_info >= (3, 8, 0):
val2 = a
else:
val2 = b
assert_type(val2, int) # E?: May not generate an error (support for three-element sys.version is optional)
if sys.version_info < (3, 8):
val3 = ""
else:
val4 = ""
this_raises = val3 # E: `val3` is undefined
does_not_raise = val4 # should not error
val5: int | str
if sys.version_info < (3, 100, 0):
val5 = a
else:
val5 = b
assert_type(val5, int) # E?: May not generate an error (support for three-element sys.version is optional)
if sys.platform == "bogus_platform":
val6 = ""
else:
val7 = ""
this_raises = val6 # E: `val6` is undefined
does_not_raise = val7 # should not error
if sys.platform != "bogus_platform":
val8 = ""
else:
val9 = ""
does_not_raise = val8 # should not error
this_raises = val9 # E: `val9` is undefined
if os.name == "bogus_os":
val10 = ""
else:
val11 = ""
this_raises = val10 # E?: `val10` is undefined, but support for `os.name` is optional
does_not_raise = val11 # E? should not error if `os.name` control flow is supported, but might be flagged as possibly undefined otherwise
if os.name != "bogus_platform":
val12 = ""
else:
val13 = ""
does_not_raise = val12 # E?: should not error if `os.name` control flow is supported, but might be flagged as possibly undefined otherwise
this_raises = val13 # E?: `val13` is undefined, but support for `os.name` is optional