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

Descriptor type shown in autocomplete popover is incorrect

Open henribru opened this issue 1 year ago • 2 comments

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

Type
foo.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: image

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:

image

Logs

https://gist.github.com/henribru/7e9997261acd33583f85e6a769a5459e

henribru avatar Dec 21 '23 07:12 henribru

Thanks for this issue, I can repro in 2024.7.1 version.

KacieKK avatar Jul 10 '24 23:07 KacieKK

This remains an issue as of v2024.12.1. Any updates or known work arounds?

whatamithinking avatar Dec 31 '24 00:12 whatamithinking