You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added reportUnreachable diagnostic check. If enabled, it emits a diagnostic for code that is determined to be structurally unreachable or unreachable via type analysis. It does not report code that is within a code block that is gated by a conditional that is statically determined to be false, such as TYPE_CHECKING and version checks. This diagnostic check is off by default even in strict mode because there are legitimate reasons for unreachable code to exist in Python code. (#10581)
This change also modifies the messages that accompany tagged hints (the mechanism by which unreachable or unanalyzed code is displayed as "dimmed" in an editor). The message now distinguishes between code that is structurally unreachable (e.g. after a `return` or `raise` statement) and code that is not analyzed because it is in a conditional block that is statically evaluated as false.
This addresses #10284.
Copy file name to clipboardExpand all lines: docs/configuration.md
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,7 +58,7 @@ The following settings determine how different types should be evaluated.
58
58
59
59
- <aname="deprecateTypingAliases"></a> **deprecateTypingAliases**[boolean]: PEP 585 indicates that aliases to types in standard collections that were introduced solely to support generics are deprecated as of Python 3.9. This switch controls whether these are treated as deprecated. This applies only when pythonVersion is 3.9 or newer. The default value for this setting is `false` but may be switched to `true` in the future.
60
60
61
-
- <aname="enableReachabilityAnalysis"></a> **enableReachabilityAnalysis**[boolean]: If enabled, code that is determined to be unreachable by type analysis is reported using a tagged hint. This setting does not affect code that is determined to be unreachable regardless of type analysis; such code is always reported as unreachable. This setting also has no effect when using the command-line version of pyright because it never emits tagged hints for unreachable code.
61
+
- <aname="enableReachabilityAnalysis"></a> **enableReachabilityAnalysis**[boolean]: If enabled, code that is determined to be unreachable by type analysis is reported using a tagged hint. This setting does not affect code that is determined to be unreachable independent of type analysis; such code is always reported as unreachable using a tagged hint. This setting also has no effect when using the command-line version of pyright because it never emits tagged hints for unreachable code.
62
62
63
63
- <aname="enableExperimentalFeatures"></a> **enableExperimentalFeatures**[boolean]: Enables a set of experimental (mostly undocumented) features that correspond to proposed or exploratory changes to the Python typing standard. These features will likely change or be removed, so they should not be used except for experimentation purposes. The default value for this setting is `false`.
64
64
@@ -233,6 +233,8 @@ The following settings allow more fine grained control over the **typeCheckingMo
233
233
234
234
- <aname="reportMatchNotExhaustive"></a> **reportMatchNotExhaustive**[boolean or string, optional]: Generate or suppress diagnostics for a `match` statement that does not provide cases that exhaustively match against all potential types of the target expression. The default value for this setting is `"none"`.
235
235
236
+
- <aname="reportUnreachable"></a> **reportUnreachable**[boolean or string, optional]: Generate or suppress diagnostics for code that is determined to be structurally unreachable or unreachable by type analysis. The default value for this setting is `"none"`.
237
+
236
238
- <aname="reportImplicitOverride"></a> **reportImplicitOverride**[boolean or string, optional]: Generate or suppress diagnostics for overridden methods in a class that are missing an explicit `@override` decorator. The default value for this setting is `"none"`.
237
239
238
240
- <aname="reportShadowedImports"></a> **reportShadowedImports**[boolean or string, optional]: Generate or suppress diagnostics for files that are overriding a module in the stdlib. The default value for this setting is `"none"`.
@@ -439,6 +441,7 @@ The following table lists the default severity levels for each diagnostic rule w
Copy file name to clipboardExpand all lines: docs/type-concepts-advanced.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -601,9 +601,9 @@ If one of these conditional expressions evaluates statically to false, pyright d
601
601
602
602
603
603
### Reachability
604
-
Pyright performs “reachability analysis” to determine whether statements will be executed at runtime.
604
+
Pyright performs “reachability analysis” to determine whether statements will be executed at runtime and whether it should analyze and report errors in code.
605
605
606
-
Reachability analysis is based on both non-type and type information. Non-type information includes statements that unconditionally affect code flow such as `continue`, `raise` and `return`. It also includes conditional statements (`if`, `elif`, or `while`) where the conditional expression is one of these [supported expression forms](type-concepts-advanced#static-conditional-evaluation). Type analysis is not performed on code determined to be unreachable using non-type information. Therefore, language server features like completion suggestions are not available for this code.
606
+
Reachability analysis is based on both non-type and type information. Non-type information includes statements that affect code structure such as `continue`, `raise` and `return`. It also includes conditional statements (`if`, `elif`, or `while`) where the conditional expression is one of these [supported expression forms](type-concepts-advanced#static-conditional-evaluation). Type analysis is not performed on code determined to be unreachable using non-type information. Therefore, language server features like completion suggestions are not available for this code.
607
607
608
608
Here are some examples of code determined to be unreachable using non-type information.
0 commit comments