Search code examples
pythonvisual-studio-codesyntax-highlightingpython-3.11

How to fix that weird syntax coloration of Python 3.11 code on VS Code?


I'm encountering a syntax coloration issue on VS Code. I don't know if this my VS Code that cannot handle Python 3.11 or it's an issue with my syntax coloration.

For example, this code:

from FcpeApp.models import User
from FcpeApp.models import Admin
from FcpeApp.models import Supervisor

from passlib.hash import sha256_crypt

class PasswordManager : 
    
    @staticmethod
    def generate(obj : User|Admin|Supervisor, pwd : str) -> None :
        obj.password = sha256_crypt.hash(pwd)
        obj.save()
        
    @staticmethod
    def verify() :
        pass

This shows up in VS Code as:

screenshot of VS Code with the code

Here, the second def is not colored like the first def, but, for me, the code is correct.

I tried to reload my IDE, re-install my theme (one dark theme), change my theme to another theme (monokai dimmed), but the problem still exists and it is very to hard to work in this type of code without correct syntax coloration features.

My Help : About output:

Version: 1.81.1 (user setup)
Commit: 6c3e3dba23e8fadc360aed75ce363ba185c49794
Date: 2023-08-09T22:22:42.175Z
Electron: 22.3.18
ElectronBuildId: 22689846
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Windows_NT x64 10.0.22621

I'm using the tht13.python extension.


Solution

  • The issue was found by extension bisect to be caused by the tht13.python, which is deprecated (see Python for VS Code installation problem: "This extension is deprecated as it is no longer being maintained." for more info on that deprecation). I suggest to use Microsoft's Python extension instead (I have no affiliation with this extension).