Skip to content

fix(stubgen): extract statements from try blocks and expand TYPE_CHECKING recognition#4143

Closed
tobyh-canva wants to merge 1 commit into
facebook:mainfrom
tobyh-canva:fix-3888-type-checking-try-except
Closed

fix(stubgen): extract statements from try blocks and expand TYPE_CHECKING recognition#4143
tobyh-canva wants to merge 1 commit into
facebook:mainfrom
tobyh-canva:fix-3888-type-checking-try-except

Conversation

@tobyh-canva

@tobyh-canva tobyh-canva commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

Updates stubgen to address two of the three limitations identified in #3888:

  • TYPE_CHECKING guards which are part of a larger boolean expression, e.g. if TYPE_CHECKING or not USE_EXTENSIONS, should have statements extracted.
  • Statements in try blocks should be extracted.

Works towards fixing #3888.

I'd prefer to handle the third limitation (sys conditionals) in a separate PR, as it's considerably more complex.

Test Plan

  • Added snapshot tests for stubgen demonstrating the desired behavioural changes
  • python3 test.py

@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. ✅

@meta-codesync

meta-codesync Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

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

@kinto0 kinto0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

@meta-codesync meta-codesync Bot closed this in 41727d4 Jul 16, 2026
@meta-codesync meta-codesync Bot added the Merged label Jul 16, 2026
@meta-codesync

meta-codesync Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

@yangdanny97 merged this pull request in 41727d4.

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.

3 participants