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

Pylance inlay hints do not honor python version

Open ElementalWarrior opened this issue 6 months ago • 1 comments

Pylance version: v2023.11.10 OS: Manjaro, 6.6.1-arch1-1-g14 Python version: VSCode interpreter set to 3.8.9, native OS version 3.11.5

Environment data

pyproject.toml includes:

[tool.pyright]
pythonVersion = "3.8"
venvPath = "/home/james/.cache/Python-3.8.9/"

Code Snippet

import os

def get(
    id = None,
):
    
    return None if os.getenv("something") else int(1)

Repro Steps

Turn on pylance inlay hints

Expected behavior

Python versions less than 3.10 suggest type hints such as Optional[int] instead of int | None.

Actual behavior

Python inlay hints suggest int | None for hinting, which is not supported by python3.8

Logs

vscode python language server output logging:

2023-12-13 14:06:06.455 [info] [Info  - 14:06:06] (228908) Setting environmentName for service "myproject": "3.8.9 (Python-3.8.9 venv)"

When running python code:

TypeError: unsupported operand type(s) for |: 'type' and 'type'

image

ElementalWarrior avatar Dec 13 '23 22:12 ElementalWarrior

Do you have only one venv folder in your project folder? I had a similar problem when upgrading Python: I recreated venv and until I deleted the old one, Pylance kept suggesting things based on the old version, not a new one. May be your case is similar, just the expected version is lower than the other one, not higher, like in my case.

YakovL avatar Apr 24 '24 12:04 YakovL