Skip to content

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

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

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
Contributor

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.

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.

2 participants