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

Magic Python textmate changes broke constants

Open funkindy opened this issue 3 weeks ago • 19 comments

  • Pylance version: 2025.10.3
  • OS and version: MacOS
  • Python version 3.12 (venv, uv)

Repro Steps

I use custom color scheme for years: https://marketplace.visualstudio.com/items?itemName=jdinhlife.gruvbox

  1. Install 2025.10.3

Expected behavior

type hints has this coloring:

Image

Actual behavior

Colors are not the same after 2025.10.3, also there are less semantics in coloring. It is almost all-yellow

Image

If i downgrade pylance version to 2025.10.2 or lower, colors become correct. Maybe it is not a bug, but for me personally it is super-inconvenient, because i use this gruvbox variant for years

funkindy avatar Dec 02 '25 10:12 funkindy

Hi @funkindy, I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.


Explanation:

  • Pylance 2025.10.3 now applies semantic highlighting to type hints (token type typeHint), which relies on your theme’s semanticTokenColors rules.
  • If your Gruvbox variant doesn’t define a color for typeHint, VS Code falls back to its default semantic color (often yellow), making all annotations appear the same.
  • Use Developer: Inspect Editor Tokens and Scopes to verify the semantic token type and scope that Pylance is assigning to your type hints.

Potential Duplicate IssuesThese issues may be duplicates of your report, but may differ in some of the details.

  • Type annotations context semantically highlighted incorrectly? – Troubleshooting via token inspector and checking editor.semanticTokenColorCustomizations.
    https://github.com/microsoft/pylance-release/issues/708
  • Pylance makes the syntax highlighting in my VSCode theme (Tokyo Night Storm) become unbalanced – Effects of semantic highlighting on theme colors.
    https://github.com/microsoft/pylance-release/issues/5570

Potential Workarounds:

  • Define semantic token rules for type hints in your settings.json, matching your Gruvbox palette. For example:

    "editor.semanticTokenColorCustomizations": {
      "[Gruvbox Dark]": {
        "rules": {
          "*.typeHint": "#A6E22E",       // adjust to your preferred type-hint color
          "*.parameter": "#F9F1A5"      // optional: customize parameter hint color
        }
      }
    }
    
  • Inspect tokens with “Developer: Inspect Editor Tokens and Scopes” to confirm which semantic token types and modifiers need overrides.

The team will respond to your issue shortly. Please note this is a trial feature and may not be fully accurate. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or was incorrect, please give it a 👎. Your feedback helps us improve!

github-actions[bot] avatar Dec 02 '25 10:12 github-actions[bot]

+ To that issue I have different color scheme, but colors for type annotations changed too. Also, some types have one color, others have another. Default values changed colors too.

It is harder to read code now. Not because colors changed, but because they've changed very inconstantly

gordiig avatar Dec 02 '25 14:12 gordiig

Can somebody post some code that causes the problem? We updated our use of Magic Python to the latest version (it's what provides most of the tokens for colorization). It's probably characterizing the types in your example as different tokens than it used to.

The question is whether or not the new tokens are more correct or not. Your theme may just not be recognizing the tokens that are being output now.

For me, with this code:

def foo(a: Optional[str] = None) -> str:
    ...

I get this set of tokens for 2025.10.3:

Image

And this set of tokens for 2025.10.2:

Image

You can see the text mate scopes have changed.

rchiodo avatar Dec 02 '25 17:12 rchiodo

Semantic tokens have stayed the same (which are provided by Pylance) so any difference here should be from text mate scoping

rchiodo avatar Dec 02 '25 17:12 rchiodo

@rchiodo sample:

def foo(a: str | None = None) -> list[dict[str, str]]: ...

2025.10.2 (Which is as expected)

Image

2025.10.3

Image

funkindy avatar Dec 02 '25 18:12 funkindy

The colors aren't the important part. It's the tokens:

Image

Your theme must not support the support.type.builtin.python scope. It's why it's coming out different. That's the new scope that was introduced in 2025.10.3

rchiodo avatar Dec 02 '25 18:12 rchiodo

Although I'm surprised your theme isn't colorizing the semantic token. It should color a 'class' the same between both versions.

rchiodo avatar Dec 02 '25 18:12 rchiodo

Yeah it doesn't look like it has a coloring for class:

This is for 2025.10.3 Image

This is for 2025.10.2

Image

It looks like it has a coloring for meta.function.python. Which is no longer one of the textmate scopes. That explains the difference.

rchiodo avatar Dec 02 '25 18:12 rchiodo

Yeah i see. But is it as expected that default (most popular obv) themes are also affected?

Dark+ 2025.10.2 - Note that None looks the same in annotation, param default and as a basic variable. It is very important for readability for me personally

Image

Dark+ 2025.10.3 - None has different colors in function and as a module var are different (!)

Image

here also list somehow has different colors in the same annotation expr:

Image

funkindy avatar Dec 03 '25 09:12 funkindy

@rchiodo sorry, i dont get why is this closed.

There are variours scope changes for textmate scopes in 2025.10.3 that brokes a lot of color themes. e.g.:

  1. constant.language.python is now not relevant to type hints (None, Ellipsis broken in type annotations and cannot be adjusted) they are now support.type.python inside type hints

  2. meta.indexed-name.python, meta.item-access.python - also dropped from annotations in favor of support.type.python

so it loses flexibility also :(

funkindy avatar Dec 03 '25 13:12 funkindy

Sorry but my colors don't come out that way. Perhaps you have some settings overriding things.

I'm using this:

Image

And this is the colors I get for your example:

Image

If you use 'Developer : Inspect Editor Tokens and Scopes', it should show you where the color is coming from.

For me the 'None' in the parameters field is actually a semantic color:

Image

The Default Dark theme does support the 'support.type' textmate scope though, so support.type.python should work even if the semantic color isn't being used.

rchiodo avatar Dec 03 '25 17:12 rchiodo

And it seems I was wrong, 'meta.function.python' is still one of the textmate scopes, it's just support.type.python comes first now. It wasn't actually removed.

rchiodo avatar Dec 03 '25 17:12 rchiodo

I get the same colors on 2025.10.2. Just the support.type token doesn't match so I don't see that in the tokens and scopes (it only matches the semantic token):

Image

rchiodo avatar Dec 03 '25 17:12 rchiodo

Maybe you have this turned off?

Image

That gives me this for 2025.10.3

Image

And this for 2025.10.2:

Image

Which looks like what you had said. 'constant.language.python' is no longer detected by the textmate scope. Instead it picks the 'support.type' color.

Given that our semantic token provider calls this a constant, then yeah the text mate language file seems wrong in this case.

rchiodo avatar Dec 03 '25 17:12 rchiodo

Yes, sorry, i had semanticHighlighting.enabled=false during those tests of Dark+. Now everything is the same with you.

So i decided to switch to default theme because even with tweaks i couldnt achieve the same result with gruvbox in 2025.10.3

The thing i really dont like is that with this semantic tokens i cant assign different colors to func parameters and variable passed to it (in nested case both parts has semantic token type = parameter with no modifier)

Image

i`d like to make it look like this:

Image

which is a default look if i disable semanticHighlighting (but this leads to list/None and other problems).

Textmate assign different scope to them and it makes sense to me. It would be nice to have some modifier maybe for right part of the assignment.

funkindy avatar Dec 04 '25 07:12 funkindy

Maybe we should open a different issue for adding a new semantic token for values passed as parameters. Right now the semantic token for the value and the keyword is the same:

Image

rchiodo avatar Dec 04 '25 17:12 rchiodo

Thanks for opening the issue @funkindy! I'd thought that I was going crazy 🙂

Reverted to 2025.10.2, things are much saner.

Theme: Monokai Pro, and I have not played with the semanticHighlighting setting

iutlu avatar Dec 08 '25 18:12 iutlu

Another point in diff editor. Different colors in default Dark+ with default settings. Why did you rename this issue? It is hard to find now obv.

Image

funkindy avatar Dec 09 '25 17:12 funkindy

Not sure what the error you're showing in the diff editor is. The left side doesn't have any textmate scopes. The right side is working better than it was in 2025.9.1 for me.

rchiodo avatar Dec 09 '25 17:12 rchiodo