pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

False "code is unreachable"

Open HaCStudio opened this issue 5 years ago • 9 comments

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.

HaCStudio avatar Dec 31 '20 14:12 HaCStudio

Please refer to https://github.com/microsoft/pylance-release/issues/470

erictraut avatar Dec 31 '20 14:12 erictraut

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

HaCStudio avatar Dec 31 '20 15:12 HaCStudio

@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

HaCStudio avatar Jan 04 '21 14:01 HaCStudio

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 avatar Jan 04 '21 15:01 erictraut

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.

erictraut avatar Jan 04 '21 15:01 erictraut

@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.

HaCStudio avatar Jan 04 '21 15:01 HaCStudio

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

erictraut avatar Jan 04 '21 16:01 erictraut

Ok got it. Thank you very much!

HaCStudio avatar Jan 04 '21 22:01 HaCStudio

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

jakebailey avatar Jan 06 '21 23:01 jakebailey