microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.69k stars 769 forks source link

Pylance inlay hints do not honor python version #5255

Open ElementalWarrior opened 8 months ago

ElementalWarrior commented 8 months ago

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

YakovL commented 4 months ago

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.

KacieKK commented 1 month ago

Hey @YakovL, thanks for posting, but your issue seems like a different one with choosing interpreter, could you create a new issue and include a log as described under "Filing an issue" in the troubleshooting guide?

heejaechang commented 1 month ago

I think it is a bug in our side. we should set pep604Printing option properly based on python version.