Skip to content

Prefer specific overloads over object fallbacks - #4532

Closed
ting-hong-shieh wants to merge 1 commit into
facebook:mainfrom
ting-hong-shieh:codex/fix-pyrefly-3977
Closed

Prefer specific overloads over object fallbacks#4532
ting-hong-shieh wants to merge 1 commit into
facebook:mainfrom
ting-hong-shieh:codex/fix-pyrefly-3977

Conversation

@ting-hong-shieh

Copy link
Copy Markdown

Summary

When an argument contains a nested Any, overload materialization can leave both a specific overload and a later object fallback in the candidate set. If their return types differ, Pyrefly then falls back to Unknown.

In the default, non-spec-compliant overload mode, skip materialization when the remaining parameter differences consist only of later object fallbacks. This matches mypy and pyright for the reported bounded-TypeVar case.

Top-level Any remains ambiguous, and spec-compliant overload behavior is unchanged.

Fixes #3977

Test Plan

  • cargo test -p pyrefly --lib test::overload:: -- --test-threads=1
  • cargo test -p pyrefly --lib test::operators:: -- --test-threads=1
  • python3 test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema
  • Verified that the issue reproduction now infers Array[tuple[Any, ...], bool] instead of Unknown.

AI assistance disclosure: I used Codex to inspect the overload-resolution path, implement the change, draft the regression tests, and prepare this description. I reviewed the diff and ran the tests locally.

@meta-cla

meta-cla Bot commented Aug 13, 2026

Copy link
Copy Markdown

Hi @ting-hong-shieh!

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 cla@meta.com. Thanks!

@ting-hong-shieh

Copy link
Copy Markdown
Author

Superseded by #4533, which contains the updated implementation and regression coverage. Closing this draft to keep the review in one place.

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.

Overloaded method with TypeVar(bound=tuple[int, ...]) resolves to Unknown when object fallback overload is present

1 participant