pylance-release
pylance-release copied to clipboard
Descriptor type shown in autocomplete popover is incorrect
Environment data
- Language Server version: 2023.12.1
- OS and version: linux x64
- Python version (and distribution if applicable, e.g. Anaconda): 3.11.6
- python.analysis.indexing: true
- python.analysis.typeCheckingMode: off
Code Snippet
from typing import overload
class FooIntDescriptor:
@overload
def __get__(self, instance: None, type: type["Foo"]) -> "FooIntDescriptor": ...
@overload
def __get__(self, instance: "Foo", type: type["Foo"]) -> int: ...
def __get__(self, instance: "Foo" | None, type: type["Foo"]) -> int | "FooIntDescriptor":
if instance is None:
return self
return 3
class Foo:
foo: FooIntDescriptor
bar: int
foo = Foo()
Repro Steps
Typefoo.f
and observe the type shown for foo.foo in the autocomplete popup.
Expected behavior
The type for foo.foo is shown as int in the autocomplete popup. If you type it out and then hover over it, this type is correctly shown:
Actual behavior
The type for foo.foo is shown as FooIntDescriptor in the autocomplete popup, like if it was looked up on the class instead of the instance:
Logs
https://gist.github.com/henribru/7e9997261acd33583f85e6a769a5459e
Thanks for this issue, I can repro in 2024.7.1 version.
This remains an issue as of v2024.12.1. Any updates or known work arounds?