Skip to content

Respect platform guards in conditional expressions#4232

Closed
goutamadwant wants to merge 1 commit into
facebook:mainfrom
goutamadwant:fix-platform-ternary
Closed

Respect platform guards in conditional expressions#4232
goutamadwant wants to merge 1 commit into
facebook:mainfrom
goutamadwant:fix-platform-ternary

Conversation

@goutamadwant

Copy link
Copy Markdown
Contributor

Summary

Use the configured Python environment when binding and inferring conditional expressions so only the reachable branch contributes diagnostics and types for sys.platform, sys.version_info, os.name, and type-checking guards.

This preserves the existing behavior for ordinary constant conditions, where unreachable branches are still checked for errors.

Fixes #2558

Test Plan

  • cargo test -p pyrefly test_platform_ternary -- --nocapture
  • cargo test -p pyrefly test_context_if_expr_unreachable -- --nocapture
  • python3 test.py (Scrut tests skipped because Scrut is not installed)

AI disclosure: AI was used to review the code and understanding the codebase.

@github-actions

Copy link
Copy Markdown

Diff from mypy_primer, showing the effect of this PR on open source code:

prefect (https://github.com/PrefectHQ/prefect)
- ERROR src/prefect/cli/server.py:662:23-58: No attribute `CREATE_NEW_PROCESS_GROUP` in module `subprocess` [missing-attribute]

apprise (https://github.com/caronc/apprise)
- ERROR apprise/url.py:463:17-25: Unpacked keyword argument `bool` is not assignable to parameter `string` with type `Buffer | None` in function `_hashlib.openssl_sha256` [bad-argument-type]
- ERROR apprise/url.py:499:17-25: Unpacked keyword argument `bool` is not assignable to parameter `string` with type `Buffer | None` in function `_hashlib.openssl_sha256` [bad-argument-type]
- ERROR apprise/url.py:504:64-72: Unpacked keyword argument `bool` is not assignable to parameter `string` with type `Buffer | None` in function `_hashlib.openssl_sha256` [bad-argument-type]
- ERROR apprise/url.py:520:17-25: Unpacked keyword argument `bool` is not assignable to parameter `string` with type `Buffer | None` in function `_hashlib.openssl_sha256` [bad-argument-type]
- ERROR apprise/url.py:536:17-25: Unpacked keyword argument `bool` is not assignable to parameter `string` with type `Buffer | None` in function `_hashlib.openssl_sha256` [bad-argument-type]
- ERROR apprise/url.py:543:17-25: Unpacked keyword argument `bool` is not assignable to parameter `string` with type `Buffer | None` in function `_hashlib.openssl_sha256` [bad-argument-type]

trio (https://github.com/python-trio/trio)
- ERROR src/trio/_path.py:133:32-35: Argument `type[PosixPath] | type[WindowsPath] | type[Self@Path]` is not assignable to parameter `cls` with type `type[Self@Path]` in function `pathlib.PurePath.__new__` [bad-argument-type]
+ ERROR src/trio/_path.py:133:32-35: Argument `type[PosixPath] | type[Self@Path]` is not assignable to parameter `cls` with type `type[Self@Path]` in function `pathlib.PurePath.__new__` [bad-argument-type]

AutoSplit (https://github.com/Toufool/AutoSplit)
- ERROR src/utils.py:349:28-36: Could not find name `platform` [unknown-name]

@yangdanny97 yangdanny97 self-assigned this Jul 23, 2026
@meta-codesync

meta-codesync Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

@yangdanny97 has imported this pull request. If you are a Meta employee, you can view this in D113349444.

@stroxler stroxler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

@meta-codesync meta-codesync Bot closed this in 57e7455 Jul 23, 2026
@meta-codesync meta-codesync Bot added the Merged label Jul 23, 2026
@meta-codesync

meta-codesync Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

@yangdanny97 merged this pull request in 57e7455.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support platform-specific stdlib attribute evaluation in ternary expressions

3 participants