Skip to content

fix(stubgen): emit instance attrs assigned in __init__#3209

Open
tobyh-canva wants to merge 1 commit intofacebook:mainfrom
tobyh-canva:fix/stubgen-instance-attrs-from-init
Open

fix(stubgen): emit instance attrs assigned in __init__#3209
tobyh-canva wants to merge 1 commit intofacebook:mainfrom
tobyh-canva:fix/stubgen-instance-attrs-from-init

Conversation

@tobyh-canva
Copy link
Copy Markdown

Summary

Fixes facebook/pyrefly#3208: .pyi stubgen omitted instance attributes that are only set in __init__ (e.g. self.name = name) when there is no class-level annotation.

Approach

After building the class stub body, resolve the class def index, consult KeyClassField / instance ClassField answers, and emit name: T lines for simple instance attributes. New lines are inserted before __init__ when present so attributes stay before methods.

Test

Made with Cursor

Stubgen only surfaced class-level assignments, so self.name = ... in
__init__ produced no name: T in .pyi files (github.com/facebook/issues/3208).

After extracting the class body, resolve the class def index, walk class field
metadata, and for instance-only ClassField answers emit typed variables. Insert
those before __init__ when present so attribute lines stay before methods, and
add a regression test.

Made-with: Cursor
@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented Apr 23, 2026

Hi @tobyh-canva!

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!

@tobyh-canva tobyh-canva changed the title fix(stubgen): emit instance attrs assigned in __init__ fix(stubgen): emit instance attrs assigned in __init__ Apr 23, 2026
@tobyh-canva tobyh-canva marked this pull request as ready for review April 23, 2026 13:03
@kinto0 kinto0 self-assigned this Apr 24, 2026
@kinto0
Copy link
Copy Markdown
Contributor

kinto0 commented Apr 24, 2026

thank you for filing the issue and for the PR! looks like you still need to sign the CLA, but once you do that I can get this imported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(stubgen): instance variables defined in __init__ method are missing from generated stubs

2 participants