Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Open
tobyh-canva wants to merge 4 commits intofacebook:mainfacebook/pyrefly:mainfrom
tobyh-canva:fix/stubgen-instance-attrs-from-inittobyh-canva/pyrefly:fix/stubgen-instance-attrs-from-initCopy head branch name to clipboard
Open

fix(stubgen): emit instance attrs assigned in __init__#3209
tobyh-canva wants to merge 4 commits intofacebook:mainfacebook/pyrefly:mainfrom
tobyh-canva:fix/stubgen-instance-attrs-from-inittobyh-canva/pyrefly:fix/stubgen-instance-attrs-from-initCopy head branch name to clipboard

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

@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

@tobyh-canva
Copy link
Copy Markdown
Author

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 😅

@tobyh-canva tobyh-canva force-pushed the fix/stubgen-instance-attrs-from-init branch from f4d916d to eb44322 Compare April 29, 2026 22:53
@github-actions github-actions Bot added size/m and removed size/m labels Apr 29, 2026
@tobyh-canva tobyh-canva force-pushed the fix/stubgen-instance-attrs-from-init branch from eb44322 to bb3144a Compare May 1, 2026 02:19
@github-actions github-actions Bot added size/m and removed size/m labels May 1, 2026
@tobyh-canva tobyh-canva force-pushed the fix/stubgen-instance-attrs-from-init branch from bb3144a to ff00bf7 Compare May 4, 2026 10:19
@github-actions github-actions Bot added size/m and removed size/m labels May 4, 2026
@kinto0
Copy link
Copy Markdown
Contributor

kinto0 commented May 4, 2026

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?

@tobyh-canva
Copy link
Copy Markdown
Author

tobyh-canva commented May 4, 2026

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.

@tobyh-canva tobyh-canva force-pushed the fix/stubgen-instance-attrs-from-init branch from ff00bf7 to 40a8053 Compare May 4, 2026 22:07
@meta-cla meta-cla Bot added the cla signed label May 4, 2026
@github-actions github-actions Bot added size/m and removed size/m labels May 4, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented May 6, 2026

@kinto0 has imported this pull request. If you are a Meta employee, you can view this in D104061069.

Copy link
Copy Markdown
Contributor

@kinto0 kinto0 left a comment

Choose a reason for hiding this comment

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

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.

image image image image

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

@tobyh-canva
Copy link
Copy Markdown
Author

tobyh-canva commented May 6, 2026

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 😂 😭

tobyh-canva and others added 2 commits May 7, 2026 09:42
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>
@tobyh-canva tobyh-canva force-pushed the fix/stubgen-instance-attrs-from-init branch from 40a8053 to 522bf7b Compare May 6, 2026 23:43
@github-actions github-actions Bot added size/l and removed size/m labels May 6, 2026
@github-actions github-actions Bot added size/l and removed size/l labels May 6, 2026
Document and test deterministic name ordering; update Cargo.lock.

Co-authored-by: Cursor <cursoragent@cursor.com>
@tobyh-canva tobyh-canva force-pushed the fix/stubgen-instance-attrs-from-init branch from 7980198 to 4d2d653 Compare May 6, 2026 23:55
@github-actions github-actions Bot added size/l and removed size/l labels May 6, 2026
@github-actions

This comment has been minimized.

Comment thread pyrefly/lib/binding/bindings.rs
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>
@github-actions github-actions Bot added size/l and removed size/l labels May 8, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

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.

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

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.