Respect platform guards in conditional expressions#4232
Closed
goutamadwant wants to merge 1 commit into
Closed
Conversation
|
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]
|
Contributor
|
@yangdanny97 has imported this pull request. If you are a Meta employee, you can view this in D113349444. |
stroxler
approved these changes
Jul 23, 2026
stroxler
left a comment
Contributor
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
Contributor
|
@yangdanny97 merged this pull request in 57e7455. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 -- --nocapturecargo test -p pyrefly test_context_if_expr_unreachable -- --nocapturepython3 test.py(Scrut tests skipped because Scrut is not installed)AI disclosure: AI was used to review the code and understanding the codebase.