Prefer specific overloads over object fallbacks - #4532
Conversation
|
Hi @ting-hong-shieh! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Superseded by #4533, which contains the updated implementation and regression coverage. Closing this draft to keep the review in one place. |
Summary
When an argument contains a nested
Any, overload materialization can leave both a specific overload and a laterobjectfallback in the candidate set. If their return types differ, Pyrefly then falls back toUnknown.In the default, non-spec-compliant overload mode, skip materialization when the remaining parameter differences consist only of later
objectfallbacks. This matches mypy and pyright for the reported bounded-TypeVar case.Top-level
Anyremains ambiguous, and spec-compliant overload behavior is unchanged.Fixes #3977
Test Plan
cargo test -p pyrefly --lib test::overload:: -- --test-threads=1cargo test -p pyrefly --lib test::operators:: -- --test-threads=1python3 test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschemaArray[tuple[Any, ...], bool]instead ofUnknown.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.