Skip to content

feat: let ProxyMethod resolve callable attribute targets - #4915

Open
yeetypete wants to merge 3 commits into
facebook:mainfrom
yeetypete:proxy-method-callable-attribute-target
Open

feat: let ProxyMethod resolve callable attribute targets#4915
yeetypete wants to merge 3 commits into
facebook:mainfrom
yeetypete:proxy-method-callable-attribute-target

Conversation

@yeetypete

Copy link
Copy Markdown
Contributor

Summary

Let ProxyMethod resolve a target declared as a class attribute, in addition to an ordinary instance method. A target is accepted whenever pyrefly can call it: Callable[...] annotations, callback protocols, and type[X] constructors all work but non-callable targets such as forward: int are still rejected.

This lets the shape stubs declare nn.Module.forward as Callable[..., Any], matching PyTorch:

https://github.com/pytorch/pytorch/blob/d6c03540dc0f040e1d8a920d19d9333de6513545/torch/nn/modules/module.py#L526

The stubs previously declared forward as a method because that was the only target ProxyMethod could resolve. Under strict-callable-subtyping, a method-form forward(*args, **kwargs) makes every concrete forward(self, x) override a bad-override.

Test Plan

Run test.py.

@meta-cla meta-cla Bot added the cla signed label Sep 12, 2026
@yeetypete yeetypete changed the title Proxy method callable attribute target feat: let ProxyMethod resolve callable attribute targets Sep 12, 2026
@meta-codesync

meta-codesync Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D119805915. (Because this pull request was imported automatically, there will not be any future comments.)

@github-actions

Copy link
Copy Markdown

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

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.

1 participant