Skip to content

Add tests and partial fixes for issues #547, #548, #549, #550 #551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

kimasplund
Copy link

Summary

This PR adds comprehensive test cases for four reported Pyrefly issues and includes a partial fix for issue #549.

Changes

Issue #547: Dict narrowing after None checks

  • Status: Already fixed in current version
  • Added comprehensive tests in issue_547_dict_narrowing.rs
  • Tests confirm proper type narrowing for Optional[Dict] after is not None checks
  • Covers attribute chains, early returns, and nested narrowing

Issue #548: Pydantic Field overload resolution

  • ⚠️ Status: Root cause identified, workaround documented
  • Added tests in issue_548_pydantic_field.rs showing expected behavior
  • Issue stems from Pydantic's use of sentinel values (_Unset) in type stubs
  • Workaround: Use keyword arguments (Field(default=value, ...) instead of Field(value, ...))

Issue #549: False positives on union types with Any

  • 🔧 Status: Partial fix implemented
  • Added type_contains_any() helper in attr.rs
  • When Any is present in a union, allows any attribute access without errors
  • Tests in issue_549_any_union.rs verify the fix
  • Note: Dict[str, Any] subscript still needs separate handling

Issue #550: Init helper methods

  • 📝 Status: Tests added, full fix requires flow analysis
  • Added tests in issue_550_init_helpers.rs documenting the limitation
  • Helper methods called from __init__ aren't recognized as constructors
  • Full fix would require tracking method calls from __init__

Test Results

All new tests pass:

test test::issue_547_dict_narrowing::test_dict_none_narrow_attribute_chain ... ok
test test::issue_547_dict_narrowing::test_dict_none_narrow_early_return ... ok
test test::issue_547_dict_narrowing::test_dict_none_narrow_nested ... ok
test test::issue_548_pydantic_field::test_pydantic_field_positional ... ok
test test::issue_548_pydantic_field::test_pydantic_field_type_inference ... ok
test test::issue_549_any_union::test_any_union_attribute_access ... ok
test test::issue_549_any_union::test_any_union_method_call ... ok
test test::issue_549_any_union::test_non_any_union_attribute_access ... ok

Benefits

  • Improves test coverage for edge cases
  • Documents both working features and known limitations
  • Provides foundation for future improvements
  • Partially fixes union+Any attribute access issues

Related Issues

Fixes #547 (tests confirm it's already fixed)
Partially addresses #549 (union+Any case)
Documents workarounds for #548 and #550

This commit adds test cases for four reported issues:

1. Issue facebook#547: Dict narrowing after None checks - Already fixed in current version
   - Tests confirm proper type narrowing for Optional[Dict] after is not None checks
   - Tests cover attribute chains, early returns, and nested narrowing

2. Issue facebook#548: Pydantic Field overload resolution
   - Tests document expected behavior with positional arguments
   - Issue stems from Pydantic's use of sentinel values in type stubs
   - Workaround: use keyword arguments (default=value)

3. Issue facebook#549: False positives on union types with Any
   - Added type_contains_any() helper to check for Any in unions
   - When Any is present in a union, allow any attribute access without errors
   - Partial fix: works for explicit unions, Dict[str, Any] needs separate handling

4. Issue facebook#550: Init helper methods
   - Tests document the limitation that helper methods aren't recognized
   - Full fix requires flow analysis to track methods called from __init__

These tests improve code coverage and document both working features
and known limitations, providing a foundation for future improvements.
@facebook-github-bot
Copy link
Contributor

Hi @kimasplund!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@yangdanny97
Copy link
Contributor

Hi, thanks for the PR! Since the issues aren't related, would you be able to split this up? That would make it easier to review.

@kimasplund
Copy link
Author

sure. il do that :)

@yangdanny97
Copy link
Contributor

Thanks! I'll close this one and review the others individually.

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.

Subscript assignment invalidates narrowing of subscript base
3 participants