microsoft / pylance-release

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

Inconsistent highlighting #6638

Open johndoknjas opened 4 weeks ago

johndoknjas commented 4 weeks 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 4 weeks ago

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

johndoknjas commented 4 weeks 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 3 weeks ago

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

KacieKK commented 2 weeks ago

I can reproduce this issue using pylance 2024.11.100