Landed upstreamCorrectnessLanded Jul 23, 2026
Respect platform guards in conditional expressions
Fixed Pyrefly conditional-expression analysis so platform guards use the configured Python environment before reporting diagnostics or inferring branch types.
facebook/pyrefly · #4232
Problem
Pyrefly applied platform-condition evaluation at statement level but not inside ternary expressions. Code such as Windows-only subprocess attributes guarded by sys.platform could still produce missing-attribute diagnostics on non-Windows environments.
Approach
Added environment-aware boolean evaluation for sys.platform, sys.version_info, os.name, and type-checking guards, then used it in conditional-expression binding and inference so only the reachable branch contributes diagnostics and type information for platform-guarded expressions.
Impact and scope
- Removes false positives for real cross-platform Python code that uses ternary expressions around platform-specific stdlib attributes.
- Preserves ordinary constant-condition checking so unreachable branches not tied to configured environment guards still receive diagnostics.
- Keeps generator detection correct when a yield expression appears inside a platform-skipped ternary branch.
Validation
- Added Linux and Windows regression coverage for platform-guarded ternary expressions.
- Added skipped-branch yield coverage so generator status remains syntactically correct even when a platform branch is unreachable.
- Landed through Meta codesync with the PR resolution and issue closure pointing to the upstream commit.