Skip to content

Conversation

@fangyi-zhou
Copy link
Contributor

Summary

When a constructor is converted as a callable, we should take care of any type annotation on the self when setting the return type of the callable.

In particular, the spec says that https://typing.python.org/en/latest/spec/constructors.html#init-method

To enable this, type checkers should allow the self parameter to be annotated with a type that influences the resulting type of the constructor call.

This diff uses the self parameter type to set the return type of the callable to implement this requirement.

NOTE: In the conformance test, the callbable converted from constructor is passed around an identical function that causes overload handing to be incorrect. Therefore, this fix does not fix the conformance test in full.

Help needed: There's a regression on dataclasses_transform_converter conformance test, but I'm unable to make sense of the error. I suspect this is due to some mishandling of generics.

Next step: Handle generics correctly when converting constructor into a callable.

Test Plan

test.py

@meta-cla meta-cla bot added the cla signed label Jan 25, 2026
@github-actions
Copy link

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@migeed-z
Copy link
Contributor

I will take a look!

@meta-codesync
Copy link

meta-codesync bot commented Jan 27, 2026

@migeed-z has imported this pull request. If you are a Meta employee, you can view this in D91549854.

@migeed-z migeed-z self-assigned this Jan 27, 2026
Copy link
Contributor

@stroxler stroxler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

fangyi-zhou added a commit to fangyi-zhou/pyrefly that referenced this pull request Jan 27, 2026
Resolves facebook#2226

Previously, the LSP code completion for overload only shows the
closest match. Now it should all overloads that are potentially
matching.

---

LLM provided summary:

Previously, add_kwargs_completions only showed parameters from the
single closest-matching overload. Now it shows parameters from all
overloads when no arguments have been provided yet, and narrows to the
closest match once arguments disambiguate.

Also changes get_callables_from_call to return Option<usize> for the
overload index, distinguishing a matched overload from no match.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@meta-codesync meta-codesync bot closed this in 5f3e71f Jan 27, 2026
@meta-codesync
Copy link

meta-codesync bot commented Jan 27, 2026

@migeed-z merged this pull request in 5f3e71f.

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.

4 participants