Skip attribute suggestions for partial union failures#2149
Closed
sgavriil01 wants to merge 1 commit intofacebook:mainfrom
Closed
Skip attribute suggestions for partial union failures#2149sgavriil01 wants to merge 1 commit intofacebook:mainfrom
sgavriil01 wants to merge 1 commit intofacebook:mainfrom
Conversation
When an attribute exists on some union members but not others, skip suggestions to avoid misleading guidance. For example, x.split() on str | None should not suggest rsplit since it also doesn't exist on None. Fixes facebook#2108
|
@grievejia has imported this pull request. If you are a Meta employee, you can view this in D91089458. |
yangdanny97
approved these changes
Jan 21, 2026
Contributor
yangdanny97
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
samwgoldman
requested changes
Jan 21, 2026
Member
samwgoldman
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
samwgoldman
approved these changes
Jan 21, 2026
Member
samwgoldman
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
rchen152
approved these changes
Jan 21, 2026
Contributor
rchen152
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
|
@grievejia merged this pull request in 9faa964. |
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.
When an attribute exists on some union members but not others, skip suggestions to avoid misleading guidance. For example, x.split() on str | None should not suggest rsplit since it also doesn't exist on None.
Fixes #2108
Summary
Modified
type_of_attr_getinpyrefly/lib/alt/attr.rsto detect partial union failures (where an attribute exists on some union members but not others) and skip suggestions in those cases. This prevents misleading suggestions like recommendingrsplitwhensplitfails onstr | None.The fix checks if
foundandnot_foundare both non-empty before suggesting, indicating the attribute exists on some union members but not all.Suggestions still work correctly when the attribute is missing on all union members or when there's no union involved.
Test Plan
Added 5 comprehensive test cases in
pyrefly/lib/test/attributes.rs:test_union_attribute_missing_no_suggestion- Core fix (str | None)test_union_attribute_missing_no_suggestion_three_types- Three-type uniontest_union_attribute_missing_no_suggestion_mostly_have_it- Two have it, one doesn'ttest_union_both_missing_should_suggest- All missing (should still suggest)test_union_all_have_attribute_no_error- All have it (no error)All tests pass (
cargo test test_union). Manually verified with release build that the fix works as expected.