Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No autocomplete for Literal with descriptor __set__ method #6523

Closed
armoha opened this issue Oct 4, 2024 · 2 comments
Closed

No autocomplete for Literal with descriptor __set__ method #6523

armoha opened this issue Oct 4, 2024 · 2 comments
Assignees
Labels
needs repro Issue has not been reproduced yet

Comments

@armoha
Copy link

armoha commented Oct 4, 2024

Might be related to #5299

Environment data

  • Language Server version: 2024.9.104
  • OS and version: win32 x64
  • Python version (and distribution if applicable, e.g. Anaconda): 3.11.9 64 bit
  • python.analysis.indexing: true
  • python.analysis.typeCheckingMode: off

Code Snippet

from __future__ import annotations

from typing import overload, Self, Literal


class FooDescriptor:
    @overload
    def __get__(self, instance: None, owner: type[Foo]) -> Self:
        ...

    @overload
    def __get__(self, instance: Foo, owner: type[Foo]) -> str:
        ...

    def __get__(self, instance, owner):
        if instance is None:
            return self
        return "foo"

    def __set__(self, instance: Foo, value: Literal["abc", "def"]) -> None:
        pass


class Foo:
    foo = FooDescriptor()


foo = Foo()
foo.foo = "_no_literal_suggestion_"

Repro Steps

Type foo.foo = "" and no auto-completes off the literal.

Expected behavior

Literal "abc", "def" are suggested in the autocomplete popup, just like how property works:

image

Actual behavior

No autocomplete popup appears.

image

Logs

https://gist.github.com/armoha/444e446feed23b09a19371e83dd6d3c9

@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Oct 4, 2024
@debonte
Copy link
Contributor

debonte commented Oct 4, 2024

If I annotate Foo.foo as ClassVar[FooDescriptor] I get the expected behavior.

image

@armoha
Copy link
Author

armoha commented Oct 5, 2024

Annotating ClassVar[FooDescriptor] solved it, thank you!

@armoha armoha closed this as completed Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Issue has not been reproduced yet
Projects
None yet
Development

No branches or pull requests

3 participants