microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.72k stars 766 forks source link

Inconsistent highlighting #6638

Open johndoknjas opened 1 week ago

johndoknjas commented 1 week ago

Does this issue occur when all extensions are disabled?: Yes/No

Steps to Reproduce:

In the code below, the argv in sys.argv isn't highlighted in the first function. This seems to be because vscode infers that the condition (if args is None) should never be true, due to the previous line. I'm not sure if this is intended behaviour though, because in the second function, sys.argv is highlighted, despite it being more obvious that the condition should never be true.

Image

import sys
from typing import Optional
from copy import copy

def first(args: Optional[list[str]]) -> None:
    args = copy(sys.argv)
    print(sys.argv if args is None else args)

def second(args: Optional[list[str]]) -> None:
    print(sys.argv if sys.argv is None else args)
alexr00 commented 1 week ago

Could you please share a copy/pastable example that I can use to repro with?

johndoknjas commented 1 week ago

@alexr00 Sure, here it is:

import sys
from typing import Optional
from copy import copy

def first(args: Optional[list[str]]) -> None:
    args = copy(sys.argv)
    print(sys.argv if args is None else args)

def second(args: Optional[list[str]]) -> None:
    print(sys.argv if sys.argv is None else args)
alexr00 commented 1 week ago

Thanks! I can't repro without the python extension. Moving to the appropriate repo.