-
Notifications
You must be signed in to change notification settings - Fork 768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Code is unreachable #6028
Comments
Reachability checks are based on type analysis. The Based on the behavior of the code, it looks like the function also accepts values of type def load_json(obj: str | list | dict) -> list | dict:
if isinstance(obj, str):
obj = json.loads(obj)
return load_json(obj)
return obj |
@erictraut in my particular case I have a stringified json object that can have multiple levels of "stringification" and will, eventually, return a list or a dict. so it is a string until it's not that is why my Anyways, your solution works as well, thanks! |
@mfeyx see this issue. might help with typing. python/typing#182 (comment) |
…e was not supported for `if` or `else` suites when the condition type was narrowed to `Never`. This addresses microsoft/pylance-release#6028.
…e was not supported for `if` or `else` suites when the condition type was narrowed to `Never`. This addresses microsoft/pylance-release#6028.
…e was not supported for `if` or `else` suites when the condition type was narrowed to `Never`. This addresses microsoft/pylance-release#6028.
@mfeyx, I took a closer look at this issue because of the inconsistency you pointed out in your bug report between the code that uses an |
…e was not supported for `if` or `else` suites when the condition type was narrowed to `Never`. This addresses microsoft/pylance-release#6028. (#8190)
Thanks Eric. I will keep this issue open until Pylance releases the fix. |
This issue has been fixed in prerelease version 2024.6.102, which we've just released. You can find the changelog here: CHANGELOG.md |
…able code was not supported for `if` or `else` suites when the condition type was narrowed to `Never`. This addresses microsoft/pylance-release#6028. (#8190)" This reverts commit b841e11.
…able code was not supported for `if` or `else` suites when the condition type was narrowed to `Never`. This addresses microsoft/pylance-release#6028. (#8190)" This reverts commit b841e11.
Hi there,
Sometimes Pylance states that my "Code is unreachable" even though the code works as expected. For instance, if I use an
if
-statement without anelse
. If I add the else statement the code is "reachable" and not greyed out. (Please find the examples below).In my understanding the additional
else
is not neccessary and "bad" practice, if you will.Environment data
python
Python version 3.10.9.final.0 (and others)
vs code
Version: 1.90.1 (system setup)
Commit: 611f9bfce64f25108829dd295f54a6894e87339d
Date: 2024-06-11T21:01:24.262Z
Electron: 29.4.0
ElectronBuildId: 9593362
Chromium: 122.0.6261.156
Node.js: 20.9.0
V8: 12.2.281.27-electron.0
OS: Windows_NT x64 10.0.19045
pylance
v2024.6.1
(Client) Pylance async client (2024.6.1) started with python extension (2024.8.1)
Pylance language server 2024.6.1 (pyright version 1.1.364, commit 0618acc5) starting
Published
2020-06-30, 22:05:55
Last released
2024-06-14, 02:25:45
Last updated
2024-06-07, 09:08:27
Identifier
ms-python.vscode-pylance
Code Snippet
"Code is unreachable"
Code is reachable
Repro Steps
The text was updated successfully, but these errors were encountered: