Skip to content
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

False "code is unreachable" #794

Closed
hilayc opened this issue Dec 31, 2020 · 9 comments
Closed

False "code is unreachable" #794

hilayc opened this issue Dec 31, 2020 · 9 comments
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@hilayc
Copy link

hilayc commented Dec 31, 2020

When you write a python code like the following:

if sys.platform == 'win32':
    #some code here
else:
    # some other code

It marks the code as "unreachable" depends on whether you are writing in Linux or Windows.
I believe the warning shouldn't appear on that case.

@erictraut
Copy link
Contributor

Please refer to #470

@hilayc
Copy link
Author

hilayc commented Dec 31, 2020

Sorry, I tried looking for "sys.platform" and I didn't search for "os.name".

@hilayc hilayc closed this as completed Dec 31, 2020
@hilayc
Copy link
Author

hilayc commented Jan 4, 2021

@erictraut I tried it and I don't find it as a good solution.
I can understand from your comment on #470 that this is intended but consider it as a feature request.
When I used {"pythonPlatform": "All"} it just swaps the unreachable part between the 'if' and 'else' statements.

Please make another option for "Any" so the sys.os / sys.platform won't show a warning, it is very confusing since the code works as I expect it and I just need to ignore this warning.

Would be appreciated.
Thank you

@erictraut
Copy link
Contributor

You won't see a warning for unreachable code. You will simply see that some code is "grayed out". If you're seeing a warning, then something else is wrong, and we should investigate that.

@erictraut
Copy link
Contributor

I've changed "pythonPlatform" to accept a value of "All". When it receives this configuration value (or any other string value that it doesn't understand), it will assume that all platforms are supported. So that should eliminate the "grayed out" code in this case. If you are seeing an actual warning, please let me know because that shouldn't happen.

@hilayc
Copy link
Author

hilayc commented Jan 4, 2021

@erictraut by warning I mean grayed out, there isn't an actual warning of course.
I'm experiencing something different than your description.
This is what I get when I use "All"
image

This is the json configuration file

{
	"pythonPlatform": "All"
}

I'm running from windows.

@erictraut
Copy link
Contributor

Yeah, I just checked in the change for "All". You won't see the updated behavior until the next release of pylance.

@hilayc
Copy link
Author

hilayc commented Jan 4, 2021

Ok got it. Thank you very much!

@jakebailey jakebailey added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Jan 6, 2021
@jakebailey jakebailey reopened this Jan 6, 2021
@github-actions github-actions bot removed the triage label Jan 6, 2021
@jakebailey
Copy link
Member

The above change is in 2021.1.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202110-6-january-2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants