mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-10 21:58:30 +00:00
1.1 KiB
1.1 KiB
sys.platform
Explicit selection of all
platforms
When 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
Explicit selection of a specific platform
[environment]
python-platform = "linux"
import sys
reveal_type(sys.platform) # revealed: Literal["linux"]
Testing for a specific platform
[environment]
python-platform = "freebsd8"
Exact comparison
import sys
reveal_type(sys.platform == "freebsd8") # revealed: Literal[True]
reveal_type(sys.platform == "linux") # revealed: Literal[False]
Substring comparison
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]