← Back to index

directives_version_platform.py

True Positive
False Positive
False Negative
Optional (detected)
Warning or Info
TP: 0
FP: 4
FN: 0
Optional: 4 / 4
1"""
2Tests checking the version or platform.
3"""
4
5# Specification: https://typing.readthedocs.io/en/latest/spec/directives.html#version-and-platform-checking
6
7import os
8import sys
9
11if sys.version_info >= (3, 8):
12 pass
13else:
14 val1: int = "" # Should not generate an error
Unexpected error [invalid-assignment] Object of type `Literal[""]` is not assignable to `int`
16if sys.version_info >= (3, 8, 0):
17 pass
18else:
19 val2: int = "" # E?: May not generate an error (support for three-element sys.version is optional)
[invalid-assignment] Object of type `Literal[""]` is not assignable to `int`
21if sys.version_info < (3, 8):
22 val3: int = "" # Should not generate an error
Unexpected error [invalid-assignment] Object of type `Literal[""]` is not assignable to `int`
24if sys.version_info < (3, 100, 0):
25 pass
26else:
27 val3: int = "" # E?: May not generate an error (support for three-element sys.version is optional)
[invalid-assignment] Object of type `Literal[""]` is not assignable to `int`
30if sys.platform == "bogus_platform":
31 val5: int = "" # Should not generate an error
Unexpected error [invalid-assignment] Object of type `Literal[""]` is not assignable to `int`
33if sys.platform != "bogus_platform":
34 pass
35else:
36 val6: int = "" # Should not generate an error
Unexpected error [invalid-assignment] Object of type `Literal[""]` is not assignable to `int`
39if os.name == "bogus_os":
40 val7: int = "" # E?: May not generate an error (support for os.name is optional)
[invalid-assignment] Object of type `Literal[""]` is not assignable to `int`
42if os.name != "bogus_platform":
43 pass
44else:
45 val8: int = "" # E?: May not generate an error (support for os.name is optional)
[invalid-assignment] Object of type `Literal[""]` is not assignable to `int`