Skip to content

Syntax highlighting broken by method return type hint #3443

@alecglen

Description

@alecglen

Type: Bug

Behaviour

Expected vs. Actual

Using the Dark+ (default dark) theme, I expect Python keywords (for, with, return, def, etc.) to display as a magenta color. This is true throughout my IDE.
image

Except when I add a type hint to the method, I lose that portion of the highlighting through the function to the next method start.
image

Details:

  • Other than def, it appears scoped to the function context (the generator inside sorted is unaffected).
  • It doesn't matter what the type hint is; a simple int still breaks it.
  • For some reason, wrapping the hint in parens avoids the issue.
    image

Steps to reproduce:

OS: Ubuntu 20.04.5 LTS

Open a class and add a type hint.

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.9.13
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Conda
  • Value of the python.languageServer setting: Default
Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

LSP Notebooks experiment is enabled
LSP Notebooks interactive window support is enabled
> conda info --json
Python interpreter path: ~/anaconda3/envs/betsy-nfl/bin/python
> /bin/python ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/interpreterInfo.py
> /bin/python3 ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/interpreterInfo.py
> /usr/bin/python ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/interpreterInfo.py
> /usr/bin/python3 ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/interpreterInfo.py
> ~/anaconda3/bin/python ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/interpreterInfo.py
> conda run -n betsy-nfl --no-capture-output python ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/printEnvVariables.py
> conda run -n betsy-nfl --no-capture-output python ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/printEnvVariables.py
> conda run -n betsy-nfl --no-capture-output python ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/printEnvVariables.py
> conda run -n betsy-nfl --no-capture-output python ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/printEnvVariables.py
> ~/anaconda3/envs/betsy-nfl/bin/python ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/interpreterInfo.py
> ~/anaconda3/envs/betsy2/bin/python ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/interpreterInfo.py
Starting Pylance language server.
Jupyter provided interpreter path override: /home/alec/anaconda3/envs/betsy-nfl/bin/python

User Settings


languageServer: "Pylance"

Extension version: 2022.16.0
VS Code version: Code 1.72.0 (64bbfbf67ada9953918d72e1df2f4d8e537d340e, 2022-10-04T23:20:47.539Z)
OS version: Linux x64 5.15.0-43-generic
Modes:
Sandboxed: No

System Info
Item Value
CPUs Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz (8 x 2800)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: disabled_software
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) 3, 2, 1
Memory (System) 31.09GB (22.38GB free)
Process Argv --unity-launch --crash-reporter-id cfe16397-b991-4479-bd53-4bc43848e2f1
Screen Reader no
VM 0%
DESKTOP_SESSION ubuntu
XDG_CURRENT_DESKTOP Unity
XDG_SESSION_DESKTOP ubuntu
XDG_SESSION_TYPE x11
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593cf:30376535
pythonvs932:30410667
cppdebug:30492333
vsclangdc:30486549
c4g48928:30535728
dsvsc012:30540252
azure-dev_surveyone:30548225
2144e591:30553903
pyindex848:30577860
fc301958:30573243

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions