crates/ty_python_semantic/resources/mdtest/sys_platform.md
sys.platformall platformsWhen python-platform="all" is specified, we fall back to the type of sys.platform declared in
typeshed:
[environment]
python-platform = "all"
import sys
reveal_type(sys.platform) # revealed: LiteralString
[environment]
python-platform = "linux"
import sys
reveal_type(sys.platform) # revealed: Literal["linux"]
[environment]
python-platform = "freebsd8"
import sys
reveal_type(sys.platform == "freebsd8") # revealed: Literal[True]
reveal_type(sys.platform == "linux") # revealed: Literal[False]
It is recommended to use
sys.platform.startswith(...) for platform checks:
import sys
reveal_type(sys.platform.startswith("freebsd")) # revealed: Literal[True]
reveal_type(sys.platform.startswith("linux")) # revealed: Literal[False]