Vince M
Vince M

Reputation: 1196

Python VsCode: Green highlight on class not working

I have the following python code:

from typing import List


class User:
    id: str
    name: str

    def __init__(self, id: str, name: str):
        self.id
        self.name = name


UserList = List[User]

User is highlighted in green but not UserList.

Here is a screen shot on VsCode: screen_shot_invalid_highlight

It causes incoherent highlights such as: incoherent_highlights

Is there a way to have UserList highlighted in green by VsCode ?

VsCode Version: 1.65.2 with python and Pylance extension installed

Upvotes: 1

Views: 1522

Answers (2)

Lucas Basquerotto
Lucas Basquerotto

Reputation: 8143

There's an open issue for that (https://github.com/microsoft/pylance-release/issues/3100) but it seems that is not currently planned:

Sorry but this is not currently planned. However you can get this somewhat by yourself.

The TypeAlias is flagged with a typehint modifier in the semantic token. This allows you to override the color [...]

To override the color for type hints, you can define the setting editor.semanticTokenColorCustomizations as:

"editor.semanticTokenColorCustomizations": {
    "[Default Dark Modern]": {
        "rules": {
            "*.typeHint": "#4EC9B0"
        }
    }
}

This assumes that you use the VSCode theme Default Dark Modern. You can just change the theme name to the actual theme you use, if you are using another one.

You can see which theme you're using in Settings -> Themes -> Color Theme (the theme identificator should be at the right of the theme name). VSCode also autocompletes the theme identificator for you if you press Ctrl+Space after [ in the settings.json file.

Upvotes: 0

rioV8
rioV8

Reputation: 28868

The semantic scope of UserList is :variable.other.readwrite

The semantic scope of User is: entity.name.type.class


on the line

from typing import List, Tuple

List and Tuple have a different color and scope

This should not be so it validates a bug issue for Pylance

Upvotes: 1

Related Questions