fix(stubgen): emit instance attrs assigned in __init__#3209
fix(stubgen): emit instance attrs assigned in __init__#3209tobyh-canva wants to merge 1 commit intofacebook:mainfrom
__init__#3209Conversation
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
|
Hi @tobyh-canva! 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! |
__init__
|
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 |
Summary
Fixes facebook/pyrefly#3208:
.pyistubgen 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/ instanceClassFieldanswers, and emitname: Tlines for simple instance attributes. New lines are inserted before__init__when present so attributes stay before methods.Test
test_stubgen_instance_fields_from_initcovers the bug(stubgen): instance variables defined in__init__method are missing from generated stubs #3208 example.Made with Cursor