directives_version_platform
error
Variable defined only in dead version/platform branch
When sys.version_info, sys.platform, or os.name is compared against a constant, one branch may be statically known to be dead for the configured target Python version (CHKARCH-VERSION-TARGET, issue #93) and platform. Variables defined exclusively in a dead branch are undefined outside that branch.
import sys
if sys.version_info < (3, 8):
val = "" # dead on Python 3.12
else:
other = ""
print(val) # E: `val` is only defined in a dead branch
print(other) # OK
How to handle it
Every rule is on by default — strict is the default, not a cage. You can dial
directives_version_platform down per-file or per-path from your editor or
pyproject.toml, or fix the code
so it type-checks. See the Type System rules and
the complete diagnostic reference.
Canonical URL: https://www.basilisk-python.dev/errors/directives_version_platform