Skip to content

Mark code after breakless statically true loops as unreachable - #5324

Open
asukaminato0721 wants to merge 1 commit into
facebook:mainfrom
asukaminato0721:fix-breakless-while-reachability
Open

asukaminato0721 wants to merge 1 commit into
facebook:mainfrom
asukaminato0721:fix-breakless-while-reachability

Conversation

@asukaminato0721

@asukaminato0721 asukaminato0721 commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Code after a statically true loop without a break is unreachable. Record flow termination after these loops, including retry loops that can exit only through return or an exception.

Preserve exception termination so an enclosing context manager can suppress it. Keep environment-dependent loop conditions from producing unreachable warnings in code that can execute in another Python environment.

This changes the default-enabled unreachable-code diagnostic. It is independent of the attribute initialization check in #4326. Direct tests cover retry loops, infinite loops, environment-dependent conditions, and suppressed exceptions.

  • I am a human, and I fully understand the code I am submitting.

Test Plan

  • 532 related tests passed, including scope, loops, branching, returns, delayed inference, hover, and ParamSpec retry coverage.
  • Formatting and lint checks passed. Clippy reports existing warnings in unchanged code.

@meta-codesync

meta-codesync Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D126824565. (Because this pull request was imported automatically, there will not be any future comments.)

@github-actions

Copy link
Copy Markdown

Diff from mypy_primer, showing the effect of this PR on open source code:

============================================================
SUMMARY
============================================================
Total: +5 new errors, -2 fixed errors
By preset: +5/-2 (default), +5/-2 (strict)

Projects with changes (4):
  psycopg: +2 -0
  manticore: +1 -2
  poetry: +1 -0
  cvxpy: +1 -0
============================================================

FULL DIFF DETAILS
------------------------------------------------------------

psycopg (https://github.com/psycopg/psycopg)
+ ERROR psycopg/psycopg/types/multirange.py:333:9-19: This code is unreachable [unreachable]
+ ERROR tests/pq/test_pgconn.py:44:5-46:61: This code is unreachable [unreachable]

manticore (https://github.com/trailofbits/manticore)
+ ERROR tests/auto_generators/trace.py:174:1-46: This code is unreachable [unreachable]
- ERROR tests/ethereum/test_general.py:1723:26-32: `result` may be uninitialized [unbound-name]
- ERROR tests/ethereum/test_general.py:1779:26-32: `result` may be uninitialized [unbound-name]

poetry (https://github.com/python-poetry/poetry)
+ ERROR src/poetry/utils/authenticator.py:301:9-74: This code is unreachable [unreachable]

cvxpy (https://github.com/cvxpy/cvxpy)
+ ERROR cvxpy/utilities/power_tools.py:610:5-69: This code is unreachable [unreachable]

This branch has not been deployed

No deployments
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.

1 participant