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

Quick fix suggests importing symbol that is not available in `pythonVersion`

Open DanielRosenwasser opened this issue 2 years ago • 1 comments

Environment data

  • Language Server version: 2023.10.40
  • OS and version: Linux
  • Python version: 3.11

Code Snippet

pyrightconfig.json

{
    "typeCheckingMode": "strict",
    "reportImplicitOverride": "error",
    "pythonVersion": "3.11",
    "include": [
        "**/*",
    ],
}

file.py

class A:
    def method(self):
        pass

class B(A):
    @override
    def method(self):
        pass

Repro Steps

  1. Request a quick fixes on override

Actual behavior

Pylance suggests "from typing import override" even though that won't work unless I'm using Python 3.12. The same is true for auto-import completions.

Expected behavior

There should be no provided quick fix.

Alternatively, I'd take the quick fix as long as I can get an error telling me it's not going to work based on the configured version of Python being too old.

DanielRosenwasser avatar Oct 21 '23 00:10 DanielRosenwasser

Note also that if I explicitly have typing-extensions installed, I only get a quick fix from typing not typing_extensions.

DanielRosenwasser avatar Oct 21 '23 00:10 DanielRosenwasser

new python.analysis.regenerateStdLibIndices option is added. if enabled, pylance will create stdlib indices per workspace rather than using prebuilt stdlib indices.

heejaechang avatar Jul 10 '24 23:07 heejaechang

This issue has been fixed in prerelease version 2024.7.100, which we've just released. You can find the changelog here: CHANGELOG.md

heejaechang avatar Jul 15 '24 22:07 heejaechang