fix(stubgen): emit instance attrs assigned in __init__#3209
fix(stubgen): emit instance attrs assigned in __init__#3209tobyh-canva wants to merge 4 commits intofacebook:mainfrom
__init__#3209Conversation
|
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 |
|
Thanks, I've reached out to Canva's point of contact for the Meta CLA, hopefully I'll be added to our corporate CLA soon 😅 |
f4d916d to
eb44322
Compare
eb44322 to
bb3144a
Compare
bb3144a to
ff00bf7
Compare
|
still no luck on the CLA, right? it looks like the signal is still red but I see you pushing code. maybe it's an issue on my end? |
|
Hi @kinto0, yeah my colleague at Canva georgnaro@canva.com reached out to cla@meta.com last Tuesday to get me added to the corporate CLA, but hasn't heard back. I've just been rebasing to trigger the check in case I've been added yet. Are you able to check internally at Meta? 🙏 In the meantime I'll sign the individual CLA to try and unblock this bugfix. |
ff00bf7 to
40a8053
Compare
|
@kinto0 has imported this pull request. If you are a Meta employee, you can view this in D104061069. |
There was a problem hiding this comment.
looks like the CLA went through, thanks!! changes look great, now your next PRs should be easy without needing a CLA
there's some bug in github leaving a review. I've tried submitting my review a few times over the last 20 mins. instead I will comment it here - sorry.
they're all fairly small and it's annoying with this bug. I can just fix these up on import for you unless you feel strongly
|
Thanks for the review! I'll get these fixed up. And no need to apologise about the GitHub bug, I understand completely, and I'm unfortunately very familiar with this experience 😂 😭 |
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
Move StmtClassDef → ClassDefIndex resolution onto Bindings so stubgen does not duplicate key lookup. Use splice when inserting synthesized instance fields, borrow class-level stub names for deduping, and add a test that documents the desired assignment-order layout for __init__-derived attrs (currently sorted). Co-authored-by: Cursor <cursoragent@cursor.com>
40a8053 to
522bf7b
Compare
Document and test deterministic name ordering; update Cargo.lock. Co-authored-by: Cursor <cursoragent@cursor.com>
7980198 to
4d2d653
Compare
This comment has been minimized.
This comment has been minimized.
Removed unused imports and streamlined the process of obtaining class definition indices from bindings. This change enhances code clarity and reduces redundancy in the server's implementation. Co-authored-by: Cursor <cursoragent@cursor.com>
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
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