skip to Main Content

When I try to add type annotations (for return types) to my functions then the syntax highlighting in vscode is not working after that point. Do you have a hint on what setting to change to fix the issues?

VSCode Version 1.67.1
Python Version 3.10.8

Code with type annotations

def median_absolute_deviaton(data: list) -> float:
    """Returns the median absolute deivation (MAD) [float]."""
    med = median(data)
    deviations = [abs(i-med) for i in data]
    return statistics.median(deviations)

Image with working syntax highlighting

Working syntax highlighting

Image with broken syntax highlighting

Broken syntax highlighting

2

Answers


  1. Chosen as BEST ANSWER

    SOLVED: It was caused by the "Python for VSCode" extension. Uninstalling helped. Found it here: https://github.com/MagicStack/MagicPython/issues/138#issuecomment-403538358


  2. You may need to install and/or select the right Python interpreter:

    VSCode Interpreter Selection

    There’s a python version shown at the lower right corner of the VSCode window. Click it, then select a version of python at least as high as python 3.5 (the version of python where type annotations were added).

    If you don’t have a version of python that high listed, then you’ll need to install one.

    If you have one installed and it isn’t listed, then you can manually enter the path to the version you installed.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search